Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core-p2p): inject objects with Inversify #4341

Merged
merged 24 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f3aca6
refactor(core-p2p): inject objects
sebastijankuzner Feb 25, 2021
212ae37
test(core-p2p): inject objects on blocks controller
sebastijankuzner Feb 25, 2021
79d6d63
refactor(core-p2p): inject objects on peer controller
sebastijankuzner Feb 25, 2021
7740aaf
test(core-p2p): inject objects on peer controller
sebastijankuzner Feb 25, 2021
d6147d6
chore(core-p2p): lint transaction schema & add return type
sebastijankuzner Feb 25, 2021
dd269bd
test(core-p2p): refactor transaction controller
sebastijankuzner Feb 25, 2021
159f33a
refactor(core-p2p): inject objects
sebastijankuzner Feb 25, 2021
cbfb7cf
test(core-p2p): test internals controllers
sebastijankuzner Feb 25, 2021
28642a4
test(core-p2p): test internals controllers
sebastijankuzner Feb 25, 2021
692b8a7
chore(core): load p2p after blockchain
sebastijankuzner Feb 25, 2021
5b7f673
refactor(core-p2p): inject blockchain
sebastijankuzner Feb 25, 2021
0889a58
refactor(core-p2p): use postConstruct()
sebastijankuzner Feb 25, 2021
c20f6e9
chore(core-p2p): skip blockchain check (it is ready)
sebastijankuzner Feb 25, 2021
ae01759
test(core-p2p): isAppReady
sebastijankuzner Feb 27, 2021
b203dba
test(core-p2p): networkMonitor
sebastijankuzner Feb 27, 2021
086ba3f
chore(core-p2p): use ioc
sebastijankuzner Feb 27, 2021
48fd9d8
test(core-p2p): use ioc in peer verifier
sebastijankuzner Feb 27, 2021
5a69382
chore(core-p2p): remove communicator from initialize method
sebastijankuzner Feb 27, 2021
a75be55
test(core-p2p): peer verifier
sebastijankuzner Feb 27, 2021
4b885fd
Merge branch 'develop' into refactor/core-p2p/inject
sebastijankuzner Feb 27, 2021
7114cae
Merge branch 'develop' into refactor/core-p2p/inject
sebastijankuzner Mar 1, 2021
e88f607
test(core-p2p): fix peer test
sebastijankuzner Mar 1, 2021
479709c
Revert "chore(core): load p2p after blockchain"
sebastijankuzner Mar 1, 2021
bdd9ff9
Merge remote-tracking branch 'origin/develop' into refactor/core-p2p/…
sebastijankuzner Mar 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(core-p2p): isAppReady
  • Loading branch information
sebastijankuzner committed Feb 27, 2021
commit ae0175980ccc773437d4858df1e5f66855cc29b9
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Server } from "@hapi/hapi";
import { Container } from "@packages/core-kernel";
import { protocol } from "@packages/core-p2p/src/hapi-nes/utils";
import { IsAppReadyPlugin } from "@packages/core-p2p/src/socket-server/plugins/is-app-ready";
import Joi from "joi";
import { Container } from "@arkecosystem/core-kernel";

import { IsAppReadyPlugin } from "@arkecosystem/core-p2p/src/socket-server/plugins/is-app-ready";
import { protocol } from "@arkecosystem/core-p2p/src/hapi-nes/utils";

afterEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -33,14 +32,13 @@ describe("IsAppReadyPlugin", () => {

const blockchainService = { isBooted: jest.fn().mockReturnValue(true) };
const app = {
isBound: jest.fn().mockReturnValue(true),
get: jest.fn().mockReturnValue(blockchainService),
resolve: jest.fn().mockReturnValue({ getRoutesConfigByPath: () => mockRouteByPath }),
};

beforeAll(() => {
container.unbindAll();
container.bind(Container.Identifiers.Application).toConstantValue(app);
container.bind(Container.Identifiers.BlockchainService).toConstantValue(blockchainService);
});

beforeEach(() => {
Expand All @@ -67,30 +65,9 @@ describe("IsAppReadyPlugin", () => {
});
expect(JSON.parse(responseValid.payload)).toEqual(responsePayload);
expect(responseValid.statusCode).toBe(200);
expect(app.isBound).toBeCalledTimes(1);
expect(blockchainService.isBooted).toBeCalledTimes(1);
});

it("should return a forbidden error when blockchain service is not bound", async () => {
const server = new Server({ port: 4100 });
server.route(mockRoute);
isAppReadyPlugin.register(server);

app.isBound.mockReturnValueOnce(false);

// try the route with a valid payload
const remoteAddress = "187.166.55.44";
const response = await server.inject({
method: "POST",
url: "/p2p/peer/mockroute",
payload: {},
remoteAddress,
});
expect(response.statusCode).toBe(protocol.gracefulErrorStatusCode);
expect(app.isBound).toBeCalledTimes(1);
expect(blockchainService.isBooted).toBeCalledTimes(0);
});

it("should return a forbidden error when blockchain service is not booted", async () => {
const server = new Server({ port: 4100 });
server.route(mockRoute);
Expand All @@ -107,7 +84,6 @@ describe("IsAppReadyPlugin", () => {
remoteAddress,
});
expect(response.statusCode).toBe(protocol.gracefulErrorStatusCode);
expect(app.isBound).toBeCalledTimes(1);
expect(blockchainService.isBooted).toBeCalledTimes(1);
});

Expand Down Expand Up @@ -142,7 +118,6 @@ describe("IsAppReadyPlugin", () => {
});
expect(JSON.parse(responseValid.payload)).toEqual(responsePayload);
expect(responseValid.statusCode).toBe(200);
expect(app.isBound).toBeCalledTimes(1);
expect(blockchainService.isBooted).toBeCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Container, Contracts } from "@arkecosystem/core-kernel";
import Boom from "@hapi/boom";
import { Server } from "@hapi/hapi";

import { protocol } from "../../hapi-nes/utils";

Expand All @@ -11,7 +12,7 @@ export class IsAppReadyPlugin {
@Container.inject(Container.Identifiers.BlockchainService)
private readonly blockchain!: Contracts.Blockchain.Blockchain;

public register(server): void {
public register(server: Server): void {
server.ext({
type: "onPostAuth",
method: async (request, h) => {
Expand Down