Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
improve tu
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitsichury committed Oct 18, 2023
1 parent 50d63c6 commit c7183bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
22 changes: 13 additions & 9 deletions src/client/__tests__/getRegistry.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { Web3RegistryClient } from "../Web3RegistryClient";
import { getRegistry } from "../getRegistry";
import { Peers } from './../../peer/Peers';
import { Peers } from '../../peer/Peers';

jest.mock('./../Web3RegistryClient');
jest.mock('../Web3RegistryClient');

describe("getRegistry", () => {
let fakeWebRegistryClient: Partial<Web3RegistryClient>;

beforeEach(() => {
jest.resetAllMocks();
});

test("Conf is not complete", () => {
expect(getRegistry({}, {} as Peers, [])).toBe(null);
expect(getRegistry({ NETWORK: "rinkeby" }, {} as Peers, [])).toBe(null);
expect(getRegistry({ API_KEY: "infura"}, {} as Peers, [])).toBe(null);
test("Conf is not complete", async () => {
expect(await getRegistry({}, {} as Peers, [])).toBe(null);
expect(await getRegistry({ NETWORK: "rinkeby" }, {} as Peers, [])).toBe(null);
expect(await getRegistry({ API_KEY: "infura"}, {} as Peers, [5])).toBe(null);
});

test("ok smart contract", () => {
const newLocal = getRegistry({ API_KEY: "infura", NETWORK: "rinkeby" }, {} as Peers, []);
expect(newLocal!.constructor.name).toBe("Web3RegistryClient");
test("ok smart contract", async () => {
const registry = await getRegistry({ API_KEY: "infura", NETWORK: "rinkeby" }, {} as Peers, [5]);
expect(registry!.constructor.name).toBe("Web3RegistryClient");
expect(registry!.connect).toHaveBeenCalledWith(5)
});
});
8 changes: 4 additions & 4 deletions src/client/getRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Peers } from './../peer/Peers.js';
import { Web3RegistryClient } from './Web3RegistryClient.js';

export function getRegistry(conf: any, peers: Peers, previsousChainObserved: number[]): Web3RegistryClient | null {
export async function getRegistry(conf: any, peers: Peers, previsousChainObserved: number[]): Promise<Web3RegistryClient | null> {
const apiKey: string = conf.API_KEY;
const network: string = conf.NETWORK;

Expand All @@ -11,9 +11,9 @@ export function getRegistry(conf: any, peers: Peers, previsousChainObserved: num
}

const registry = new Web3RegistryClient(apiKey, peers);
previsousChainObserved.forEach(chainId => {
registry.connect(chainId)
})
for (const chain of previsousChainObserved){
await registry.connect(chain)
}
return registry;
}

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (!isNumeric(process.env.MAX_RESULTS_FOR_QUERY)) {

const peers = new Peers(database, host, broadcastClient);

const registryClient = getRegistry(process.env, peers, previsousChainObserved);
const registryClient = await getRegistry(process.env, peers, previsousChainObserved);
if (registryClient === null) {
process.exit(3);
}
Expand Down

0 comments on commit c7183bf

Please sign in to comment.