Skip to content

Commit caad78e

Browse files
chore: cherry picked #2854 (#2859)
fix: duplicated transactions in transactions array on eth_getBlockByNumber (#2854) * chore: remove duplicated transactions * chore: add tests * chore: fix typo --------- Signed-off-by: nikolay <[email protected]> Signed-off-by: Logan Nguyen <[email protected]> Co-authored-by: Nikolay Atanasow <[email protected]>
1 parent e23dd2b commit caad78e

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,7 @@ export class EthImpl implements Eth {
22782278
}
22792279

22802280
transactionArray = this.populateSyntheticTransactions(showDetails, logs, transactionArray, requestIdPrefix);
2281+
transactionArray = showDetails ? _.uniqBy(transactionArray, 'hash') : _.uniq(transactionArray);
22812282

22822283
const blockHash = toHash32(blockResponse.hash);
22832284
return new Block({

packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ describe('@ethGetBlockByHash using MirrorNode', async function () {
123123
});
124124
});
125125

126+
it('eth_getBlockByHash with match and duplicated transactions', async function () {
127+
restMock.onGet(`blocks/${BLOCK_HASH}`).reply(200, DEFAULT_BLOCK);
128+
restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL).reply(200, {
129+
results: [...defaultContractResults.results, ...defaultContractResults.results],
130+
});
131+
restMock.onGet('network/fees').reply(200, DEFAULT_NETWORK_FEES);
132+
restMock.onGet(CONTRACT_RESULTS_LOGS_WITH_FILTER_URL).reply(200, DEFAULT_ETH_GET_BLOCK_BY_LOGS);
133+
134+
const res = await ethImpl.getBlockByHash(BLOCK_HASH, false);
135+
RelayAssertions.assertBlock(res, {
136+
transactions: [CONTRACT_HASH_1, CONTRACT_HASH_2],
137+
hash: BLOCK_HASH_TRIMMED,
138+
number: BLOCK_NUMBER_HEX,
139+
timestamp: BLOCK_TIMESTAMP_HEX,
140+
parentHash: BLOCK_HASH_PREV_TRIMMED,
141+
gasUsed: TOTAL_GAS_USED,
142+
});
143+
});
144+
126145
it('eth_getBlockByHash with match and valid logsBloom field', async function () {
127146
// mirror node request mocks
128147
restMock.onGet(`blocks/${BLOCK_HASH}`).reply(200, {

packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
226226
});
227227
});
228228

229+
it('eth_getBlockByNumber with match and duplicated transactions', async function () {
230+
restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL).reply(200, {
231+
results: [...defaultContractResults.results, ...defaultContractResults.results],
232+
});
233+
234+
const res = await ethImpl.getBlockByNumber(numberTo0x(BLOCK_NUMBER), false);
235+
RelayAssertions.assertBlock(res, {
236+
transactions: [CONTRACT_HASH_1, CONTRACT_HASH_2],
237+
hash: BLOCK_HASH_TRIMMED,
238+
number: BLOCK_NUMBER_HEX,
239+
timestamp: BLOCK_TIMESTAMP_HEX,
240+
parentHash: BLOCK_HASH_PREV_TRIMMED,
241+
gasUsed: TOTAL_GAS_USED,
242+
});
243+
});
244+
229245
it('eth_getBlockByNumber with match and valid logsBloom field', async function () {
230246
restMock.onGet(`blocks/${BLOCK_NUMBER}`).reply(200, {
231247
...DEFAULT_BLOCK,

0 commit comments

Comments
 (0)