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