web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

2d array with web3 validator

Open ernieyang09 opened this issue 1 year ago • 1 comments

For below scenario, it will fail in web3 validator

    inputs: [
      { internalType: "address[]", name: "addr1", type: "address[]" },
      { internalType: "address[][]", name: "addr2", type: "address[][]" },
    ],
const addr1 = ['0xaddr']
const addr2 [['0xaddr','0xaddr','0xaddr'],['0xaddr'], ['0xaddr','0xaddr'], ...]
contract.methods.xxMethod(addr1, addr2).estimateGas()

check the jsonSchema

{"type":"array","items":[{"type":"array","$id":"addr1","items":{"format":"address","required":true}},{"type":"array","items":[{"type":"array","$id":"addr2","items":{"for
mat":"address","required":true}}]}],"maxItems":2,"minItems":2}

Also the encodeABI method gave wrong output.

Test in web3.js v1.10.2. Works as expected.

Logs

code: 1100,
      errors: [
        {
          keyword: 'maxItems',
          instancePath: '/1',
          schemaPath: '#1/maxItems',
          params: { limit: 1 },
          message: 'must NOT have more than 1 items'
        }
      ]

Environment

web3.js 4.4.0

ernieyang09 avatar Feb 08 '24 06:02 ernieyang09

Hi @ernieyang09 thanks for submitting the issue, the devs will take a look at it as soon as possible!👍

SantiagoDevRel avatar Feb 08 '24 20:02 SantiagoDevRel

Hi @ernieyang09

Hey, I'm interested in working on this one

RaghavenderSingh avatar Feb 23 '24 07:02 RaghavenderSingh

Great! Feel free to submit a PR and mention this issue on it #6798 Pls tag me so I can ping the team to look into it once it's done @RaghavenderSingh

SantiagoDevRel avatar Feb 23 '24 11:02 SantiagoDevRel

Hi @SantiagoDevRel @RaghavenderSingh , I encountered the same issue in my work. Since the project is quite urgent, I took the initiative to debug and identify the problem myself. I have already submitted a PR for it. Here is the link: #6836

EtlesL avatar Feb 27 '24 02:02 EtlesL

@EtlesL Thanks

jdevcs avatar Feb 27 '24 14:02 jdevcs