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: flatten nested arrays in parseAbiParameters #232

Merged
merged 4 commits into from
Mar 15, 2024

Conversation

xenoliss
Copy link
Contributor

@xenoliss xenoliss commented Mar 8, 2024

Description

Hopefully fix #231

Additional Information

Introduce a DeepFlatten and use it in ParseAbiParameters instead of assuming that Filter<Mapped, never> has always only one element.

NOTE: I had to update parseAbiParameters to return abiParameters as unknown as ParseAbiParameters<TParams> for the compiler to be happy but waiting for feedback.

Before submitting this issue, please make sure you do the following.

  • [x ] Read the contributing guide
  • [x ] Added documentation related to the changes made.
  • Added or updated tests (and snapshots) related to the changes made.

PR-Codex overview

This PR focuses on fixing type detection in ParseAbiParameters when using an array.

Detailed summary

  • Fixed type detection issue with arrays in ParseAbiParameters
  • Added DeepFlatten type for flattening arrays
  • Updated documentation for DeepFlatten
  • Improved parsing of human-readable ABI parameters to AbiParameter objects

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Mar 8, 2024

⚠️ No Changeset found

Latest commit: 9a03cf1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Mar 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
abitype ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 14, 2024 7:38am

@Raiden1411
Copy link
Collaborator

Can you add a test based on #231? You can use the provided playground as the base for the test. That way if there is a unforseen regression that test catches it.

@xenoliss
Copy link
Contributor Author

Sure! I noticed the type tests are failing. I need to fix that as well when I find time. Any help/guidance is welcomed

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.85%. Comparing base (6b2979f) to head (9ad4c80).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #232      +/-   ##
==========================================
+ Coverage   99.83%   99.85%   +0.01%     
==========================================
  Files          26       26              
  Lines        6082     6105      +23     
  Branches      195      195              
==========================================
+ Hits         6072     6096      +24     
  Misses          8        8              
+ Partials        2        1       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Raiden1411
Copy link
Collaborator

@xenoliss since depth flatten returns a arraylist now you need to check if it's length is 0 instead of checking if the list member is undefined which was the previous implementation so that it shows as never for the parameters.

Something like this should work. But feel free to take any other approach

? Filter<Mapped, never> extends readonly [...infer Content]
  ? Content['length'] extends 0
    ? never
    : DeepFlatten<Content>
  : never
: never

@xenoliss
Copy link
Contributor Author

Hey thank you @Raiden1411, I added your fix and it seems to work fine. I also added the playground test. Let me know how that looks to you.

@Raiden1411
Copy link
Collaborator

I think that the only thing that is missing is the changeset otherwise it looks good

@xenoliss
Copy link
Contributor Author

I added the changeset @Raiden1411

Copy link
Member

@tmm tmm left a comment

Choose a reason for hiding this comment

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

Looking good! s/o @Raiden1411 for reviewing.

"abitype": patch
---

Fix type detection when using an array in (encode|parse)AbiParameters
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Fix type detection when using an array in (encode|parse)AbiParameters
Fixed type detection when using an array in `ParseAbiParameters`

@Raiden1411 Raiden1411 merged commit 22a5f3a into wevm:main Mar 15, 2024
15 checks passed
@github-actions github-actions bot mentioned this pull request Mar 15, 2024
@xenoliss xenoliss deleted the fix/issue#231 branch March 15, 2024 20:30
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.

(encode|parse)AbiParameters detects types correctly when passed as string but not array
3 participants