Skip to content

Commit

Permalink
feat[lang]: support top level "abi" key in json interfaces (#4279)
Browse files Browse the repository at this point in the history
some frameworks produce json ABI files with `"abi"` as a top-level
key. this decreases a bit of friction for using those ABI files.
  • Loading branch information
sandbubbles authored Oct 14, 2024
1 parent 33b9f83 commit 6bcdb00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/unit/cli/vyper_json/test_compile_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,27 @@ def test_relative_import_paths(input_json):
input_json["sources"]["contracts/potato/baz/potato.vy"] = {"content": "from . import baz"}
input_json["sources"]["contracts/potato/footato.vy"] = {"content": "from baz import baz"}
compile_from_input_dict(input_json)


def test_compile_json_with_abi_top(make_input_bundle):
stream = """
{
"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" }]
}
]
}
"""
code = """
from . import stream
"""
input_bundle = make_input_bundle({"stream.json": stream, "code.vy": code})
vyper.compiler.compile_code(code, input_bundle=input_bundle)
2 changes: 2 additions & 0 deletions vyper/compiler/input_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class ABIInput(CompilerInput):
def try_parse_abi(file_input: FileInput) -> CompilerInput:
try:
s = json.loads(file_input.source_code)
if isinstance(s, dict) and "abi" in s:
s = s["abi"]
return ABIInput(**asdict(file_input), abi=s)
except (ValueError, TypeError):
return file_input
Expand Down

0 comments on commit 6bcdb00

Please sign in to comment.