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

fix: tuples response parser, for nested tuples, or tuple including Result

Open PhilippeR26 opened this issue 1 year ago • 1 comments

Motivation and Resolution

Solve issue #997

  • If the tuple includes a Result enum, the parse is wrong (because the Result type includes a , : Result<u64, u8>
  • if it's nested tuples (more than 2 levels), it's not handled by the parser.

Usage related changes

Such Abi outputs are now handled (in Cairo 1):

((u256,(u16,Order2)), u8)
(Result<u64, u8>, u8)
(tupleResponse::tupleResponse::Direction, core::integer::u8) // where Direction type can be a Result type

Development related changes

  • the tuple parser was splitting the abi output string, using , as splitter, and was not able to handle more than 2 levels of tuples. This code has been completely rewritten.
  • Tests : a dedicated test contract has been added, and tests have been added in Cairo1v2.test.ts

Checklist:

  • [x] Performed a self-review of the code
  • [x] Rebased to the last commit of the target branch (or merged it into my branch)
  • [x] Linked the issues which this PR resolves
  • [x] Documented the changes in code (API docs will be generated automatically)
  • [x] Updated the tests
  • [x] All tests are passing

PhilippeR26 avatar Mar 06 '24 15:03 PhilippeR26

I wanted to test a refactoring suggestion and I noticed that some of the tests don't fully check the code.

On this branch you can see that part of the code is commented out but the tests still pass. The code does get passed through when it is not removed, but when it is removed the fallback conditional is sufficient to produce the expected result for the corresponding tests.

It should be better now. I have already tried a refactor of this part of the code, using .some(), but i had an error message due to variable posStart.

PhilippeR26 avatar Mar 07 '24 11:03 PhilippeR26

:tada: This PR is included in version 6.2.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Mar 11 '24 07:03 github-actions[bot]

:tada: This issue has been resolved in version 7.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jul 03 '24 10:07 github-actions[bot]