Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/datastore/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
28 changes: 28 additions & 0 deletions src/tests/api-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down