From 3fb104c0c4d237805c8ca0c9c0e0f279bfe230e2 Mon Sep 17 00:00:00 2001 From: janniks Date: Fri, 19 May 2023 18:37:41 +0200 Subject: [PATCH] test: refactor tests to use less build() --- tests/stats.test.ts | 73 +++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/tests/stats.test.ts b/tests/stats.test.ts index efde27ea..7023104b 100644 --- a/tests/stats.test.ts +++ b/tests/stats.test.ts @@ -34,15 +34,15 @@ describe('/stats', () => { }; test('returns stats when processing blocks in order', async () => { - await db.updateInscriptions(testRevealBuilder(778_000).build()); - await db.updateInscriptions(testRevealBuilder(778_000).build()); - await db.updateInscriptions(testRevealBuilder(778_001).build()); - await db.updateInscriptions(testRevealBuilder(778_002).build()); - await db.updateInscriptions(testRevealBuilder(778_005).build()); - await db.updateInscriptions(testRevealBuilder(778_005).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); + await db.updateInscriptions(testRevealApply(778_000)); + await db.updateInscriptions(testRevealApply(778_000)); + await db.updateInscriptions(testRevealApply(778_001)); + await db.updateInscriptions(testRevealApply(778_002)); + await db.updateInscriptions(testRevealApply(778_005)); + await db.updateInscriptions(testRevealApply(778_005)); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_010)); const response = await fastify.inject({ method: 'GET', @@ -53,15 +53,15 @@ describe('/stats', () => { }); test('returns stats when processing blocks out-of-order', async () => { - await db.updateInscriptions(testRevealBuilder(778_001).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_000).build()); - await db.updateInscriptions(testRevealBuilder(778_000).build()); - await db.updateInscriptions(testRevealBuilder(778_005).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_002).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_005).build()); + await db.updateInscriptions(testRevealApply(778_001)); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_000)); + await db.updateInscriptions(testRevealApply(778_000)); + await db.updateInscriptions(testRevealApply(778_005)); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_002)); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_005)); const response = await fastify.inject({ method: 'GET', @@ -72,20 +72,20 @@ describe('/stats', () => { }); test('returns stats when processing rollbacks', async () => { - const payloadApply = testRevealBuilder(778_004).build(); + const payloadApply = testRevealApply(778_004); const payloadRollback = { ...payloadApply, apply: [], rollback: payloadApply.apply }; - await db.updateInscriptions(testRevealBuilder(778_001).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_000).build()); + await db.updateInscriptions(testRevealApply(778_001)); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_000)); await db.updateInscriptions(payloadApply); - await db.updateInscriptions(testRevealBuilder(778_005).build()); - await db.updateInscriptions(testRevealBuilder(778_000).build()); + await db.updateInscriptions(testRevealApply(778_005)); + await db.updateInscriptions(testRevealApply(778_000)); await db.updateInscriptions(payloadRollback); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_002).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); - await db.updateInscriptions(testRevealBuilder(778_005).build()); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_002)); + await db.updateInscriptions(testRevealApply(778_010)); + await db.updateInscriptions(testRevealApply(778_005)); const response = await fastify.inject({ method: 'GET', @@ -97,12 +97,12 @@ describe('/stats', () => { }); test('range filters', async () => { - await db.updateInscriptions(testRevealBuilder(778_000).build()); - await db.updateInscriptions(testRevealBuilder(778_001).build()); - await db.updateInscriptions(testRevealBuilder(778_002).build()); - await db.updateInscriptions(testRevealBuilder(778_005).build()); - await db.updateInscriptions(testRevealBuilder(778_005).build()); - await db.updateInscriptions(testRevealBuilder(778_010).build()); + await db.updateInscriptions(testRevealApply(778_000)); + await db.updateInscriptions(testRevealApply(778_001)); + await db.updateInscriptions(testRevealApply(778_002)); + await db.updateInscriptions(testRevealApply(778_005)); + await db.updateInscriptions(testRevealApply(778_005)); + await db.updateInscriptions(testRevealApply(778_010)); const responseFrom = await fastify.inject({ method: 'GET', @@ -150,7 +150,7 @@ describe('/stats', () => { }); }); -function testRevealBuilder(blockHeight: number) { +function testRevealApply(blockHeight: number) { const randomHex = [...Array(64)].map(() => Math.floor(Math.random() * 16).toString(16)).join(''); return new TestChainhookPayloadBuilder() .apply() @@ -175,5 +175,6 @@ function testRevealBuilder(blockHeight: number) { ordinal_block_height: Math.floor(Math.random() * 777_000), ordinal_offset: 0, satpoint_post_inscription: `${randomHex}:0:0`, - }); + }) + .build(); }