diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 7fe232b7b..0063f4bf1 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -156,7 +156,7 @@ jobs: - name: "Test step run with mandelbrot, setting print only" shell: bash run: | - python ./resources/tests/steprun.py ./resources/tests/mandelbrot/mandelbrot.clvm.hex mand_args.txt ./resources/tests/mandelbrot/mandelbrot.sym > /tmp/mand_output.txt + python ./resources/tests/lib/steprun.py ./resources/tests/mandelbrot/mandelbrot.clvm.hex mand_args.txt ./resources/tests/mandelbrot/mandelbrot.sym > /tmp/mand_output.txt # Fail if the output differs. diff -s -q /tmp/mand_output.txt ./resources/tests/mandelbrot/mand_test.txt diff --git a/resources/tests/lib/steprun.py b/resources/tests/lib/steprun.py index 02db51339..52f4d3452 100644 --- a/resources/tests/lib/steprun.py +++ b/resources/tests/lib/steprun.py @@ -2,14 +2,9 @@ import json import os from pathlib import Path -from typing import List - -# from chia.types.blockchain_format.program import Program -from clvm_rs import Program from clvm_tools.binutils import assemble, disassemble - -from clvm_tools_rs import compile_clvm, compose_run_function, start_clvm_program - +from clvm_tools_rs import start_clvm_program, compose_run_function, compile_clvm +from chia.types.blockchain_format.program import Program def compile_module_with_symbols(include_paths: List[Path], source: Path): path_obj = Path(source) @@ -36,34 +31,47 @@ def run_until_end(p): step_result = p.step() if step_result is not None: last = step_result - if "Print" in last: - to_print = last["Print"] - if "Print-Location" in last: - print(f"{last['Print-Location']}: print {to_print}") - else: - print(f"print {to_print}") + if 'Print' in last: + print(f"{last['Print']}") - return last + if 'Result-Location' in last and \ + 'Arguments' in last and \ + 'print' in last['Result-Location'] and \ + 'Value' in last: + value_assembled = assemble(last['Value']) + assembled_arg_list = [] + while value_assembled.pair is not None: + assembled_arg_list.append(value_assembled.pair[0]) + value_assembled = value_assembled.pair[1] + if len(assembled_arg_list) > 2: + to_show = disassemble(Program.to(assembled_arg_list[-2:])) + print(f"print {last['Operator']} {to_show}") + return last -def diag_run_clvm(program, args, symbols): - hex_form_of_program = binascii.hexlify(bytes(program)).decode("utf8") - hex_form_of_args = binascii.hexlify(bytes(args)).decode("utf8") +def diag_run_clvm(program, args, symbols, options): + hex_form_of_program = binascii.hexlify(bytes(program)).decode('utf8') + hex_form_of_args = binascii.hexlify(bytes(args)).decode('utf8') symbols = json.loads(open(symbols).read()) - p = start_clvm_program( - hex_form_of_program, hex_form_of_args, symbols, None - ) + p = start_clvm_program(hex_form_of_program, hex_form_of_args, symbols, None, options) report = run_until_end(p) - if "Failure" in report: - raise Exception(report) - else: - return assemble(report["Final"]) + if 'Failure' in report: + print(report['Failure']) - -if __name__ == "__main__": +if __name__ == '__main__': # smoke test import sys + import argparse + import traceback + + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--print', action='store_true', default=True) + parser.add_argument('program') + parser.add_argument('env') + parser.add_argument('symbols') + args = parser.parse_args() - program = Program.fromhex(open(sys.argv[1]).read()) - args = Program.fromhex(open(sys.argv[2]).read()) - diag_run_clvm(program, args) + program = Program.fromhex(open(args.program).read()) + env = Program.fromhex(open(args.env).read()) + options = { 'print': args.print } + diag_run_clvm(program, env, args.symbols, options)