Openzeppelin-contracts: Use expectEvent to test logs

Created on 23 Aug 2018  路  4Comments  路  Source: OpenZeppelin/openzeppelin-contracts

Most log tests directly access the log array: we should instead use the expectEvent helper to do that.

Example from the Escrow tests:

const { logs } = await this.escrow.deposit(payee1, { from: owner, value: amount });
expectEvent.inLogs(logs, 'Deposited', { payee: payee1 });

Part of #1091.
Requires https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1026.

good first issue tests

Most helpful comment

Yes Sir! I will do it shortly :)

All 4 comments

Hey, apart of main work for this task I faced the case where logged event argument is uint256. At truffle test level this argument is represented by BigNumber, so I tried to verify if argument was logged.

For instance:
const event = expectEvent.inLogs(currentSnapshotId.logs, 'Snapshot', { id: new BigNumber(1) });

Even the values are equal the check fails due the arguments are both struct. Please correct me if I'm missing something but I have feeling that expectEvent.inLogs method should verify equality like:
if (!_.isEqual(e.args[k], v)) {

I have tested it for my case with BigNumber and it works fine.

Hey there @jbogacz! You're absolutely right, expectEvent doesn't work properly with BigNumber values, which is why some of the tests mix both styles (e.g. they use expectEvent for event name, account, etc, but then test the values separetely). We actually have a separate issue for this: https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1026, if you can open a PR with your change to the test helper, that'd be amazing!

Yes Sir! I will do it shortly :)

Was this page helpful?
0 / 5 - 0 ratings