Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emitWithArgs(contract, eventName, {args}) and emitCount(n) #835

Open
MantisClone opened this issue Sep 5, 2023 · 0 comments
Open

emitWithArgs(contract, eventName, {args}) and emitCount(n) #835

MantisClone opened this issue Sep 5, 2023 · 0 comments

Comments

@MantisClone
Copy link

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:

  1. emitWithArgs(contract, eventName, { args }) - this combines the emit and withArgs matchers for more precision.
  2. emitCount(contract, eventName, n) - This counts the number of times an event was emitted.
  3. emitOnce - this is syntactic sugar for emittedCount(1)
  4. emitTwice
  5. 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');
@MantisClone MantisClone changed the title emittedWithArgs(contract, eventName, {args}) and emittedCount(n) emitWithArgs(contract, eventName, {args}) and emitCount(n) Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
@MantisClone and others