truffle-assertions icon indicating copy to clipboard operation
truffle-assertions copied to clipboard

Support numeric event parameter

Open TripleSpeeder opened this issue 5 years ago • 2 comments

Numeric event parameters (e.g. uint256 in solidity) are represented as bn.js instances. It looks like currently it is not possible to check these numbers, as the equality check is not aware of BN and thus fails.

Ideally i would be able to create a filter Object with BN instances. Assume a transaction emits the event "idEvent" with the parameter "id" being an uint256, i would like to do:

truffleAssert.eventEmitted(result, 'IdEvent', {
    id: new BN('1')
})

Describe alternatives you've considered Another option would be to check the string representation of a BN instance, so one could write the filter like this:

truffleAssert.eventEmitted(result, 'IdEvent', {
    id: '1'
})

(This is what web3.eth.abi.decodeLog does - any BN instance is decoded to it's string representation)

TripleSpeeder avatar Jan 29 '20 09:01 TripleSpeeder

Thanks @TripleSpeeder! This should definitely be supported if it currently isn't. I will look into it.

rkalis avatar Jan 29 '20 10:01 rkalis

This seems to be an available feature now. I'm currently able to create a filter to check for the parameter value of type uint256 using this:

truffleAssert.eventEmitted(tx, 'IdEvent', { id: web3.utils.toBN(10000) });

I'm not sure if this was recently added and this issue was never closed, or if this always existed.

dpurhar27 avatar Feb 27 '20 21:02 dpurhar27