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

Fix multi dimensional array validation issue #6435

Merged

Conversation

fullkomnun
Copy link
Contributor

Description

Currently for a multi-dimensional array (bounded or unbounded) that follows a sibling field (is not the first field defined in its level), extrwcted JSON scheme is missing some field.

Sample ABI

[
   {
      "name":"x1",
      "type":"uint256[][]"
   },
   {
      "name":"x2",
      "type":"uint256[][]"
   },
   {
      "name":"x3",
      "type":"uint256"
   }
]

Expected JSON Scheme

  {
   "type":"array",
   "items":[
      {
         "type":"array",
         "items":[
            {
               "type":"array",
               "$id":"x1",
               "items":{
                  "format":"uint",
                  "required":true
               }
            }
         ]
      },
      {
         "type":"array",
         "items":[
            {
               "type":"array",
               "$id":"x2",
               "items":{
                  "format":"uint",
                  "required":true
               }
            }
         ]
      },
      {
         "$id":"x3",
         "format":"uint256",
         "required":true
      }
   ],
   "maxItems":3,
   "minItems":3
}

Actual JSON Scheme

{
   "type":"array",
   "items":{
      "type":"array",
      "items":[
         {
            "type":"array",
            "$id":"x2",
            "items":{
               "format":"uint",
               "required":true
            }
         },
         {
            "$id":"x3",
            "format":"uint256",
            "required":true
         }
      ]
   },
   "maxItems":3,
   "minItems":3
}

This is due to mishandling of multi-dimensional arrays when ABI is converted to JSON scheme leading to loss of parts of the scheme (in this case 'x1' input parameter from the ABI is discarded).
Fixed that and added a unit test payload to verify.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run lint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:coverage and my test cases cover all the lines and branches of the added code.
  • I ran npm run build and tested dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.
  • I have linked Issue(s) with this PR in "Linked Issues" menu.

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Merging #6435 (db8718c) into 4.x (2b445bf) will increase coverage by 0.00%.
The diff coverage is 71.42%.

❗ Current head db8718c differs from pull request most recent head 8c8f40d. Consider uploading reports for the commit 8c8f40d to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##              4.x    #6435   +/-   ##
=======================================
  Coverage   89.15%   89.16%           
=======================================
  Files         199      199           
  Lines        7756     7762    +6     
  Branches     2147     2150    +3     
=======================================
+ Hits         6915     6921    +6     
  Misses        841      841           
Flag Coverage Δ
UnitTests 89.16% <71.42%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
web3 ∅ <ø> (∅)
web3-core ∅ <ø> (∅)
web3-errors ∅ <ø> (∅)
web3-eth ∅ <ø> (∅)
web3-eth-abi ∅ <ø> (∅)
web3-eth-accounts ∅ <ø> (∅)
web3-eth-contract ∅ <ø> (∅)
web3-eth-ens ∅ <ø> (∅)
web3-eth-iban ∅ <ø> (∅)
web3-eth-personal ∅ <ø> (∅)
web3-net ∅ <ø> (∅)
web3-providers-http ∅ <ø> (∅)
web3-providers-ipc ∅ <ø> (∅)
web3-providers-ws ∅ <ø> (∅)
web3-rpc-methods ∅ <ø> (∅)
web3-utils ∅ <ø> (∅)
web3-validator ∅ <ø> (∅)

Copy link
Contributor

@jdevcs jdevcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

@fullkomnun fullkomnun force-pushed the fix_multi_dimensional_array_validation_issue branch from 1b73081 to db8718c Compare September 19, 2023 12:23
@jdevcs
Copy link
Contributor

jdevcs commented Sep 19, 2023

@fullkomnun also now there is need to fix Conflicting file. thanks.

@jdevcs jdevcs merged commit 66ddb7e into web3:4.x Sep 21, 2023
22 of 27 checks passed
@fullkomnun fullkomnun deleted the fix_multi_dimensional_array_validation_issue branch September 21, 2023 22:06
@luu-alex luu-alex mentioned this pull request Sep 29, 2023
17 tasks
@jdevcs jdevcs mentioned this pull request Oct 18, 2023
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

Successfully merging this pull request may close these issues.

None yet

4 participants