TrueFiEng / Waffle

Library for writing and testing smart contracts.
https://getwaffle.io
MIT License
961 stars 162 forks source link

events emitted by library are not matched #609

Closed auryn-macmillan closed 2 years ago

auryn-macmillan commented 2 years ago

In this commit, we moved some events from a contract to a library that it uses. This, unfortunately, broke all of the tests that matched, with the following error: AssertionError: Expected event "AllowTarget" to be emitted, but it doesn't exist in the contract.

This is reasonable, since the contract did not contain the events. However, if I switch .to.emit(contract, 'AllowTarget') to .to.emit(library, 'Transfer'), the error changed to one saying the we expected the event to be emitted but it wasn't.

In a later commit we duplicated the events back into the original contract, but still only emit them in the library, and all of the tests pass.

My assumption is that when we defined the library contract in the listener (.to.emit(library, 'Transfer')) we must have been telling it to watch the library's address, so of course it didn't emit any events.

Is there a way to make this work without duplicating or importing the events into both contracts? i.e. assert that the contract will emit events defined in the library.

rzadp commented 2 years ago

@auryn-macmillan Please take a look at this

auryn-macmillan commented 2 years ago

cc @cristovaoth, for future reference.

auryn-macmillan commented 2 years ago

Thanks for getting back to me, @rzadp.