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

feat[lang]: support top level "abi" key in json interfaces #4279

Merged
merged 7 commits into from
Oct 14, 2024

Conversation

sandbubbles
Copy link
Contributor

@sandbubbles sandbubbles commented Oct 8, 2024

What I did

address #4231

How I did it

How to verify it

Commit message

some frameworks produce json ABI files with `"abi"` as a top-level
key. this decreases a bit of friction for using those ABI files.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

code = """
from . import json
"""
input_bundle = make_input_bundle({"json.json": json, "code.vy": code})
Copy link
Member

Choose a reason for hiding this comment

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

maybe let's call the file abi.json or stream.json

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

looks good. did you find the commit where the regression was introduced?

@sandbubbles
Copy link
Contributor Author

looks good. did you find the commit where the regression was introduced?

No no, should i look into it?

@charles-cooper
Copy link
Member

looks good. did you find the commit where the regression was introduced?

No no, should i look into it?

yes please -- i was going to include it when drafting the commit message

@sandbubbles
Copy link
Contributor Author

looks good. did you find the commit where the regression was introduced?

No no, should i look into it?

yes please -- i was going to include it when drafting the commit message

I think it was always there.

6b8b7f6c558cff79f5b552ed8a13df296b469a58 is the first bad commit
commit 6b8b7f6c558cff79f5b552ed8a13df296b469a58
Author: Ben Hauser <ben@hauser.id>
Date:   Fri Aug 21 17:15:06 2020 +0300

    refactor: allow access to vyper-json via vyper-compile

 vyper/cli/vyper_compile.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

when run against

{
 "abi": [
   {
     "name": "validate",
     "inputs": [
       { "name": "creator", "type": "address" },
       { "name": "token", "type": "address" },
       { "name": "amount_per_second", "type": "uint256" },
       { "name": "reason", "type": "bytes" }
     ],
     "outputs": [{ "name": "max_stream_life", "type": "uint256" }]
   }
 ]
}

The error was the same across all commits.

@charles-cooper
Copy link
Member

something is weird, because we theoretically used to have code to handle this, e.g.

# ABI JSON file (either `List[ABI]` or `{"abi": List[ABI]}`)
elif isinstance(contents, list) or (
"abi" in contents and isinstance(contents["abi"], list)
):
interfaces[file_path][interface_name] = {"type": "json", "code": contents}

@cyberthirst
Copy link
Collaborator

something is weird, because we theoretically used to have code to handle this, e.g.

# ABI JSON file (either `List[ABI]` or `{"abi": List[ABI]}`)
elif isinstance(contents, list) or (
"abi" in contents and isinstance(contents["abi"], list)
):
interfaces[file_path][interface_name] = {"type": "json", "code": contents}

i didn't look deeply into the code, but in this link we don't flatten the "abi" dict into the list (which is what we do in this fix)

@charles-cooper
Copy link
Member

something is weird, because we theoretically used to have code to handle this, e.g.

# ABI JSON file (either `List[ABI]` or `{"abi": List[ABI]}`)
elif isinstance(contents, list) or (
"abi" in contents and isinstance(contents["abi"], list)
):
interfaces[file_path][interface_name] = {"type": "json", "code": contents}

i didn't look deeply into the code, but in this link we don't flatten the "abi" dict into the list (which is what we do in this fix)

so why is this considered a regression 🤔 paging @fubuloubu

@fubuloubu
Copy link
Member

The regression might be that it didn't try and check anything was implemented because it was empty?

This fix seems good regardless

@charles-cooper charles-cooper changed the title fix[lang]: support top level "abi" key fix[lang]: support top level "abi" key in json interfaces Oct 11, 2024
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 46.08%. Comparing base (4845fd4) to head (8a8f35b).

Files with missing lines Patch % Lines
vyper/compiler/input_bundle.py 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (4845fd4) and HEAD (8a8f35b). Click for more details.

HEAD has 139 uploads less than BASE
Flag BASE (4845fd4) HEAD (8a8f35b)
140 1
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #4279       +/-   ##
===========================================
- Coverage   91.36%   46.08%   -45.29%     
===========================================
  Files         110      110               
  Lines       15810    15812        +2     
  Branches     2678     2679        +1     
===========================================
- Hits        14445     7287     -7158     
- Misses        931     7974     +7043     
- Partials      434      551      +117     

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

@charles-cooper charles-cooper changed the title fix[lang]: support top level "abi" key in json interfaces fix[lang]: support top level "abi" key in json interfaces Oct 11, 2024
@charles-cooper charles-cooper changed the title fix[lang]: support top level "abi" key in json interfaces feat[lang]: support top level "abi" key in json interfaces Oct 11, 2024
Copy link
Collaborator

@pcaversaccio pcaversaccio left a comment

Choose a reason for hiding this comment

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

For Solidity development frameworks, this can be quite common. For example, using Hardhat, you get this as an example.

@charles-cooper charles-cooper enabled auto-merge (squash) October 14, 2024 21:38
@charles-cooper charles-cooper merged commit 6bcdb00 into vyperlang:master Oct 14, 2024
155 checks passed
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.

5 participants