rkalis / truffle-assertions

🛠 Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
https://kalis.me/check-events-solidity-smart-contract-test-truffle/
MIT License
154 stars 20 forks source link

Assigning emitted event parameter to variable #36

Closed kallolborah closed 1 year ago

kallolborah commented 3 years ago

This may sound silly but I am unable to assign an indexed event parameter in a variable.

Let’s say, we have :

var result;
truffleAssert.eventEmitted(tx, EventName, (ev)=> { return ev.param; });

How do we assign ev.param to result ? When I assign it inside the scope of eventEmitted, I get an error stating ‘can’t convert undefined or null to object’. But I also see that the event is emitted in truffle test log.

Another thing I notice is that the truffle test log also prints ‘can’t decode event’ - is getting the ‘can’t assign null to object’ related to this ?

I am using TruffleSuite 5x.

rkalis commented 3 years ago

Are these events emitted by the contract that you called a function on or was it emitted in a different contract that was called somewhere in the call stack? Could you share a little bit more of the test code, e.g. where you assign tx?