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

Upgrade breaks Interaction serialization with native variadic arguments #306

Closed
michavie opened this issue Jun 22, 2023 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@michavie
Copy link
Contributor

Upgrading from 12.1.0 breaks transactions using native variadic arguments, with this error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'belongsToTypesystem')
    at eu (_app-e1ba62606a0e66e8.js:5:31477)
    at Object.ec [as nativeToTypedValues] (_app-e1ba62606a0e66e8.js:5:31004)
    at methods.<computed> [as someMethod] (_app-e1ba62606a0e66e8.js:5:42871)
    at U (3032-5df52ac79f3887e8.js:1:27869)
    at async Object.S [as someOtherMethod] (3032-5df52ac79f3887e8.js:1:26988)

Worked before and fails after upgrade for Interactions:

const interactionArgs = [
    someValue,
    ...['a', 'b', 'c'], // <--- used to work, but now causes errors with latest versions
  ]

Using VariadicValue is a temporary fix, but ideally, native values would keep working

Likely caused by this change here: 973c823

@andreibancioiu andreibancioiu self-assigned this Jun 22, 2023
@andreibancioiu andreibancioiu added the bug Something isn't working label Jun 22, 2023
@andreibancioiu
Copy link
Contributor

andreibancioiu commented Jun 22, 2023

Hi @michavie,

Thank you for raising the issue 🙏

Do you think you can help us reproduce the issue, by altering the following test case (the one below passes)?

it.only("issue 306", async () => {
    const endpoint = AbiRegistry.create({
        "endpoints": [
            {
                "name": "foo",
                "inputs": [{
                    "type": "u64"
                }, {
                    "type": "variadic<bytes>"
                }],
                "outputs": []
            }
        ]
    }).getEndpoint("foo");

    // Using both native JavaScript objects and typed values
    const typedValues = NativeSerializer.nativeToTypedValues([
        42,
        ...['a', 'b', 'c'],
    ], endpoint);

    assert.deepEqual(typedValues[0].getType(), new U64Type());
    assert.deepEqual(typedValues[0].valueOf(), new BigNumber(42));
    assert.deepEqual(typedValues[1].getType(), new VariadicType(new BytesType()));
    assert.deepEqual(typedValues[1].valueOf(), [Buffer.from('a'), Buffer.from('b'), Buffer.from('c')]);
});

Thank you!

@michavie
Copy link
Contributor Author

michavie commented Jun 22, 2023

I could reproduce the error in the test results by not providing any values, as in spreading an empty array: ...[] or providing no value at all

Would make sense as ...[] evaluates to undefined and giving no value also equals undefined

Sorry for the initial sloppy example

Submitted a quick PR here: #307

@andreibancioiu
Copy link
Contributor

Fixed by your PR, #307.

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants