Skip to content

Commit 15c0c11

Browse files
authored
fix: remove duplicate txs in microblock responses (#1167)
* test: added test for duplicate txs in microblocks * fix: rebased with develop * test: updated txs with microblock * test: removed unnecessary comments
1 parent 3ff4177 commit 15c0c11

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/datastore/pg-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ export class PgStore {
431431
const txQuery = await sql<{ tx_id: string }[]>`
432432
SELECT tx_id
433433
FROM txs
434-
WHERE microblock_hash = ${args.microblockHash}
434+
WHERE microblock_hash = ${args.microblockHash} AND canonical = true AND microblock_canonical = true
435435
ORDER BY tx_index DESC
436436
`;
437437
const microblock = parseMicroblockQueryResult(result[0]);

src/tests/api-tests.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10813,6 +10813,34 @@ describe('api tests', () => {
1081310813
expect(addressEvents.status).toBe(400);
1081410814
});
1081510815

10816+
test('/microblock/:hash duplicate txs', async () => {
10817+
const microblock_hash = '0x0fff',
10818+
tx_id = '0x1234';
10819+
const block = new TestBlockBuilder({ block_hash: '0x1234', block_height: 1 }).build();
10820+
await db.update(block);
10821+
10822+
const microblock = new TestMicroblockStreamBuilder()
10823+
.addMicroblock({ microblock_hash, parent_index_block_hash: block.block.index_block_hash })
10824+
.addTx({
10825+
tx_id,
10826+
microblock_canonical: true,
10827+
canonical: true,
10828+
index_block_hash: '0x1234',
10829+
})
10830+
.addTx({
10831+
tx_id,
10832+
microblock_canonical: false,
10833+
canonical: false,
10834+
index_block_hash: '0x123456',
10835+
})
10836+
.build();
10837+
await db.updateMicroblocks(microblock);
10838+
10839+
const result = await supertest(api.server).get(`/extended/v1/microblock/${microblock_hash}`);
10840+
expect(result.body.txs).toHaveLength(1);
10841+
expect(result.body.txs[0]).toEqual(tx_id);
10842+
});
10843+
1081610844
afterEach(async () => {
1081710845
await api.terminate();
1081810846
await db?.close();

0 commit comments

Comments
 (0)