-
Notifications
You must be signed in to change notification settings - Fork 179
Open
Labels
Description
Is your feature request related to a problem? Please describe.
My contract function emits the Transfer event twice with different arguments if certain conditions are met but only once otherwise. I want to write a test where I check that the first Transfer event was emitted but the 2nd Transfer event was NOT.
The emit(Transfer).withArgs(1st_transfer_args) chained matchers successfully match the first Transfer event, but chaining not.emit(Transfer).withArgs(2nd_transfer_args) fails to match because the Transfer event was, in fact, emitted so the withArgs(2nd_transfer_args) is never evaluated.
Describe the solution you'd like
Some new matchers that would help:
emitWithArgs(contract, eventName, { args })- this combines theemitandwithArgsmatchers for more precision.emitCount(contract, eventName, n)- This counts the number of times an event was emitted.emitOnce- this is syntactic sugar foremittedCount(1)emitTwiceemitThrice
Describe alternatives you've considered
None.
Additional context
Example usage:
// In this test, only the first Transfer event is emitted
await expect(contract.transferAtLeastOnceButSometimesTwice())
.to.emitWithArgs(contract, 'Transfer', { "1st_transfer_args" })
.to.not.emitWithArgs(contract, 'Transfer', { "2nd_transfer_args" })
.to.emitCount(contract, 'Transfer', 1)
.to.emitOnce(contract, 'Transfer');