Skip to content

Commit

Permalink
Merge in new functionality in resources/tests/lib/steprun.py
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Nov 16, 2023
1 parent a016db5 commit c8427a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 37 additions & 29 deletions resources/tests/lib/steprun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit c8427a7

Please sign in to comment.