Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated bindings fail to decode events #142

Open
michaelbajor opened this issue May 3, 2024 · 1 comment
Open

Generated bindings fail to decode events #142

michaelbajor opened this issue May 3, 2024 · 1 comment

Comments

@michaelbajor
Copy link

michaelbajor commented May 3, 2024

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:

  1. The tx is sent and executed on the node (running substrate-contracts-node for testing).
  2. Then, the code attempts to decode events by calling a decodeEvents function in <typechain-generated-dir>/shared/utils.ts.
  3. In this function, there is a line: const {args, event} = contract.abi.decodeEvent(data);
  4. In there, this.__internal__decodeEventV4 function is called.
  5. It is in this function that the problem occurs, as this is its definition:
__internal__decodeEventV4 = (record) => {
        const data = record.event.data[1]; // this line causes the error
        const index = data[0];
        const event = this.events[index];
        if (!event) {
            throw new Error(`Unable to find event with index ${index}`);
        }
        return event.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:

image

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).

The dependencies:

"dependencies": {
    "@727-ventures/typechain-compiler": "^1.1.4",
    "@727-ventures/typechain-polkadot": "^1.1.1",
    "@727-ventures/typechain-types": "^1.1.2",
    "@polkadot/util": "^12.6.2",
    "@polkadot/util-crypto": "^12.6.2",
    "@types/bn.js": "^5.1.0",
    "@types/eslint": "^8.4.3",
    "@types/jest": "^27.5.2",
    "@types/node": "*",
    "@typescript-eslint/eslint-plugin": "^5.25.0",
    "@typescript-eslint/parser": "^5.25.0",
    "eslint": "^8.18.0",
    "eslint-import-resolver-typescript": "^2.7.1",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-node": "^11.1.0",
    "hjson": "^3.2.2",
    "jest": "^28.0.0",
    "scale-ts": "^1.6.0",
    "ts-jest": "^28.0.0",
    "typescript": "^4.7.4"
  }
@michaelbajor
Copy link
Author

Not sure, but may be related to #105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant