From be9f5c29b1ca4db788f59ff31c667c502d76211a Mon Sep 17 00:00:00 2001 From: Blockchain Guy Date: Tue, 23 Jul 2024 20:29:17 +0530 Subject: [PATCH] feat: add rpc test to match logIndex (#284) Co-authored-by: Milap Sheth --- test/RpcCompatibility.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/RpcCompatibility.js b/test/RpcCompatibility.js index cc8acdb7..f787a854 100644 --- a/test/RpcCompatibility.js +++ b/test/RpcCompatibility.js @@ -3,7 +3,7 @@ const chai = require('chai'); const { ethers, network } = require('hardhat'); const { - utils: { hexValue, getAddress, keccak256 }, + utils: { hexValue, getAddress, keccak256, id }, Wallet, BigNumber, } = ethers; @@ -384,6 +384,33 @@ describe('RpcCompatibility', () => { }); }); + it('should return consistent logIndex values between eth_getLogs and eth_getTransactionReceipt', async () => { + const amount = 100; + + const receipt = await rpcCompatibilityContract.updateValue(amount).then((tx) => tx.wait()); + const logsFromReceipt = receipt.logs; + + const eventSignature = id('ValueUpdated(uint256)'); + const expectedEvent = logsFromReceipt.find((log) => log.topics[0] === eventSignature); + expect(expectedEvent, 'ValueUpdated event not found in logs from tx receipt').to.exist.and.to.not.be.null; + + const blockNumber = '0x' + parseInt(receipt.blockNumber).toString(16); + const logsFromGetLogs = await provider.send('eth_getLogs', [ + { + fromBlock: blockNumber, + toBlock: blockNumber, + }, + ]); + + const matchingEvent = logsFromGetLogs.find((log) => log.topics[0] === eventSignature); + expect(matchingEvent, 'ValueUpdated event not found in logs from eth_getLogs').to.not.be.null; + + expect(parseInt(expectedEvent.logIndex)).to.equal( + parseInt(matchingEvent.logIndex), + 'Log index mismatch between tx receipt and eth_getLogs', + ); + }); + describe('eip-1559 supported rpc methods', () => { if (!isHardhat) { it('should support RPC method eth_maxPriorityFeePerGas', async () => {