From 0f3c733a7253350403e70fd9e529c7b2b2be266e Mon Sep 17 00:00:00 2001 From: Joe Caputo Date: Fri, 25 Oct 2024 09:50:53 -0400 Subject: [PATCH] fix: account-lib/blockchain-scanner unit tests - Test was failing to run; error message was a red herring--needed to mock NonceRedis connection because account-api uses read/write BlockchainService, due to its need for SIWFv2 to generate transactions for external signing. - Some tests were not being executed in the pipeline, due to not being included by any of the regexes in package.json; fixed --- .../utils/blockchain-scanner.service.spec.ts | 26 ++++++++++++++++--- package.json | 23 ++++++++++------ 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/libs/account-lib/src/utils/blockchain-scanner.service.spec.ts b/libs/account-lib/src/utils/blockchain-scanner.service.spec.ts index 93384be7..68d7dbe6 100644 --- a/libs/account-lib/src/utils/blockchain-scanner.service.spec.ts +++ b/libs/account-lib/src/utils/blockchain-scanner.service.spec.ts @@ -6,11 +6,12 @@ import { Redis } from 'ioredis'; import { BlockchainScannerService } from './blockchain-scanner.service'; import { FrameSystemEventRecord } from '@polkadot/types/lookup'; import { mockApiPromise } from '#testlib/polkadot-api.mock.spec'; -import { BlockchainService } from '#blockchain/blockchain.service'; +import { BlockchainService, NONCE_SERVICE_REDIS_NAMESPACE } from '#blockchain/blockchain.service'; import { IBlockchainNonProviderConfig } from '#blockchain/blockchain.config'; import { GenerateMockConfigProvider } from '#testlib/utils.config-tests'; import { EventEmitterModule } from '@nestjs/event-emitter'; import { AnyNumber } from '@polkadot/types/types'; +import { NonceConstants } from '#types/constants'; jest.mock('@polkadot/api', () => { const originalModule = jest.requireActual('@polkadot/api'); @@ -28,9 +29,21 @@ const mockBlockchainConfigProvider = GenerateMockConfigProvider { ignoreErrors: false, }), ], - providers: [mockRedis, mockBlockchainConfigProvider, Logger, BlockchainService, ScannerService], + providers: [ + mockDefaultRedisProvider, + mockNonceRedisProvider, + mockBlockchainConfigProvider, + Logger, + BlockchainService, + ScannerService, + ], }).compile(); moduleRef.enableShutdownHooks(); service = moduleRef.get(ScannerService); diff --git a/package.json b/package.json index 131d411b..411e0557 100644 --- a/package.json +++ b/package.json @@ -65,14 +65,21 @@ "generate:swagger-ui:graph": "npx --yes @redocly/cli build-docs openapi-specs/graph.openapi.json --output=./docs/graph/index.html", "pregenerate:swagger-ui:graph": "npx --yes @redocly/cli build-docs openapi-specs/graph-webhooks.openapi.yaml --output=./docs/graph/webhooks.html", "generate:swagger-ui": "npm run generate:swagger-ui:account ; npm run generate:swagger-ui:content-publishing ; npm run generate:swagger-ui:content-watcher ; npm run generate:swagger-ui:graph", - "test:account": "dotenvx run -f env-files/account.template.env -- jest 'account*'", - "test:content-publishing": "dotenvx run -f env-files/content-publishing.template.env -- jest 'content-publishing*'", - "test:content-watcher": "dotenvx run -f env-files/content-watcher.template.env -- jest 'content-watcher*'", - "test:graph": "dotenvx run -f env-files/graph.template.env -- jest 'graph*'", - "test:libs:blockchain": "dotenvx run -f env-files/graph.template.env -- jest --runInBand 'libs/blockchain*'", - "test:libs:cache": "dotenvx run -f env-files/graph.template.env -- jest 'libs/cache*'", - "test:libs:utils": "jest 'libs/utils*'", - "test:libs": "npm run test:libs:blockchain ; npm run test:libs:cache; npm run test:libs:utils;", + "test:account": "dotenvx run -f env-files/account.template.env -- jest 'apps/account-api' 'apps/account-worker'", + "test:content-publishing": "dotenvx run -f env-files/content-publishing.template.env -- jest 'apps/content-publishing-api' 'apps/content-publishing-worker'", + "test:content-watcher": "dotenvx run -f env-files/content-watcher.template.env -- jest 'apps/content-watcher'", + "test:graph": "dotenvx run -f env-files/graph.template.env -- jest 'apps/graph-api' 'apps/graph-worker'", + "test:libs:account": "dotenvx run -f env-files/account.template.env -- jest 'libs/account-lib'", + "test:libs:blockchain": "dotenvx run -f env-files/graph.template.env -- jest 'libs/blockchain'", + "test:libs:cache": "dotenvx run -f env-files/graph.template.env -- jest 'libs/cache'", + "test:libs:config": "dotenvx run -f env-files/graph.template.env -- jest 'libs/config'", + "test:libs:content-publishing": "dotenvx run -f env-files/content-publishing.template.env -- jest 'libs/content-publishing-lib'", + "test:libs:content-watcher": "dotenvx run -f env-files/content-watcher.template.env -- jest 'libs/content-watcher-lib'", + "test:libs:graph": "dotenvx run -f env-files/graph.template.env -- jest 'libs/graph-lib'", + "test:libs:queue": "dotenvx run -f env-files/graph.template.env -- jest 'libs/queue'", + "test:libs:storage": "dotenvx run -f env-files/content-publishing.template.env -- jest 'libs/storage'", + "test:libs:utils": "jest 'libs/utils'", + "test:libs": "dotenvx run -f env-files/graph.template.env -f env-files/content-publishing.template.env -- jest 'libs/'", "test": "npm run test:account ; npm run test:content-publishing ; npm run test:content-watcher ; npm run test:graph ; npm run test:libs", "test:verbose": "jest --coverage --verbose", "test:e2e:account": "dotenvx run -f env-files/account.template.env -- jest --runInBand --detectOpenHandles --testRegex 'account-api/.*\\.e2e-spec\\.ts'",