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

function encodeValueContent does not work with tuples #489

Open
1 of 4 tasks
CJ42 opened this issue Nov 7, 2024 · 0 comments
Open
1 of 4 tasks

function encodeValueContent does not work with tuples #489

CJ42 opened this issue Nov 7, 2024 · 0 comments
Labels
discussion enhancement New feature or request help wanted Extra attention is needed

Comments

@CJ42
Copy link
Collaborator

CJ42 commented Nov 7, 2024

I'm submitting a...

  • bug report
  • feature request
  • question about the decisions made in the repository
  • question about how to use this project

Summary

The following function does not work.

// {
  //   "name": "LSP8ReferenceContract",
  //   "key": "0x708e7b881795f2e6b6c2752108c177ec89248458de3bf69d0d43480b3e5034e6",
  //   "keyType": "Singleton",
  //   "valueType": "(address,bytes32)",
  //   "valueContent": "(Address,Bytes32)"
  // }
  test('render view with data key `LSP8ReferenceContract` + data value = tuple (address,bytes32) as [ "0xcafecafecafecafecafecafecafecafecafecafe", "0xbeefbeef...beefbeef" ]', async () => {
    const expectedDataKeyText = 'LSP8TokenIdFormat'
    const expectedDataValueText =
      '[ "0xcafecafecafecafecafecafecafecafecafecafe", "0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef" ]'

    const encodedDataValue = ERC725.encodeValueContent('(Address,Bytes32)', [
      '0xcafecafecafecafecafecafecafecafecafecafe',
      '0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef',
    ])

    render(DefaultSetDataKey, {
      props: {
        transaction: {
          to: UP_ADDRESS_EXAMPLE,
        },
        setDataKeyValuePair: {
          setDataKey: ERC725YDataKeys.LSP8.LSP8TokenIdFormat,
          setDataValue: encodedDataValue,
        },
      },
    })

    expect(await screen.findByTestId('set-data-key-text')).toHaveTextContent(
      expectedDataKeyText
    )
    expect(await screen.findByTestId('set-data-value-text')).toHaveTextContent(
      expectedDataValueText
    )
  })

It generates the following errors:

Error: Argument of type 'string[]' is not assignable to parameter of type 'string | number | boolean | AssetURLEncode | URLDataToEncode'

Encoding tuples is still possible with the encodeData function, but this requires to pass a schema, which increases a bit the complexity of the library.
It should be consider whether we want to allow or not tuple encoding / decoding with the encodeValueContent function for simplicity for developers.

@CJ42 CJ42 added help wanted Extra attention is needed discussion enhancement New feature or request labels Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant