Waffle
Waffle copied to clipboard
Add a way to capture events values to be able to write tests requiring them
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];
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?
Yes, it would be perfect ie args() returning the values of the event from the last emit().