Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Apr 26, 2024
1 parent fe81f5a commit 40506e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,16 @@ 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
`;
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}`
);
Expand Down
10 changes: 10 additions & 0 deletions tests/api/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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' })
Expand Down Expand Up @@ -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' })
Expand Down Expand Up @@ -246,6 +251,7 @@ describe('ETag cache', () => {

// New location
const block3 = new TestChainhookPayloadBuilder()
.streamingBlocks(true)
.apply()
.block({ height: 778577 })
.transaction({ hash: 'ae9d273a10e899f0d2cad47ee2b0e77ab8a9addd9dd5bb5e4b03d6971c060d52' })
Expand Down Expand Up @@ -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' })
Expand Down Expand Up @@ -326,6 +333,7 @@ describe('ETag cache', () => {

// New block
const block2 = new TestChainhookPayloadBuilder()
.streamingBlocks(true)
.apply()
.block({ height: 778576, hash: randomHash() })
.transaction({ hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' })
Expand Down Expand Up @@ -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' })
Expand Down Expand Up @@ -422,6 +431,7 @@ describe('ETag cache', () => {

// New block
const block2 = new TestChainhookPayloadBuilder()
.streamingBlocks(true)
.apply()
.block({ height: 778576, hash: randomHash() })
.transaction({ hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' })
Expand Down

0 comments on commit 40506e2

Please sign in to comment.