Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 49cdaff

Browse files
committed
test: add test for content etag
1 parent ee66f93 commit 49cdaff

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/cache.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,45 @@ describe('ETag cache', () => {
244244
});
245245
expect(cacheBusted.statusCode).toBe(200);
246246
});
247+
248+
test('inscription content cache control', async () => {
249+
const block1 = new TestChainhookPayloadBuilder()
250+
.apply()
251+
.block({ height: 778575, hash: randomHash() })
252+
.transaction({ hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201' })
253+
.inscriptionRevealed({
254+
content_bytes: '0x48656C6C6F',
255+
content_type: 'text/plain',
256+
content_length: 5,
257+
inscription_number: 7,
258+
inscription_fee: 705,
259+
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
260+
inscription_output_value: 10000,
261+
inscriber_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
262+
ordinal_number: 257418248345364,
263+
ordinal_block_height: 650000,
264+
ordinal_offset: 0,
265+
satpoint_post_inscription:
266+
'9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0',
267+
})
268+
.build();
269+
await db.updateInscriptions(block1);
270+
271+
// ETag response
272+
const response = await fastify.inject({
273+
method: 'GET',
274+
url: '/ordinals/v1/inscriptions/9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0/content',
275+
});
276+
expect(response.statusCode).toBe(200);
277+
expect(response.headers.etag).not.toBeUndefined();
278+
const etag = response.headers.etag;
279+
280+
// Cached
281+
const cached = await fastify.inject({
282+
method: 'GET',
283+
url: '/ordinals/v1/inscriptions/9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0/content',
284+
headers: { 'if-none-match': etag },
285+
});
286+
expect(cached.statusCode).toBe(304);
287+
});
247288
});

0 commit comments

Comments
 (0)