Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Sep 29, 2024
1 parent c9db561 commit 01a2f8c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
23 changes: 9 additions & 14 deletions packages/node-core/src/indexer/fetch.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import {EventEmitter2} from '@nestjs/event-emitter';
import {SchedulerRegistry} from '@nestjs/schedule';
import {BaseDataSource, BaseHandler, BaseMapping, DictionaryQueryEntry, IProjectNetworkConfig} from '@subql/types-core';
import {BaseDataSource, BaseHandler, BaseMapping, DictionaryQueryEntry} from '@subql/types-core';
import {range} from 'lodash';
import {
BaseUnfinalizedBlocksService,
Expand Down Expand Up @@ -83,11 +83,6 @@ const nodeConfig = new NodeConfig({
networkDictionary: [''],
});

const getNetworkConfig = () =>
({
dictionary: 'https://example.com',
}) as IProjectNetworkConfig;

const mockDs: BaseDataSource = {
kind: 'mock/DataSource',
startBlock: 1,
Expand Down Expand Up @@ -140,7 +135,7 @@ const getDictionaryService = () =>
initDictionaries: () => {
/* TODO */
},
}) as any as DictionaryService<any, any>;
} as any as DictionaryService<any, any>);

const getBlockDispatcher = () => {
const inst = {
Expand All @@ -164,9 +159,9 @@ describe('Fetch Service', () => {
let fetchService: TestFetchService;
let blockDispatcher: IBlockDispatcher<any>;
let dictionaryService: DictionaryService<any, any>;
let networkConfig: IProjectNetworkConfig;
let dataSources: BaseDataSource[];
let unfinalizedBlocksService: BaseUnfinalizedBlocksService<any>;
let projectService: IProjectService<any>;

let spyOnEnqueueSequential: jest.SpyInstance<
void | Promise<void>,
Expand All @@ -183,7 +178,7 @@ describe('Fetch Service', () => {
const eventEmitter = new EventEmitter2();
const schedulerRegistry = new SchedulerRegistry();

const projectService = {
projectService = {
getStartBlockFromDataSources: jest.fn(() => Math.min(...dataSources.map((ds) => ds.startBlock ?? 0))),
getAllDataSources: jest.fn(() => dataSources),
getDataSourcesMap: jest.fn(() => {
Expand All @@ -197,16 +192,15 @@ describe('Fetch Service', () => {
});
return new BlockHeightMap(x);
}),
bypassBlocks: [],
} as any as IProjectService<any>;

blockDispatcher = getBlockDispatcher();
dictionaryService = getDictionaryService();
networkConfig = getNetworkConfig();

fetchService = new TestFetchService(
nodeConfig,
projectService,
networkConfig,
blockDispatcher,
dictionaryService,
eventEmitter,
Expand Down Expand Up @@ -331,7 +325,8 @@ describe('Fetch Service', () => {
);

await fetchService.init(1);
expect((fetchService as any).bypassBlocks).toEqual(range(301, 500));

expect((fetchService as any).getDatasourceBypassBlocks()).toEqual([`301-500`]);
});

it('checks chain heads at an interval', async () => {
Expand Down Expand Up @@ -614,7 +609,7 @@ describe('Fetch Service', () => {
});

it('skips bypassBlocks', async () => {
(fetchService as any).networkConfig.bypassBlocks = [3];
projectService.bypassBlocks = [3];

await fetchService.init(1);

Expand All @@ -625,7 +620,7 @@ describe('Fetch Service', () => {

it('transforms bypassBlocks', async () => {
// Set a range so on init its transformed
(fetchService as any).networkConfig.bypassBlocks = ['2-5'];
projectService.bypassBlocks = ['2-5'];

await fetchService.init(1);

Expand Down
4 changes: 1 addition & 3 deletions packages/node-core/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import assert from 'assert';
import {OnApplicationShutdown} from '@nestjs/common';
import {EventEmitter2} from '@nestjs/event-emitter';
import {SchedulerRegistry} from '@nestjs/schedule';
import {BaseDataSource, IProjectNetworkConfig} from '@subql/types-core';
import {BaseDataSource} from '@subql/types-core';
import {range} from 'lodash';
import {NodeConfig} from '../configure';
import {IndexerEvent} from '../events';
Expand All @@ -27,7 +27,6 @@ export abstract class BaseFetchService<DS extends BaseDataSource, B extends IBlo
private _latestBestHeight?: number;
private _latestFinalizedHeight?: number;
private isShutdown = false;
// private bypassBlocks: number[] = [];

// If the chain doesn't have a distinction between the 2 it should return the same value for finalized and best
protected abstract getFinalizedHeader(): Promise<Header>;
Expand All @@ -47,7 +46,6 @@ export abstract class BaseFetchService<DS extends BaseDataSource, B extends IBlo
constructor(
private nodeConfig: NodeConfig,
protected projectService: IProjectService<DS>,
protected networkConfig: IProjectNetworkConfig,
protected blockDispatcher: B,
protected dictionaryService: DictionaryService<DS, FB>,
private eventEmitter: EventEmitter2,
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/indexer/fetch.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('FetchSevice', () => {
null as any, // ApiService
null as any, // NodeConfig
projectService, // ProjectService
{} as any, // Project
null as any, // BlockDispatcher,
null as any, // DictionaryService
null as any, // UnfinalizedBlocks
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/indexer/fetch.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('FetchService', () => {
apiService, // ApiService
null as any, // NodeConfig
null as any, // ProjectService
{} as any, // Project
null as any, // BlockDispatcher,
null as any, // DictionaryService
{
Expand Down
3 changes: 0 additions & 3 deletions packages/node/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
StoreCacheService,
} from '@subql/node-core';
import { SubstrateDatasource, SubstrateBlock } from '@subql/types';
import { SubqueryProject } from '../configure/SubqueryProject';
import { calcInterval, substrateHeaderToHeader } from '../utils/substrate';
import { ApiService } from './api.service';
import { ISubstrateBlockDispatcher } from './blockDispatcher/substrate-block-dispatcher';
Expand All @@ -37,7 +36,6 @@ export class FetchService extends BaseFetchService<
private apiService: ApiService,
nodeConfig: NodeConfig,
@Inject('IProjectService') projectService: ProjectService,
@Inject('ISubqueryProject') project: SubqueryProject,
@Inject('IBlockDispatcher')
blockDispatcher: ISubstrateBlockDispatcher,
dictionaryService: SubstrateDictionaryService,
Expand All @@ -50,7 +48,6 @@ export class FetchService extends BaseFetchService<
super(
nodeConfig,
projectService,
project.network,
blockDispatcher,
dictionaryService,
eventEmitter,
Expand Down

0 comments on commit 01a2f8c

Please sign in to comment.