I am calling a contract function which emits an event in a transaction. This transaction should include the event and is typically visible via:
const receipt = await contractInstance.someFunction()
let logs = receipt.logs
This normally contains a list of the emitted event names in the transaction. However in my call the tests output:
[]
1) Test someFunction()
Events emitted during test:
---------------------------
Stored()
---------------------------
1 failing
1) Contract: Test.js
Test someFunction():
AssertionError: Stored event not emitted: expected false to be truthy
at Context.it (test/test.js:145:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
with testing block that fails:
const receipt = await instance.someFunction();
let event = validationReceipt.logs.some(l => { return l.event == "Stored" });
console.log(validationReceipt.logs);
assert.ok(event, "Stored event not emitted");
First line performs the function call which emits the event Stored
. Second line retrieves the instance by event name from the logs. Third line simply logs the contained events. Fourth line asserts that the event exists in the logs.
As shown in the test output, the logs were empty []
, but the event was emitted.
Why is the event being shown to have been emitted but also not present in the logs of the transaction that emitted it?