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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading