diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index 3856aa3362..5a87809203 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -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]