Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rpc test to match logIndex #284

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 20 additions & 0 deletions contracts/test/TestRpcCompatibility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ contract TestRpcCompatibility {

event ValueUpdated(uint256 indexed value);
event ValueUpdatedForSubscribe(uint256 indexed value);
event ContractCallWithToken(
address indexed sender,
string destinationChain,
string destinationContractAddress,
bytes32 indexed payloadHash,
bytes payload,
string symbol,
uint256 amount
);

function getValue() public view returns (uint256) {
return value;
Expand All @@ -21,4 +30,15 @@ contract TestRpcCompatibility {
subscribeValue = newValue;
emit ValueUpdatedForSubscribe(newValue);
}

function emitCallContractWithToken(
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
string calldata destinationChain,
string calldata destinationContractAddress,
bytes32 payloadHash,
bytes calldata payload,
string calldata symbol,
uint256 amount
) external {
emit ContractCallWithToken(msg.sender, destinationChain, destinationContractAddress, payloadHash, payload, symbol, amount);
}
}
36 changes: 35 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,40 @@ describe('RpcCompatibility', () => {
});
});

it('should match the fetched logIndex value', async function () {
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
const destinationChain = 'Ethereum';
const destinationContractAddress = '0x0000000000000000000000000000000000000001';
const payload = '0x01';
const payloadHash = keccak256(payload);
const symbol = 'TOKEN';
const amount = 100;

const receipt = await rpcCompatibilityContract
.emitCallContractWithToken(destinationChain, destinationContractAddress, payloadHash, payload, symbol, amount)
.then((tx) => tx.wait());
const logsFromReceipt = receipt.logs;

const eventSignature = id('ContractCallWithToken(address,string,string,bytes32,bytes,string,uint256)');
const expectedEvent = logsFromReceipt.find((log) => log.topics[0] === eventSignature);
expect(expectedEvent, 'ContractCallWithToken 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, 'ContractCallWithToken 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
Loading