OpenZeppelin / openzeppelin-test-helpers

Assertion library for Ethereum smart contract testing
https://docs.openzeppelin.com/test-helpers
MIT License
416 stars 132 forks source link

An event signature in 'inTransaction' is incorrect if the event has a struct as an argument #178

Open Vsevo1od opened 2 years ago

Vsevo1od commented 2 years ago

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');
})