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 the emit and withArgs matchers for more precision.
emitCount(contract, eventName, n) - This counts the number of times an event was emitted.
emitOnce - this is syntactic sugar for emittedCount(1)
emitTwice
emitThrice
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');
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 firstTransfer
event was emitted but the 2ndTransfer
event was NOT.The
emit(Transfer).withArgs(1st_transfer_args)
chained matchers successfully match the firstTransfer
event, but chainingnot.emit(Transfer).withArgs(2nd_transfer_args)
fails to match because theTransfer
event was, in fact, emitted so thewithArgs(2nd_transfer_args)
is never evaluated.Describe the solution you'd like Some new matchers that would help:
emitWithArgs(contract, eventName, { args })
- this combines theemit
andwithArgs
matchers for more precision.emitCount(contract, eventName, n)
- This counts the number of times an event was emitted.emitOnce
- this is syntactic sugar foremittedCount(1)
emitTwice
emitThrice
Describe alternatives you've considered None.
Additional context Example usage: