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): rename peer storage into repository #4291

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion __tests__/integration/core-api/handlers/peers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ beforeAll(async () => {

for (const peerMock of Object.values(peerMocks)) {
// @ts-ignore
app.get<Contracts.P2P.PeerStorage>(Container.Identifiers.PeerStorage).setPeer(peerMock);
app.get<Contracts.P2P.PeerRepository>(Container.Identifiers.PeerRepository).setPeer(peerMock);
}
});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/core-state/__support__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const peerNetworkMonitor = {
boot: jest.fn(),
cleansePeers: jest.fn(),
};
const peerStorage = null;
const peerRepository = null;

export const setUp = async (): Promise<Application> => {
jest.setTimeout(60000);
Expand Down Expand Up @@ -45,7 +45,7 @@ export const setUp = async (): Promise<Application> => {
app.bind(Container.Identifiers.TransactionPoolQuery).toConstantValue(transactionPoolQuery);
app.bind(Container.Identifiers.TransactionPoolService).toConstantValue(transactionPoolService);
app.bind(Container.Identifiers.PeerNetworkMonitor).toConstantValue(peerNetworkMonitor);
app.bind(Container.Identifiers.PeerStorage).toConstantValue(peerStorage);
app.bind(Container.Identifiers.PeerRepository).toConstantValue(peerRepository);

await app.bootstrap({
flags: {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/core-api/__support__/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const initApp = (): Application => {

app.bind(Container.Identifiers.PeerNetworkMonitor).toConstantValue(Mocks.NetworkMonitor.instance);

app.bind(Container.Identifiers.PeerStorage).toConstantValue(Mocks.PeerStorage.instance);
app.bind(Container.Identifiers.PeerRepository).toConstantValue(Mocks.PeerRepository.instance);

app.bind(Container.Identifiers.DatabaseRoundRepository).toConstantValue(Mocks.RoundRepository.instance);

Expand Down
28 changes: 14 additions & 14 deletions __tests__/unit/core-api/controllers/peers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ beforeEach(() => {

controller = app.resolve<PeersController>(PeersController);

Mocks.PeerStorage.setPeers([]);
Mocks.PeerRepository.setPeers([]);
});

afterEach(() => {
Expand Down Expand Up @@ -77,7 +77,7 @@ describe("PeersController", () => {

describe("index", () => {
it("should return list of peers", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand All @@ -101,7 +101,7 @@ describe("PeersController", () => {
});

it("should return list of peers if version in request is not set", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -137,7 +137,7 @@ describe("PeersController", () => {
});

it("should return error when offset is negative", async () => {
Mocks.PeerStorage.setPeers([peer]);
Mocks.PeerRepository.setPeers([peer]);

const request: Hapi.Request = {
query: {
Expand All @@ -157,7 +157,7 @@ describe("PeersController", () => {
});

it("should return paginated response when offset is not a number", async () => {
Mocks.PeerStorage.setPeers([peer]);
Mocks.PeerRepository.setPeers([peer]);

const request: Hapi.Request = {
query: {
Expand All @@ -177,7 +177,7 @@ describe("PeersController", () => {
});

it("should return paginated response when limit is not defined", async () => {
Mocks.PeerStorage.setPeers([peer]);
Mocks.PeerRepository.setPeers([peer]);

const request: Hapi.Request = {
query: {
Expand All @@ -196,7 +196,7 @@ describe("PeersController", () => {
});

it("should return list of peers ordered by version ascending", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe("PeersController", () => {
});

it("should return list of peers ordered by version descending", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -256,7 +256,7 @@ describe("PeersController", () => {
});

it("should return list of peers ordered by height ascending", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -286,7 +286,7 @@ describe("PeersController", () => {
});

it("should return list of peers ordered by height descending", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -316,7 +316,7 @@ describe("PeersController", () => {
});

it("should return list of peers ordered by latency ascending", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -346,7 +346,7 @@ describe("PeersController", () => {
});

it("should return list of peers ordered by latency descending", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -376,7 +376,7 @@ describe("PeersController", () => {
});

it("should return list of peers ordered by other descending", async () => {
Mocks.PeerStorage.setPeers([peer, anotherPeer]);
Mocks.PeerRepository.setPeers([peer, anotherPeer]);

const request: Hapi.Request = {
query: {
Expand Down Expand Up @@ -408,7 +408,7 @@ describe("PeersController", () => {

describe("show", () => {
it("should return peer", async () => {
Mocks.PeerStorage.setPeers([peer]);
Mocks.PeerRepository.setPeers([peer]);

const request: Hapi.Request = {
params: {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/core-api/service-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ beforeEach(() => {

app.bind(Container.Identifiers.PeerNetworkMonitor).toConstantValue({});

app.bind(Container.Identifiers.PeerStorage).toConstantValue({});
app.bind(Container.Identifiers.PeerRepository).toConstantValue({});

app.bind(Container.Identifiers.DatabaseRoundRepository).toConstantValue({});

Expand Down
12 changes: 6 additions & 6 deletions __tests__/unit/core-blockchain/blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("Blockchain", () => {
const stateMachine: any = {};
const eventDispatcherService: any = {};
const peerNetworkMonitor: any = {};
const peerStorage: any = {};
const peerRepository: any = {};
const blockProcessor: any = {};
const databaseInteractions: any = {};

Expand All @@ -41,7 +41,7 @@ describe("Blockchain", () => {
sandbox.app.bind(Container.Identifiers.StateMachine).toConstantValue(stateMachine);
sandbox.app.bind(Container.Identifiers.EventDispatcherService).toConstantValue(eventDispatcherService);
sandbox.app.bind(Container.Identifiers.PeerNetworkMonitor).toConstantValue(peerNetworkMonitor);
sandbox.app.bind(Container.Identifiers.PeerStorage).toConstantValue(peerStorage);
sandbox.app.bind(Container.Identifiers.PeerRepository).toConstantValue(peerRepository);
sandbox.app.bind(Container.Identifiers.BlockchainService).to(Blockchain).inSingletonScope();
sandbox.app.bind(Container.Identifiers.BlockProcessor).toConstantValue(blockProcessor);
sandbox.app.bind(Container.Identifiers.DatabaseTransactionRepository).toConstantValue({});
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("Blockchain", () => {
peerNetworkMonitor.broadcastBlock = jest.fn();
peerNetworkMonitor.checkNetworkHealth = jest.fn();

peerStorage.hasPeers = jest.fn();
peerRepository.hasPeers = jest.fn();

blockProcessor.process = jest.fn();

Expand Down Expand Up @@ -756,15 +756,15 @@ describe("Blockchain", () => {
it("should return true if we have no peer", () => {
const blockchain = sandbox.app.resolve<Blockchain>(Blockchain);

peerStorage.hasPeers = jest.fn().mockReturnValue(false);
peerRepository.hasPeers = jest.fn().mockReturnValue(false);

expect(blockchain.isSynced()).toBeTrue();
});

it("should return true if last block is less than 3 blocktimes away from current slot time", () => {
const blockchain = sandbox.app.resolve<Blockchain>(Blockchain);

peerStorage.hasPeers = jest.fn().mockReturnValue(true);
peerRepository.hasPeers = jest.fn().mockReturnValue(true);
const mockBlock = { data: { id: "123", height: 444, timestamp: Crypto.Slots.getTime() - 16 } };
stateStore.getLastBlock = jest.fn().mockReturnValue(mockBlock);

Expand All @@ -774,7 +774,7 @@ describe("Blockchain", () => {
it("should return false if last block is more than 3 blocktimes away from current slot time", () => {
const blockchain = sandbox.app.resolve<Blockchain>(Blockchain);

peerStorage.hasPeers = jest.fn().mockReturnValue(true);
peerRepository.hasPeers = jest.fn().mockReturnValue(true);
const mockBlock = { data: { id: "123", height: 444, timestamp: Crypto.Slots.getTime() - 25 } };
stateStore.getLastBlock = jest.fn().mockReturnValue(mockBlock);

Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/core-magistrate-api/__support__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const initApp = (): Application => {
app.bind(Container.Identifiers.DatabaseTransactionRepository).toConstantValue({});
app.bind(Container.Identifiers.DatabaseRoundRepository).toConstantValue({});
app.bind(Container.Identifiers.PeerNetworkMonitor).toConstantValue({});
app.bind(Container.Identifiers.PeerStorage).toConstantValue({});
app.bind(Container.Identifiers.PeerRepository).toConstantValue({});
app.bind(Container.Identifiers.TransactionPoolQuery).toConstantValue({});
app.bind(Container.Identifiers.TransactionPoolProcessorFactory).toConstantValue({});
app.bind(Container.Identifiers.TransactionHistoryService).toConstantValue({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ beforeEach(() => {

app.bind(Container.Identifiers.PeerNetworkMonitor).toConstantValue({});

app.bind(Container.Identifiers.PeerStorage).toConstantValue({});
app.bind(Container.Identifiers.PeerRepository).toConstantValue({});

app.bind(Container.Identifiers.DatabaseRoundRepository).toConstantValue({});

Expand Down
16 changes: 8 additions & 8 deletions __tests__/unit/core-p2p/listeners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("DisconnectInvalidPeers", () => {
const container = new Container.Container();

const logger = { warning: jest.fn(), debug: jest.fn() };
const storage = { getPeers: jest.fn() };
const repository = { getPeers: jest.fn() };
const app = {
getTagged: () => ({
getOptional: () => ["^3.0.0", "^3.0.0-next.0"], // minimumVersions
Expand All @@ -19,7 +19,7 @@ describe("DisconnectInvalidPeers", () => {
beforeAll(() => {
container.unbindAll();
container.bind(Container.Identifiers.LogService).toConstantValue(logger);
container.bind(Container.Identifiers.PeerStorage).toConstantValue(storage);
container.bind(Container.Identifiers.PeerRepository).toConstantValue(repository);
container.bind(Container.Identifiers.Application).toConstantValue(app);
container.bind(Container.Identifiers.EventDispatcherService).toConstantValue(emitter);
});
Expand All @@ -38,10 +38,10 @@ describe("DisconnectInvalidPeers", () => {
peers[4].version = "3.0.1"; // valid
beforeEach(() => {
disconnectInvalidPeers = container.resolve<DisconnectInvalidPeers>(DisconnectInvalidPeers);
storage.getPeers = jest.fn().mockReturnValue(peers);
repository.getPeers = jest.fn().mockReturnValue(peers);
});
afterEach(() => {
storage.getPeers = jest.fn();
repository.getPeers = jest.fn();
});

describe("handle", () => {
Expand All @@ -59,13 +59,13 @@ describe("DisconnectPeer", () => {
const container = new Container.Container();

const logger = { warning: jest.fn(), debug: jest.fn() };
const storage = { forgetPeer: jest.fn() };
const repository = { forgetPeer: jest.fn() };
const connector = { disconnect: jest.fn() };

beforeAll(() => {
container.unbindAll();
container.bind(Container.Identifiers.LogService).toConstantValue(logger);
container.bind(Container.Identifiers.PeerStorage).toConstantValue(storage);
container.bind(Container.Identifiers.PeerRepository).toConstantValue(repository);
container.bind(Container.Identifiers.PeerConnector).toConstantValue(connector);
});

Expand All @@ -78,8 +78,8 @@ describe("DisconnectPeer", () => {
const peer = new Peer("187.176.1.1", 4000);
await disconnectPeer.handle({ data: { peer: peer, port: 4000 } });

expect(storage.forgetPeer).toBeCalledTimes(1);
expect(storage.forgetPeer).toBeCalledWith(peer);
expect(repository.forgetPeer).toBeCalledTimes(1);
expect(repository.forgetPeer).toBeCalledWith(peer);
expect(connector.disconnect).toBeCalledTimes(1);
expect(connector.disconnect).toBeCalledWith(peer);
});
Expand Down
Loading