At present there is no way I can see or is documented to be able to easily use something like this with the truffle framework:
So using chai and writing a test to deploy a contract with something like this.
c = await MyContract.new();
// this wont work...
truffleAssert.eventEmitted(c, "ContractCreated", (ev) => {
return ev.param === myInputParam;
});
My contract constructor will emit a ContractCreated
event. I want to assert that this happened and the values are as expected. The event itself and its content is irrelevant. Its more the process of asserting events were emitted and contract construction time is important.
I would expect or want that I can do this assertion and use the assertEventEmitted
function above.
Currently the only way I can see to accomplish this is so:
let event = c.allEvents({fromBlock: 0, toBlock: 'latest'});
event.watch(function (error, result) {
if (!error){
console.log("Result: ", result);
// or some assertions similar to assertEventEmitted(...)
}
});
I can't find an elegant way to read the event logs emitted during contract construction using the truffle toolset.
When you send a transaction in you get the result object you can assert, upon contract creation the object returned is different and as such the logs are not available to check for event emission.
Does anyone know of a way to get those event logs from a truffle contract creation call and use the truffle-assertions.assertEventEmitted
function to test with?
Thanks in Advance.