Skip to content

Commit 90484ec

Browse files
committed
add test filtering nakamoto coinbase
1 parent dae3758 commit 90484ec

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/api/tx.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,6 +2698,59 @@ describe('tx tests', () => {
26982698
.build();
26992699
await db.update(block3);
27002700

2701+
const block4 = new TestBlockBuilder({
2702+
block_height: 4,
2703+
index_block_hash: '0x04',
2704+
parent_block_hash: block3.block.block_hash,
2705+
parent_index_block_hash: block3.block.index_block_hash,
2706+
burn_block_time: 1740000000,
2707+
}).addTx({
2708+
tx_id: '0x4234',
2709+
fee_rate: 4n,
2710+
sender_address: testSendertAddr,
2711+
nonce: 4,
2712+
type_id: DbTxTypeId.NakamotoCoinbase,
2713+
coinbase_vrf_proof: '0x01',
2714+
}).build();
2715+
await db.update(block4);
2716+
2717+
// Ensure chain_tip reflects latest height for maxHeight filtering
2718+
const txCountRes = await client<{ count: number }[]>`
2719+
SELECT COUNT(*)::integer AS count FROM txs
2720+
`;
2721+
const txCount = txCountRes[0]?.count ?? 0;
2722+
await client`
2723+
INSERT INTO chain_tip (
2724+
id,
2725+
block_height,
2726+
block_hash,
2727+
index_block_hash,
2728+
burn_block_height,
2729+
block_count,
2730+
microblock_count,
2731+
tx_count,
2732+
tx_count_unanchored
2733+
) VALUES (
2734+
true,
2735+
${block4.block.block_height},
2736+
${block4.block.block_hash},
2737+
${block4.block.index_block_hash},
2738+
${block4.block.burn_block_height},
2739+
${block4.block.block_height},
2740+
0,
2741+
${txCount},
2742+
${txCount}
2743+
)
2744+
ON CONFLICT (id) DO UPDATE SET
2745+
block_height = EXCLUDED.block_height,
2746+
block_hash = EXCLUDED.block_hash,
2747+
index_block_hash = EXCLUDED.index_block_hash,
2748+
burn_block_height = EXCLUDED.burn_block_height,
2749+
block_count = EXCLUDED.block_count,
2750+
tx_count = EXCLUDED.tx_count,
2751+
tx_count_unanchored = EXCLUDED.tx_count_unanchored
2752+
`;
2753+
27012754
const filterTypes: TransactionType[] = ['coinbase', 'poison_microblock', 'token_transfer'];
27022755
const txsReq1 = await supertest(api.server).get(
27032756
`/extended/v1/tx?type=${filterTypes.join(',')}`
@@ -2706,6 +2759,9 @@ describe('tx tests', () => {
27062759
expect(txsReq1.body).toEqual(
27072760
expect.objectContaining({
27082761
results: [
2762+
expect.objectContaining({
2763+
tx_id: block4.txs[0].tx.tx_id,
2764+
}),
27092765
expect.objectContaining({
27102766
tx_id: block3.txs[0].tx.tx_id,
27112767
}),

0 commit comments

Comments
 (0)