|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import json |
| 4 | +import subprocess |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import jsonschema |
| 8 | +import pytest |
| 9 | + |
| 10 | + |
| 11 | +def get_nested_value(dictionary, *keys): |
| 12 | + for key in keys: |
| 13 | + dictionary = dictionary[key] |
| 14 | + return dictionary |
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture(params=["input_file.json", "input_file_eof.json"]) |
| 18 | +def solc_output(request, solc_path): |
| 19 | + testfile_dir = Path(__file__).parent |
| 20 | + with open(testfile_dir / request.param, "r", encoding="utf8") as f: |
| 21 | + source = json.load(f) |
| 22 | + |
| 23 | + process = subprocess.run( |
| 24 | + [solc_path, "--standard-json"], |
| 25 | + input=json.dumps(source), |
| 26 | + encoding='utf8', |
| 27 | + capture_output=True, |
| 28 | + check=True, |
| 29 | + ) |
| 30 | + assert process.returncode == 0 |
| 31 | + return json.loads(process.stdout) |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.parametrize("output_selection", ["evm.bytecode.ethdebug", "evm.deployedBytecode.ethdebug"], ids=str) |
| 35 | +def test_program_schema( |
| 36 | + output_selection, |
| 37 | + ethdebug_schema_repository, |
| 38 | + solc_output |
| 39 | +): |
| 40 | + validator = jsonschema.Draft202012Validator( |
| 41 | + schema={"$ref": "schema:ethdebug/format/program"}, |
| 42 | + registry=ethdebug_schema_repository |
| 43 | + ) |
| 44 | + assert "contracts" in solc_output |
| 45 | + for contract in solc_output["contracts"].keys(): |
| 46 | + contract_output = solc_output["contracts"][contract] |
| 47 | + assert len(contract_output) > 0 |
| 48 | + for source in contract_output.keys(): |
| 49 | + source_output = contract_output[source] |
| 50 | + ethdebug_data = get_nested_value(source_output, *(output_selection.split("."))) |
| 51 | + validator.validate(ethdebug_data) |
0 commit comments