From 106a35bed624a251bc223ce9a2452bc48ddc71f8 Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Mon, 11 Nov 2024 15:35:14 +1300 Subject: [PATCH] Fix tests --- .../SchemaMigration.service.test.ts | 6 ++--- .../src/indexer/fetch.service.spec.ts | 2 +- .../indexer/unfinalizedBlocks.service.spec.ts | 22 +++++++++++-------- .../plugins/historical/PgBlockHeightPlugin.ts | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/node-core/src/db/migration-service/SchemaMigration.service.test.ts b/packages/node-core/src/db/migration-service/SchemaMigration.service.test.ts index 53f99b2dba..855b390380 100644 --- a/packages/node-core/src/db/migration-service/SchemaMigration.service.test.ts +++ b/packages/node-core/src/db/migration-service/SchemaMigration.service.test.ts @@ -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')); @@ -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')); @@ -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')); diff --git a/packages/node-core/src/indexer/fetch.service.spec.ts b/packages/node-core/src/indexer/fetch.service.spec.ts index a813a0d3ab..3a5d7b45ea 100644 --- a/packages/node-core/src/indexer/fetch.service.spec.ts +++ b/packages/node-core/src/indexer/fetch.service.spec.ts @@ -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', diff --git a/packages/node-core/src/indexer/unfinalizedBlocks.service.spec.ts b/packages/node-core/src/indexer/unfinalizedBlocks.service.spec.ts index 0323ad245f..c9f4fbf80f 100644 --- a/packages/node-core/src/indexer/unfinalizedBlocks.service.spec.ts +++ b/packages/node-core/src/indexer/unfinalizedBlocks.service.spec.ts @@ -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, ]); @@ -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 () => { @@ -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 @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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); }); }); diff --git a/packages/query/src/graphql/plugins/historical/PgBlockHeightPlugin.ts b/packages/query/src/graphql/plugins/historical/PgBlockHeightPlugin.ts index 01f13c3291..1b9cb1af17 100644 --- a/packages/query/src/graphql/plugins/historical/PgBlockHeightPlugin.ts +++ b/packages/query/src/graphql/plugins/historical/PgBlockHeightPlugin.ts @@ -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',