Skip to content

Commit

Permalink
fix: account-lib/blockchain-scanner unit tests
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
JoeCap08055 committed Oct 25, 2024
1 parent ed7499f commit 0f3c733
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
26 changes: 23 additions & 3 deletions libs/account-lib/src/utils/blockchain-scanner.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 14 in libs/account-lib/src/utils/blockchain-scanner.service.spec.ts

View workflow job for this annotation

GitHub Actions / [account] Build and Test

'NonceConstants' is defined but never used

jest.mock('@polkadot/api', () => {
const originalModule = jest.requireActual<typeof import('@polkadot/api')>('@polkadot/api');
Expand All @@ -28,9 +29,21 @@ const mockBlockchainConfigProvider = GenerateMockConfigProvider<IBlockchainNonPr
frequencyApiWsUrl: new URL('ws://localhost:9944'),
isDeployedReadOnly: false,
});

const mockRedis = {
get: jest.fn(),
set: jest.fn(),
defineCommand: jest.fn(),
};

const mockDefaultRedisProvider = {
provide: getRedisToken(DEFAULT_REDIS_NAMESPACE),
useValue: { get: jest.fn(), set: jest.fn() },
useValue: mockRedis,
};

const mockNonceRedisProvider = {
provide: getRedisToken(NONCE_SERVICE_REDIS_NAMESPACE),
useValue: mockRedis,
};

const mockBlockHash = {
Expand Down Expand Up @@ -91,7 +104,14 @@ describe('BlockchainScannerService', () => {
ignoreErrors: false,
}),
],
providers: [mockRedis, mockBlockchainConfigProvider, Logger, BlockchainService, ScannerService],
providers: [
mockDefaultRedisProvider,
mockNonceRedisProvider,
mockBlockchainConfigProvider,
Logger,
BlockchainService,
ScannerService,
],
}).compile();
moduleRef.enableShutdownHooks();
service = moduleRef.get<ScannerService>(ScannerService);
Expand Down
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down

0 comments on commit 0f3c733

Please sign in to comment.