Skip to content

Commit

Permalink
feat: add rpc test to match logIndex (#284)
Browse files Browse the repository at this point in the history
Co-authored-by: Milap Sheth <milap@interoplabs.io>
  • Loading branch information
blockchainguyy and milapsheth authored Jul 23, 2024
1 parent 0213a39 commit be9f5c2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion test/RpcCompatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit be9f5c2

Please sign in to comment.