2

I'm currently testing events that include numeric values:

const level = new BN(1);
truffleAssert.eventEmitted(tx, 'EventName', {level});

As you can see, the level variable is a BN, and holds the correct value, I've already checked that. However two BN objects seem not to be equal when comparing through eventEmitted.

I know I can do it in the following way:

const level = new BN(1);
truffleAssert.eventEmitted(tx, 'EventName', e => e.level.toString() === level.toString());

However this second way is less intuitive, longer to write, harder to maintain and definitely much dirtier.

Do you guys know if there's a workaround to make this work using objects rather than filter functions?

2

Actually never mind, I just found the solution, which is definitely not very intuitive. I leave it here in case it can help someone.

const level = web3.utils.toBN(1);  // <------ we must use this function
truffleAssert.eventEmitted(tx, 'EventName', {level});  // now this works

So just using web3.utils.toBN suffices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.