Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Nov 11, 2024
1 parent 717cdaa commit 106a35b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe('SchemaMigration integration tests', () => {
schemaName,
initialSchema,
sequelize,
new NodeConfig({disableHistorical: true} as any)
new NodeConfig({historical: false} as any)
);

await migrationService.run(initialSchema, loadGqlSchema('test_10_1000.graphql'));
Expand Down Expand Up @@ -329,7 +329,7 @@ WHERE
schemaName,
initialSchema,
sequelize,
new NodeConfig({disableHistorical: true} as any)
new NodeConfig({historical: false} as any)
);

await migrationService.run(initialSchema, loadGqlSchema('test_13_2000.graphql'));
Expand Down Expand Up @@ -369,7 +369,7 @@ WHERE
schemaName,
initialSchema,
sequelize,
new NodeConfig({disableHistorical: true} as any)
new NodeConfig({historical: false} as any)
);

await migrationService.run(initialSchema, loadGqlSchema('test_14_1000.graphql'));
Expand Down
2 changes: 1 addition & 1 deletion packages/node-core/src/indexer/fetch.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe('Fetch Service', () => {
expect(finalizedSpy).toHaveBeenCalledTimes(2);
expect(bestSpy).toHaveBeenCalledTimes(2);

await expect(fetchService.getFinalizedHeader()).resolves.toEqual({
await expect(fetchService.getFinalizedHeader()).resolves.toMatchObject({
blockHeight: fetchService.finalizedHeight,
blockHash: '0xxx',
parentHash: '0xxx',
Expand Down
22 changes: 13 additions & 9 deletions packages/node-core/src/indexer/unfinalizedBlocks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('UnfinalizedBlocksService', () => {
await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(111, '0xabc111'));
await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(112, '0xabc112'));

expect((unfinalizedBlocksService as any).unfinalizedBlocks).toEqual([
expect((unfinalizedBlocksService as any).unfinalizedBlocks).toMatchObject([
mockBlock(111, '0xabc111').block.header,
mockBlock(112, '0xabc112').block.header,
]);
Expand All @@ -135,7 +135,9 @@ describe('UnfinalizedBlocksService', () => {

await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(113, '0xabc113'));

expect((unfinalizedBlocksService as any).unfinalizedBlocks).toEqual([mockBlock(113, '0xabc113').block.header]);
expect((unfinalizedBlocksService as any).unfinalizedBlocks).toMatchObject([
mockBlock(113, '0xabc113').block.header,
]);
});

it('can handle a fork and rewind to the last finalized height', async () => {
Expand All @@ -150,7 +152,7 @@ describe('UnfinalizedBlocksService', () => {
const res = await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(113, '0xabc113'));

// Last valid block
expect(res).toBe(111);
expect(res).toMatchObject({blockHash: '0xabc111', blockHeight: 111, parentHash: ''});

// After this the call stack is something like:
// indexerManager -> blockDispatcher -> project -> project -> reindex -> blockDispatcher.resetUnfinalizedBlocks
Expand All @@ -175,7 +177,7 @@ describe('UnfinalizedBlocksService', () => {
const res = await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(117, '0xabc117'));

// Last valid block
expect(res).toBe(112);
expect(res).toMatchObject({blockHash: '0xabc112', blockHeight: 112, parentHash: ''});
});

it('can handle a fork when all unfinalized blocks are invalid', async () => {
Expand All @@ -190,7 +192,7 @@ describe('UnfinalizedBlocksService', () => {
const res = await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(113, '0xabc113'));

// Last valid block
expect(res).toBe(110);
expect(res).toMatchObject({blockHash: '0xabc110f', blockHeight: 110, parentHash: '0xabc109f'});
});

it('can handle a fork and when unfinalized blocks < finalized head', async () => {
Expand All @@ -205,7 +207,7 @@ describe('UnfinalizedBlocksService', () => {
const res = await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(113, '0xabc113'));

// Last valid block
expect(res).toBe(110);
expect(res).toMatchObject({blockHash: '0xabc110f', blockHeight: 110, parentHash: '0xabc109f'});
});

it('can handle a fork and when unfinalized blocks < finalized head 2', async () => {
Expand All @@ -226,7 +228,7 @@ describe('UnfinalizedBlocksService', () => {
const res = await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(113, '0xabc113'));

// Last valid block
expect(res).toBe(110);
expect(res).toMatchObject({blockHash: '0xabc110f', blockHeight: 110, parentHash: '0xabc109f'});
});

it('can handle a fork and when unfinalized blocks < finalized head with a large difference', async () => {
Expand All @@ -241,7 +243,7 @@ describe('UnfinalizedBlocksService', () => {
const res = await unfinalizedBlocksService.processUnfinalizedBlocks(mockBlock(113, '0xabc113'));

// Last valid block
expect(res).toBe(110);
expect(res).toMatchObject({blockHash: '0xabc110f', blockHeight: 110, parentHash: '0xabc109f'});
});

it('can rewind any unfinalized blocks when restarted and unfinalized blocks is disabled', async () => {
Expand Down Expand Up @@ -269,7 +271,9 @@ describe('UnfinalizedBlocksService', () => {

await unfinalizedBlocksService2.init(reindex);

expect(reindex).toHaveBeenCalledWith(90);
expect(reindex).toHaveBeenCalledWith(
expect.objectContaining({blockHash: '0xabc90f', blockHeight: 90, parentHash: '0xabc89f'})
);
expect((unfinalizedBlocksService2 as any).lastCheckedBlockHeight).toBe(90);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const PgBlockHeightPlugin: Plugin = async (builder, options) => {
);

// Note this varies from node where true is allowed because of legacy support
const historicalMode = rows[0].value as boolean | 'block' | 'timestamp';
const historicalMode = rows[0]?.value || ('block' as boolean | 'block' | 'timestamp');
// Adds blockHeight condition to join clause when joining a table that has _block_range column
builder.hook(
'GraphQLObjectType:fields:field',
Expand Down

0 comments on commit 106a35b

Please sign in to comment.