You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whenever a contract is emitting an event, the jest tests fail due to TypeError: Cannot read properties of undefined (reading 'data'). I've debugged the test case, and it turned out that this is the flow of execution:
The tx is sent and executed on the node (running substrate-contracts-node for testing).
Then, the code attempts to decode events by calling a decodeEvents function in <typechain-generated-dir>/shared/utils.ts.
In this function, there is a line: const {args, event} = contract.abi.decodeEvent(data);
In there, this.__internal__decodeEventV4 function is called.
It is in this function that the problem occurs, as this is its definition:
__internal__decodeEventV4=(record)=>{constdata=record.event.data[1];// this line causes the errorconstindex=data[0];constevent=this.events[index];if(!event){thrownewError(`Unable to find event with index ${index}`);}returnevent.fromU8a(data.subarray(1));};
It attempts to read the property data on the event. However, the VS Code debugger shows that there is no event property defined on the object that it's executing on. Here is the screenshot of the type that's there:
I believe it should do:
const data = record;
Furthermore, I believe this is not the issue related to using v4 instead of v5, as at __internal__decodeEventV5 also would take the same object as the argument and try to get the data in the same manner (also trying to get record.topics[0] before that which would fail too, in my opinion).
Whenever a contract is emitting an event, the
jest
tests fail due toTypeError: Cannot read properties of undefined (reading 'data')
. I've debugged the test case, and it turned out that this is the flow of execution:substrate-contracts-node
for testing).decodeEvents
function in<typechain-generated-dir>/shared/utils.ts
.const {args, event} = contract.abi.decodeEvent(data);
this.__internal__decodeEventV4
function is called.It attempts to read the property
data
on theevent
. However, the VS Code debugger shows that there is noevent
property defined on the object that it's executing on. Here is the screenshot of the type that's there:I believe it should do:
const data = record;
Furthermore, I believe this is not the issue related to using v4 instead of v5, as at
__internal__decodeEventV5
also would take the same object as the argument and try to get thedata
in the same manner (also trying to getrecord.topics[0]
before that which would fail too, in my opinion).The dependencies:
The text was updated successfully, but these errors were encountered: