Skip to content

fix[cli]: relax validation of solc json inputs #4553

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions tests/unit/cli/vyper_json/test_get_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def test_interface_collision():
"sources": {"foo.vy": {"content": FOO_CODE}},
"interfaces": {"bar.json": {"abi": BAR_ABI}, "bar.vy": {"content": BAR_CODE}},
}
with pytest.raises(JSONError):
get_inputs(input_json)
# don't throw, bar.json and bar.vy have different paths
get_inputs(input_json)


def test_json_no_abi():
Expand Down
15 changes: 8 additions & 7 deletions vyper/cli/vyper_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Callable, Hashable, Optional

import vyper
from vyper.compiler.input_bundle import FileInput, JSONInputBundle
from vyper.compiler.input_bundle import FileInput, JSONInputBundle, _normpath
from vyper.compiler.settings import OptimizationLevel, Settings
from vyper.evm.opcodes import EVM_VERSIONS
from vyper.exceptions import JSONError
Expand Down Expand Up @@ -155,7 +155,8 @@ def get_inputs(input_dict: dict) -> dict[PurePath, Any]:
seen = {}

for path, value in input_dict["sources"].items():
path = PurePath(path)
path = PurePath(_normpath(path))

if "urls" in value:
raise JSONError(f"{path} - 'urls' is not a supported field, use 'content' instead")
if "content" not in value:
Expand All @@ -166,17 +167,17 @@ def get_inputs(input_dict: dict) -> dict[PurePath, Any]:
raise JSONError(
f"Calculated keccak of '{path}' does not match keccak given in input JSON"
)
if path.stem in seen:
if path in seen:
raise JSONError(f"Contract namespace collision: {path}")

# value looks like {"content": <source code>}
# this will be interpreted by JSONInputBundle later
ret[path] = value
seen[path.stem] = True
seen[path] = True

for path, value in input_dict.get("interfaces", {}).items():
path = PurePath(path)
if path.stem in seen:
path = PurePath(_normpath(path))
if path in seen:
raise JSONError(f"Interface namespace collision: {path}")

if isinstance(value, list):
Expand All @@ -203,7 +204,7 @@ def get_inputs(input_dict: dict) -> dict[PurePath, Any]:
)

ret[path] = value
seen[path.stem] = True
seen[path] = True

return ret

Expand Down
Loading