I'm currently using chai
with hardhat
and ethereum-waffle
to test my smart contracts:
const chai = require('chai')
const hre = require('hardhat')
const { solidity } = require('ethereum-waffle')
chai.use(solidity)
I have been finding it great to use.
However I have had some difficulty testing events. I'm currently using expect( ... ).to.emit( ... ).withArgs( ... )
which works for a lot of cases but not all.
Take the following example snippet from a test:
const destroyResult = await gameContract.attack([4, 0])
// Expect the game to end with the announced winner being owner
expect(destroyResult)
.to.emit(gameContract, 'GameEnd')
.withArgs(undefined, owner.address)
In this example, the GameEnd event has two arguments: the timestamp of the game ending and the address of the winner (owner.address
above). In my test, I only care about testing the 2nd argument (who won the game).
I tried providing undefined
for the timestamp, but this is not acceptable and causes the test to fail. What I need is a way to test only the 2nd argument of the event.
It would also be acceptable for me to have a function where I have access to the event object so that I can perform any test I like. However I haven't seen any way of doing this.
Any help would be appreciated, thank you!