openzeppelin-test-helpers
openzeppelin-test-helpers copied to clipboard
An event signature in 'inTransaction' is incorrect if the event has a struct as an argument
A quick solution is to replace this line
const eventSignature = `${eventName}(${eventABI.inputs.map(input => input.type).join(',')})`;
with
const eventSignature = `${eventName}(${eventABI.inputs.map(input => {
if (input.type === 'tuple'){
return `(${input.components.map(input => input.type).join()})`
}
return input.type;
}
).join(',')})`;
At least it works in my case An example contract that can be used to reproduce the issue
pragma solidity 0.8.7;
contract Issue {
struct AStruct {
uint256 someValue;
}
event AnEvent(AStruct aStruct);
function doEmit() external {
emit AnEvent(AStruct({someValue: 0}));
}
}
A test
import {artifacts, ethers} from "hardhat";
import {expectEvent} from "@openzeppelin/test-helpers";
import {test} from "mocha";
test('is emitted', async () => {
const [deployer] = await ethers.getSigners();
const factory = await ethers.getContractFactory('Issue', deployer);
const contract = await factory.deploy();
const tx = await contract.doEmit();
await expectEvent.inTransaction(tx.hash, artifacts.require('Issue'), 'AnEvent');
})