From 40506e245d209cb85011668cb7a0e2fdf1cdf9ca Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Fri, 26 Apr 2024 12:16:37 -0600 Subject: [PATCH] fix: tests --- src/pg/pg-store.ts | 5 +++-- tests/api/cache.test.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pg/pg-store.ts b/src/pg/pg-store.ts index 0bc10fa2..0dbf25a2 100644 --- a/src/pg/pg-store.ts +++ b/src/pg/pg-store.ts @@ -384,7 +384,7 @@ export class PgStore extends BasePgStore { // TODO: How do we check blocks with only transfers? return; } - const result = await sql<{ max: number; block_height: number }[]>` + const result = await sql<{ max: number | null; block_height: number }[]>` WITH tip AS (SELECT block_height::int FROM chain_tip) SELECT MAX(number)::int AS max, (SELECT block_height FROM tip) FROM inscriptions WHERE number >= 0 @@ -392,7 +392,8 @@ export class PgStore extends BasePgStore { if (!result.count) return; const data = result[0]; const firstReveal = cache.revealedNumbers.sort()[0]; - if (data.max + 1 != firstReveal) + if (data.max === null && firstReveal === 0) return; + if ((data.max ?? 0) + 1 != firstReveal) throw new BadPayloadRequestError( `Streamed block ${event.block_identifier.index} is non-contiguous, attempting to reveal #${firstReveal} when current max is #${data.max} at block height ${data.block_height}` ); diff --git a/tests/api/cache.test.ts b/tests/api/cache.test.ts index 9eca102e..9c2fc564 100644 --- a/tests/api/cache.test.ts +++ b/tests/api/cache.test.ts @@ -21,6 +21,7 @@ describe('ETag cache', () => { test('inscription cache control', async () => { const block = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 775617 }) .transaction({ hash: '0x38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc' }) @@ -88,6 +89,7 @@ describe('ETag cache', () => { // Perform transfer and check cache await db.updateInscriptions( new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 775618, timestamp: 1678122360 }) .transaction({ @@ -125,6 +127,7 @@ describe('ETag cache', () => { // Perform transfer GAP FILL and check cache await db.updateInscriptions( new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 775619, timestamp: 1678122360 }) .transaction({ @@ -161,6 +164,7 @@ describe('ETag cache', () => { test('inscriptions index cache control', async () => { const block1 = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 778575 }) .transaction({ hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201' }) @@ -194,6 +198,7 @@ describe('ETag cache', () => { .build(); await db.updateInscriptions(block1); const block2 = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 778576 }) .transaction({ hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' }) @@ -246,6 +251,7 @@ describe('ETag cache', () => { // New location const block3 = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 778577 }) .transaction({ hash: 'ae9d273a10e899f0d2cad47ee2b0e77ab8a9addd9dd5bb5e4b03d6971c060d52' }) @@ -274,6 +280,7 @@ describe('ETag cache', () => { test('inscriptions stats per block cache control', async () => { const block1 = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 778575, hash: randomHash() }) .transaction({ hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201' }) @@ -326,6 +333,7 @@ describe('ETag cache', () => { // New block const block2 = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 778576, hash: randomHash() }) .transaction({ hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' }) @@ -370,6 +378,7 @@ describe('ETag cache', () => { test('status etag changes with new block', async () => { const block1 = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 778575, hash: randomHash() }) .transaction({ hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201' }) @@ -422,6 +431,7 @@ describe('ETag cache', () => { // New block const block2 = new TestChainhookPayloadBuilder() + .streamingBlocks(true) .apply() .block({ height: 778576, hash: randomHash() }) .transaction({ hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' })