hardhat
hardhat copied to clipboard
hardhat-chai-matchers: Test an emit event that is in a library
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')
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
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.
I think this is blocked by https://github.com/ethereum/solidity/pull/10996
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