Skip to content

Commit

Permalink
test: refactor tests to use less build()
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed May 19, 2023
1 parent 9af6988 commit 152c70e
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions tests/stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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()
Expand All @@ -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();
}

0 comments on commit 152c70e

Please sign in to comment.