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

Add a way to capture events values to be able to write tests requiring them #730

Open
bhuisgen opened this issue May 16, 2022 · 2 comments

Comments

@bhuisgen
Copy link

As the issue #581, I need an easy way to capture values from event to reuse them.

For the moment and thanks to @wminshew I did this:

  it('should burn tokens if asked', async () => {
    const response = await (
      await contract.safeMint(await owner.getAddress())
    ).wait();

    expect(response.events[0].event).to.equals('Transfer');
    const [, , tokenId] = response.events.[0].args;

    await expect(await contract.burn(tokenId)).to.emit(contract, 'Transfer');
  });

Note the boring stuff about response / await / await / wait and the required expect on the event name. Maybe something like that could be interesting:

const args = await expect(await contract.safeMint(await owner.getAddress())).to.emit(contract, 'Transfer').args();
const tokenId = args[2];
@rzadp
Copy link
Contributor

rzadp commented May 17, 2022

Interesting, wondering what we would like to return in the case of chaining the matcher, ie:

await expect(tx)
  .to.emit(contract, 'Transfer')
  .to.emit(contract, 'Mint')
  .args()

Just the arguments of the last one, Mint?
Have you thought about this, what would make sense to you in this case?

@bhuisgen
Copy link
Author

Yes, it would be perfect ie args() returning the values of the event from the last emit().

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