hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

hardhat-chai-matchers: Test an emit event that is in a library

Open rtomas opened this issue 2 years ago • 1 comments

file Library

library Events {
    event Mint();
}

file Contract calling the event emit Event.Mint()

Can't get Chai to detect the event that is in the library

Throw this error in both cases: AssertionError: Event "Events.Mint" doesn't exist in the contract

try: await expect(contract.connect(minter).mint(data)).to.emit(contract, 'Events.Mint') or await expect(contract.connect(minter).mint(data)).to.emit(contract, 'Mint')

rtomas avatar Sep 06 '22 13:09 rtomas

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: fa1e9c33-e7b5-496d-9896-6fa97eae3ebf

github-actions[bot] avatar Sep 06 '22 13:09 github-actions[bot]

Thanks @rtomas, I can reproduce this.

Notes for ourselves:

  • The event is not part of the ABI of the contract. This is different to what happens if you use, for example, a top-level error. I don't know if this is intended behavior or a bug in solc.
  • Allowing an API like .to.emit(contract, 'MyEvent(uint)') would be an acceptable workaround and an useful feature on its own.

fvictorio avatar Oct 31 '22 17:10 fvictorio

I think this is blocked by https://github.com/ethereum/solidity/pull/10996

fvictorio avatar Dec 27 '22 13:12 fvictorio

It's not a but actually, since the "emit" checks both the contract address and its ABI, so if someone wants to get the events that have been emitted in a library, it's possible by creating a contract instance with the Library ABI and the contract address. can find how to fix this problem in the unit test in the following link:

https://ethereum.stackexchange.com/a/147619/118766

mahdiidarabi avatar Mar 19 '23 08:03 mahdiidarabi