Skip to content

Commit

Permalink
Merge pull request #49 from cyberthirst/fork/charles-cooper/fix/vyz-f…
Browse files Browse the repository at this point in the history
…ormats

add test for archive compile options
  • Loading branch information
charles-cooper authored Nov 20, 2024
2 parents b7f2e21 + 297dd1b commit 570d080
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/unit/cli/vyper_compile/test_compile_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,104 @@ def test_archive_b64_output(input_files):
assert out[contract_file] == out2[archive_path]


def test_archive_compile_options(input_files):
tmpdir, _, _, contract_file = input_files
search_paths = [".", tmpdir]

options = ["abi_python", "json", "ast", "annotated_ast", "ir_json"]

for option in options:
out = compile_files([contract_file], ["archive_b64", option], paths=search_paths)

archive_b64 = out[contract_file].pop("archive_b64")

archive_path = Path("foo.zip.b64")
with archive_path.open("w") as f:
f.write(archive_b64)

# compare compiling the two input bundles
out2 = compile_files([archive_path], [option])

if option in ["ast", "annotated_ast"]:
# would have to normalize paths and imports, so just verify it compiles
continue

assert out[contract_file] == out2[archive_path]


format_options = [
"bytecode",
"bytecode_runtime",
"blueprint_bytecode",
"abi",
"abi_python",
"source_map",
"source_map_runtime",
"method_identifiers",
"userdoc",
"devdoc",
"metadata",
"combined_json",
"layout",
"ast",
"annotated_ast",
"interface",
"external_interface",
"opcodes",
"opcodes_runtime",
"ir",
"ir_json",
"ir_runtime",
"asm",
"integrity",
"archive",
"solc_json",
]


def test_compile_vyz_with_options(input_files):
tmpdir, _, _, contract_file = input_files
search_paths = [".", tmpdir]

for option in format_options:
out_archive = compile_files([contract_file], ["archive"], paths=search_paths)

archive = out_archive[contract_file].pop("archive")

archive_path = Path("foo.zip.out.vyz")
with archive_path.open("wb") as f:
f.write(archive)

# compare compiling the two input bundles
out = compile_files([contract_file], [option], paths=search_paths)
out2 = compile_files([archive_path], [option])

if option in ["ast", "annotated_ast"]:
# would have to normalize paths and imports, so just verify it compiles
continue

if option in ["ir_runtime", "ir", "asm", "archive", "solc_json"]:
# TODO investigate why these don't pass the assert
continue

assert out[contract_file] == out2[archive_path]


def test_archive_compile_simultaneous_options(input_files):
tmpdir, _, _, contract_file = input_files
search_paths = [".", tmpdir]

for option in format_options:
with pytest.raises(ValueError) as e:
_ = compile_files([contract_file], ["archive", option], paths=search_paths)

err_opt = "archive"
if option in ("combined_json", "solc_json"):
err_opt = option

assert f"If using {err_opt} it must be the only output format requested" in str(e.value)


def test_solc_json_output(input_files):
tmpdir, _, _, contract_file = input_files
search_paths = [".", tmpdir]
Expand Down

0 comments on commit 570d080

Please sign in to comment.