Skip to content

Commit dec3aeb

Browse files
authored
fix: fixes check to remove duplicates from transactionArray (#3731)
Signed-off-by: Simeon Nakov <[email protected]>
1 parent c5a8efb commit dec3aeb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,7 @@ export class EthImpl implements Eth {
28812881
);
28822882
}
28832883

2884+
transactionsArray = _.uniqWith(transactionsArray, _.isEqual);
28842885
return transactionsArray;
28852886
}
28862887

@@ -2948,8 +2949,6 @@ export class EthImpl implements Eth {
29482949
}
29492950

29502951
transactionArray = this.populateSyntheticTransactions(showDetails, logs, transactionArray, requestDetails);
2951-
transactionArray = showDetails ? transactionArray : _.uniq(transactionArray);
2952-
29532952
const formattedReceipts: IReceiptRootHash[] = ReceiptsRootUtils.buildReceiptRootHashes(
29542953
transactionArray.map((tx) => (showDetails ? tx.hash : tx)),
29552954
contractResults,

packages/relay/tests/lib/ethGetBlockBy.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,20 @@ describe('eth_getBlockBy', async function () {
277277
expect(txObjects[1].hash).to.equal(modelLog2.transactionHash);
278278
expect(txObjects[2].hash).to.equal(modelLog3.transactionHash);
279279
});
280+
281+
it('deduplicates duplicate transaction objects in the result', async function () {
282+
const tx1 = getTransactionModel(modelLog1.transactionHash);
283+
const tx2 = getTransactionModel(modelLog1.transactionHash); // duplicate hash, different object
284+
const initTxObjects = [tx1, tx2];
285+
286+
const txObjects = initTxObjects.slice();
287+
const returnedTxObjects = ethImpl.populateSyntheticTransactions(true, referenceLogs, txObjects, requestDetails);
288+
289+
// Should only have one object with modelLog1.transactionHash
290+
const count = returnedTxObjects.filter((tx) => tx.hash === modelLog1.transactionHash).length;
291+
expect(count).to.equal(1);
292+
293+
expect(returnedTxObjects.length).to.equal(referenceLogs.length);
294+
});
280295
});
281296
});

0 commit comments

Comments
 (0)