From bf99a08383f6af4dcaa32e3f686f2970f041b91c Mon Sep 17 00:00:00 2001 From: JQQQ Date: Tue, 9 Apr 2024 16:24:33 +1200 Subject: [PATCH] Fix test --- .../v1/algorandDictionaryV1.spec.ts | 59 ++++++++++++++++--- packages/node/src/indexer/worker/worker.ts | 2 +- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/packages/node/src/indexer/dictionary/v1/algorandDictionaryV1.spec.ts b/packages/node/src/indexer/dictionary/v1/algorandDictionaryV1.spec.ts index c1b32ab7..1edb14ff 100644 --- a/packages/node/src/indexer/dictionary/v1/algorandDictionaryV1.spec.ts +++ b/packages/node/src/indexer/dictionary/v1/algorandDictionaryV1.spec.ts @@ -1,28 +1,73 @@ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 -import { NodeConfig } from '@subql/node-core'; +import { EventEmitter2 } from '@nestjs/event-emitter'; +import { NETWORK_FAMILY } from '@subql/common'; +import { DictionaryService, NodeConfig } from '@subql/node-core'; +import { MetaData } from '@subql/utils'; import { AlgorandDictionaryV1 } from './algorandDictionaryV1'; -describe('dictionary service', () => { - let dictionary: AlgorandDictionaryV1; +const nodeConfig = { + dictionaryTimeout: 10000, + dictionaryRegistry: + 'https://github.com/subquery/templates/raw/main/dist/dictionary.json', +} as NodeConfig; +const project = { + network: { + chainId: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', + }, +} as any; +class TestDictionaryService extends DictionaryService { + async initDictionaries(): Promise { + return Promise.resolve(undefined); + } + async getRegistryDictionaries(chainId: string): Promise { + return this.resolveDictionary( + NETWORK_FAMILY.algorand, + chainId, + this.nodeConfig.dictionaryRegistry, + ); + } +} +describe('dictionary v1', () => { + let dictionary: AlgorandDictionaryV1; beforeEach(async () => { + const testDictionaryService = new TestDictionaryService( + project.network.chainId, + nodeConfig, + new EventEmitter2(), + ); + const dictionaryEndpoints = + await testDictionaryService.getRegistryDictionaries( + project.network.chainId, + ); dictionary = await AlgorandDictionaryV1.create( { network: { chainId: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - dictionary: - 'https://api.subquery.network/sq/subquery/Algorand-Dictionary', + dictionary: dictionaryEndpoints[1], }, } as any, { dictionaryTimeout: 10000 } as NodeConfig, jest.fn(), - 'https://api.subquery.network/sq/subquery/Algorand-Dictionary', + dictionaryEndpoints[1], // use endpoint from network ); }); it('successfully validates metatada', () => { - expect(dictionary.metadataValid).toBeTruthy(); + // @ts-ignore + expect( + dictionary.dictionaryValidation( + { + lastProcessedHeight: 10000, + targetHeight: 10000, + chain: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', + genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', + startHeight: 1, + } as MetaData, + 1, + ), + ).toBeTruthy(); }); }); diff --git a/packages/node/src/indexer/worker/worker.ts b/packages/node/src/indexer/worker/worker.ts index b852a182..7830aa7e 100644 --- a/packages/node/src/indexer/worker/worker.ts +++ b/packages/node/src/indexer/worker/worker.ts @@ -34,7 +34,7 @@ const logger = getLogger(`worker #${threadId}`); async function initWorker(startHeight: number): Promise { try { const app = await NestFactory.create(WorkerModule, { - // logger: new NestLogger(!!argv.debug), // TIP: If the worker is crashing comment out this line for better logging + logger: new NestLogger(!!argv.debug), // TIP: If the worker is crashing comment out this line for better logging }); await app.init();