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
This commit is contained in:
M Hassan Tariq
2022-05-24 20:46:00 +05:00
committed by GitHub
parent 3ff41779f8
commit 15c0c1124a
2 changed files with 29 additions and 1 deletions

View File

@@ -431,7 +431,7 @@ export class PgStore {
const txQuery = await sql<{ tx_id: string }[]>`
SELECT tx_id
FROM txs
WHERE microblock_hash = ${args.microblockHash}
WHERE microblock_hash = ${args.microblockHash} AND canonical = true AND microblock_canonical = true
ORDER BY tx_index DESC
`;
const microblock = parseMicroblockQueryResult(result[0]);

View File

@@ -10813,6 +10813,34 @@ describe('api tests', () => {
expect(addressEvents.status).toBe(400);
});
test('/microblock/:hash duplicate txs', async () => {
const microblock_hash = '0x0fff',
tx_id = '0x1234';
const block = new TestBlockBuilder({ block_hash: '0x1234', block_height: 1 }).build();
await db.update(block);
const microblock = new TestMicroblockStreamBuilder()
.addMicroblock({ microblock_hash, parent_index_block_hash: block.block.index_block_hash })
.addTx({
tx_id,
microblock_canonical: true,
canonical: true,
index_block_hash: '0x1234',
})
.addTx({
tx_id,
microblock_canonical: false,
canonical: false,
index_block_hash: '0x123456',
})
.build();
await db.updateMicroblocks(microblock);
const result = await supertest(api.server).get(`/extended/v1/microblock/${microblock_hash}`);
expect(result.body.txs).toHaveLength(1);
expect(result.body.txs[0]).toEqual(tx_id);
});
afterEach(async () => {
await api.terminate();
await db?.close();