Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20230326 better print #31

Merged
merged 80 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
5664d13
Better printing. Use the simple method of matching (all ...) and ad…
prozacchiwawa Mar 27, 2023
0bbebb1
Better printing. Use the simple method of matching (all ...) and ad…
prozacchiwawa Mar 27, 2023
0ccc2ed
Better printing. Use the simple method of matching (all ...) and ad…
prozacchiwawa Mar 27, 2023
7759853
Ensure tools are built
prozacchiwawa Mar 27, 2023
4a5e01d
Try a different way of doing this on windows
prozacchiwawa Mar 27, 2023
1400a5a
try to fix syntax error in github workflow
prozacchiwawa Mar 27, 2023
66f1a69
it isn't python
prozacchiwawa Mar 27, 2023
06d32aa
Merge up
prozacchiwawa Apr 25, 2023
aa6fa5e
Merge remote-tracking branch 'chia/base' into 20230326-better-print
prozacchiwawa May 15, 2023
a5b6e3a
remove stray whitespace
aqk May 17, 2023
4814b39
Make debug print on opcode 34 a compile-time option
aqk May 19, 2023
6a24ed4
Experimenting with feature flags in workflows
prozacchiwawa May 19, 2023
3de61bd
Add env var setting
prozacchiwawa May 19, 2023
4cb4391
Show what we fished out
prozacchiwawa May 19, 2023
1a40e2a
Ensure tomlkit is installed
prozacchiwawa May 19, 2023
97b0d52
Try another way
prozacchiwawa May 19, 2023
12a6df0
Remove, this moved down to the next step
prozacchiwawa May 19, 2023
9095c10
Removed, moved down
prozacchiwawa May 19, 2023
d880b75
a bit of diagnostics
prozacchiwawa May 19, 2023
76e2dc8
test --no-default-features with --features
prozacchiwawa May 19, 2023
e75d13f
typo
prozacchiwawa May 19, 2023
443299d
Try a windows specific setup, try including --no-default-features wit…
prozacchiwawa May 19, 2023
4fc20c0
Fix typo
prozacchiwawa May 19, 2023
2e4d1df
right form of not
prozacchiwawa May 19, 2023
384d7ac
must be glued?
prozacchiwawa May 19, 2023
3ef4deb
braces?
prozacchiwawa May 19, 2023
c35fea8
making yaml upset, will have to dive in
prozacchiwawa May 19, 2023
e6f3a39
refine a bit
prozacchiwawa May 19, 2023
55e7fcd
Hmm ya we don't need to exclude extension-module here
prozacchiwawa May 19, 2023
8dec664
powershell
prozacchiwawa May 19, 2023
d33804c
Try a different capture tactic for powershell
prozacchiwawa May 19, 2023
9686d71
Remove unneeded
prozacchiwawa May 19, 2023
5511dcc
Support a simpler style if desired, use a direct append in windows
prozacchiwawa May 20, 2023
9e3b3b8
try bash on windows?
prozacchiwawa May 20, 2023
5f21194
try using GITHUB_ENV
prozacchiwawa May 20, 2023
68f7202
Print the result
prozacchiwawa May 20, 2023
b06c207
Try decorating with import environment variables
prozacchiwawa May 20, 2023
c671d37
Put this env on the wrong step
prozacchiwawa May 20, 2023
fdb8acb
Try switching to bash
prozacchiwawa May 20, 2023
2e0f8a8
Experiment with more switching to bash on windows
prozacchiwawa May 20, 2023
cba36a3
Link activate so our usual procedure for using the venv will work
prozacchiwawa May 20, 2023
17f110c
Symlinks imperfect in windows?
prozacchiwawa May 20, 2023
0db234a
On windows, these are in venv/Scripts
prozacchiwawa May 20, 2023
65938c3
Add final printing
prozacchiwawa May 20, 2023
7046cae
Merge remote-tracking branch 'chia/20230326-better-print' into 202303…
prozacchiwawa May 20, 2023
efa9011
Add final output we now ensure is generated
prozacchiwawa May 20, 2023
38da63e
Merge up
prozacchiwawa Aug 3, 2023
2621139
Ensure extension-module is added when we're calling maturin
prozacchiwawa Aug 3, 2023
a67abe3
Remove accidentally-added merge marks
prozacchiwawa Aug 14, 2023
dee6f63
Fix nonsense
prozacchiwawa Aug 14, 2023
e6a69bb
more detritus
prozacchiwawa Aug 14, 2023
13ab198
One more mistaken feature set
prozacchiwawa Aug 14, 2023
e954903
Merge up
prozacchiwawa Sep 13, 2023
5a49e39
Merge up
prozacchiwawa Sep 14, 2023
4cc32c9
Remove diff
prozacchiwawa Sep 14, 2023
46ce12e
Merge up
prozacchiwawa Sep 14, 2023
63f0fd5
Merge up
prozacchiwawa Sep 27, 2023
13cc4ec
Improve printing speed
prozacchiwawa Sep 29, 2023
8d3f09f
Merge pull request #44 from Chia-Network/20230928-print-improve-speed
prozacchiwawa Sep 29, 2023
a2ae3b8
Merge up
prozacchiwawa Nov 2, 2023
24d71be
Merge up
prozacchiwawa Nov 2, 2023
b75ac4e
Merge up
prozacchiwawa Nov 2, 2023
f77802d
ungate this feature
prozacchiwawa Nov 2, 2023
dc2823e
Back out feature infra, as we won't be using it here
prozacchiwawa Nov 2, 2023
7c06a7a
Merge remote-tracking branch 'chia/base' into 20230326-better-print
prozacchiwawa Nov 16, 2023
5133fe0
Run cargo build to ensure the binaries are available as newly built
prozacchiwawa Nov 16, 2023
337accb
Add new test run and python interface to print running
prozacchiwawa Nov 16, 2023
a016db5
fmt + clippy
prozacchiwawa Nov 16, 2023
c8427a7
Merge in new functionality in resources/tests/lib/steprun.py
prozacchiwawa Nov 16, 2023
0d7fb71
Import program from clvm_rs
prozacchiwawa Nov 17, 2023
4dbc477
Remove unused clvm_tools imports and remove hacky print substitute
prozacchiwawa Nov 17, 2023
2c859f1
Activate venv for new test
prozacchiwawa Nov 17, 2023
43aaeda
Add type hint support
prozacchiwawa Nov 17, 2023
0d3f5c4
Replace maturin develop with pip install due to support in pyproject
prozacchiwawa Nov 17, 2023
aae2cb6
Ensure clvm_rs is also installed
prozacchiwawa Nov 17, 2023
334f6ae
Set args path
prozacchiwawa Nov 17, 2023
5dcf74f
Same output as before on Final
prozacchiwawa Nov 17, 2023
16b3849
Same output as before on Final
prozacchiwawa Nov 17, 2023
0261e39
Ensure clvm_tools is installed since it has 'assemble'
prozacchiwawa Nov 17, 2023
1d1dff6
Remove no longer needed comment.
AmineKhaldi Nov 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ jobs:

- name: Build Windows with maturin on Python ${{ matrix.python }}
if: startsWith(matrix.os, 'windows')
shell: bash
run: |
python -m venv venv
echo ". .\venv\Scripts\Activate.ps1" > activate.ps1
cp venv/Scripts/activate .
. ./activate
maturin build -i python --release --strip
# Find and install the newly built wheel
Expand Down Expand Up @@ -140,14 +141,35 @@ jobs:
python -c 'import clvm_tools_rs; print(clvm_tools_rs.__file__)'
echo "CLVM_TOOLS_RS_VERSION=$(python -c 'import clvm_tools_rs; print(clvm_tools_rs.get_version())')" >> "$GITHUB_ENV"

# Test cldb output both run from python and via its command line tool.
- name: "Run step run tests"
shell: bash
run: |
. ./activate
cargo build
pip install .
pip install clvm_rs
pip install clvm_tools
cd resources/tests && \
python test_clvm_step.py && \
python mandelbrot-cldb.py

- name: "Test step run with mandelbrot, setting print only"
shell: bash
run: |
. ./activate
python ./resources/tests/lib/steprun.py ./resources/tests/mandelbrot/mandelbrot.clvm.hex resources/tests/mandelbrot/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


- name: Verify recompilation of old sources match with new compiler
if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8')
run: |
set -x
. ./activate
# Build cmd line tools
PYO3_PYTHON=`which python` cargo build --no-default-features --release
PYO3_PYTHON=`which python` cargo build --release

# Grab chia-blockchain
rm -rf chia-blockchain
Expand Down Expand Up @@ -210,7 +232,7 @@ jobs:

- name: Run tests
if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8')
run: cargo test --no-default-features
run: cargo test

- name: Exhaustive assign tests
if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.8')
Expand Down
8 changes: 4 additions & 4 deletions resources/tests/game-referee-in-cl21/test_library_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_smoke_compare():
compare_program.run(Program.to([]))

def test_handcalc():
diag_run_clvm(test_handcalc_program, Program.to([]), 'test_handcalc.sym')
diag_run_clvm(test_handcalc_program, Program.to([]), 'test_handcalc.sym', {'print': True})

def proper_list_inner(result,cl):
if hasattr(cl, 'pair') and cl.pair is not None:
Expand Down Expand Up @@ -137,20 +137,20 @@ def test_permutations_2():
all_b_string = 0x626262626262
for try_list in [[all_a_string,all_b_string], [all_b_string,all_a_string]]:
want_set = list([list(v) for v in sorted(permutations(try_list))])
listed_result = diag_run_clvm(smoke_test_permutations_program, Program.to([try_list]), 'smoke_test_permutations.sym')
listed_result = diag_run_clvm(smoke_test_permutations_program, Program.to([try_list]), 'smoke_test_permutations.sym', {'print': True})
pl = proper_list(listed_result)
perms_result = sorted([int_list(x) for x in de_none_list(pl)])
assert want_set == perms_result

def test_chialisp_sort_program():
diag_run_clvm(test_sort_program, Program.to([]), 'test_sort.sym')
diag_run_clvm(test_sort_program, Program.to([]), 'test_sort.sym', {'print': True})

def test_permutations_n():
for i in range(3,6):
do_test_permutations_of_size_n(i)

def test_chialisp_permutations_program():
diag_run_clvm(test_permutations_program, Program.to([3, 5]), 'test_permutations.sym')
diag_run_clvm(test_permutations_program, Program.to([3, 5]), 'test_permutations.sym', {'print': True})

def test_smoke_sort():
for length in range(7): # 0-7 length
Expand Down
54 changes: 26 additions & 28 deletions resources/tests/lib/steprun.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from typing import List
import binascii
import json
import os
from pathlib import Path
from typing import List

# from chia.types.blockchain_format.program import Program
from clvm_tools_rs import start_clvm_program, compose_run_function, compile_clvm
from clvm_tools.binutils import assemble
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


def compile_module_with_symbols(include_paths: List[Path], source: Path):
path_obj = Path(source)
Expand All @@ -36,34 +32,36 @@ 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


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)
if 'Failure' in report:
print(report['Failure'])
else:
return assemble(report["Final"])
return assemble(report['Final'])


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)
37 changes: 37 additions & 0 deletions resources/tests/mandelbrot-cldb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

import subprocess

command = ['../../target/debug/cldb', '-p', './mandelbrot/mandelbrot.clsp', '(-192 -128 -144 -96 8)']
want_output = """---
- Print: ((escape-at -152 -104) 14)
- Print: ((escape-at -160 -104) 14)
- Print: ((escape-at -168 -104) 14)
- Print: ((escape-at -176 -104) 11)
- Print: ((escape-at -184 -104) 8)
- Print: ((escape-at -192 -104) 7)
- Print: ((escape-at -152 -112) 14)
- Print: ((escape-at -160 -112) 14)
- Print: ((escape-at -168 -112) 14)
- Print: ((escape-at -176 -112) 14)
- Print: ((escape-at -184 -112) 8)
- Print: ((escape-at -192 -112) 7)
- Print: ((escape-at -152 -120) 14)
- Print: ((escape-at -160 -120) 14)
- Print: ((escape-at -168 -120) 14)
- Print: ((escape-at -176 -120) 13)
- Print: ((escape-at -184 -120) 8)
- Print: ((escape-at -192 -120) 6)
- Print: ((escape-at -152 -128) 12)
- Print: ((escape-at -160 -128) 10)
- Print: ((escape-at -168 -128) 10)
- Print: ((escape-at -176 -128) 7)
- Print: ((escape-at -184 -128) 6)
- Print: ((escape-at -192 -128) 5)
- Print: "(\\"result\\" \\"||567AAC|68DEEE|78EEEE|78BEEE\\")"
- Final: "3356114000950459963475899699747220812557867594760040767593731831711045"
Final-Location: "./mandelbrot/mandelbrot.clsp(8):43"
"""

have_output = subprocess.check_output(command).decode('utf8')
assert have_output == want_output
1 change: 1 addition & 0 deletions resources/tests/mandelbrot/mand_args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ff82ff40ff8180ff82ff70ff81a0ff0880
25 changes: 25 additions & 0 deletions resources/tests/mandelbrot/mand_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(("escape-at" -152 -104) 14)
(("escape-at" -160 -104) 14)
(("escape-at" -168 -104) 14)
(("escape-at" -176 -104) 11)
(("escape-at" -184 -104) 8)
(("escape-at" -192 -104) 7)
(("escape-at" -152 -112) 14)
(("escape-at" -160 -112) 14)
(("escape-at" -168 -112) 14)
(("escape-at" -176 -112) 14)
(("escape-at" -184 -112) 8)
(("escape-at" -192 -112) 7)
(("escape-at" -152 -120) 14)
(("escape-at" -160 -120) 14)
(("escape-at" -168 -120) 14)
(("escape-at" -176 -120) 13)
(("escape-at" -184 -120) 8)
(("escape-at" -192 -120) 6)
(("escape-at" -152 -128) 12)
(("escape-at" -160 -128) 10)
(("escape-at" -168 -128) 10)
(("escape-at" -176 -128) 7)
(("escape-at" -184 -128) 6)
(("escape-at" -192 -128) 5)
("result" "||567AAC|68DEEE|78EEEE|78BEEE")
55 changes: 55 additions & 0 deletions resources/tests/mandelbrot/mandelbrot.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
;; Mandelbrot set in chialisp
(mod (X1 Y1 X2 Y2 STEP)
(include *standard-cl-21*)
(defconstant LIMIT 0x0400)
(defconstant MAXITERS 15)
(defconstant CHARS "0123456789ABCDEF")

(defun print (M P) (if (all "$print$" M P) P P))

(defun to-char (V)
(c 1 (substr CHARS V (+ 1 V)))
)

(defun escape-steps (X Y WX WY V)
(if (> MAXITERS V)
(let
((xsqr (ash (* X X) -8))
(ysqr (ash (* Y Y) -8)))
(if (> (+ xsqr ysqr) LIMIT)
(- V 1)
(let
((next-x (+ (- xsqr ysqr) WX))
(next-y (+ (* 2 (ash (* X Y) -8)) WY)))
(escape-steps next-x next-y WX WY (+ 1 V))
)
)
)
(- V 1)
)
)


(defun basic-scanline (X1 Y1 X2 STEP)
(if (> X2 X1)
(let ((escape (print (list "escape-at" X1 Y1) (escape-steps 0 0 X1 Y1 0)))
(rest (basic-scanline (+ X1 STEP) Y1 X2 STEP)))
(c (to-char escape) rest)
)
()
)
)

(defun stringify-row (R)
(a (c 14 (c (c 1 "|") R)) ())
)

(defun scan (X1 Y1 X2 Y2 STEP)
(if (> Y2 Y1)
(c (c 1 (stringify-row (basic-scanline X1 Y1 X2 STEP))) (scan X1 (+ STEP Y1) X2 Y2 STEP))
()
)
)

(print "result" (stringify-row (scan X1 Y1 X2 Y2 STEP)))
)
1 change: 1 addition & 0 deletions resources/tests/mandelbrot/mandelbrot.clvm.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ff02ffff01ff02ff08ffff04ff02ffff04ffff0186726573756c74ffff04ffff02ff16ffff04ff02ffff04ffff02ff1effff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff2fffff04ff5fff8080808080808080ff80808080ff8080808080ffff04ffff01ffffff02ffff01ff02ffff03ffff22ffff0187247072696e7424ff05ff0b80ffff01ff02ffff010bff0180ffff01ff02ffff010bff018080ff0180ff0180ffff02ffff01ff04ffff0101ffff0cffff019030313233343536373839414243444546ff05ffff10ffff0101ff05808080ff0180ff02ffff01ff02ffff03ffff15ffff010fff5f80ffff01ff02ffff01ff02ffff03ffff15ffff10ffff16ffff12ff05ff0580ffff0181f880ffff16ffff12ff0bff0b80ffff0181f88080ffff0182040080ffff01ff02ffff01ff11ffff05ffff06ffff06ffff06ffff06ffff06ff01808080808080ffff010180ff0180ffff01ff02ffff01ff02ff1cffff04ff02ffff04ffff10ffff11ffff16ffff12ff05ff0580ffff0181f880ffff16ffff12ff0bff0b80ffff0181f88080ffff05ffff06ffff06ffff06ff018080808080ffff04ffff10ffff12ffff0102ffff16ffff12ffff05ffff06ff018080ffff05ffff06ffff06ff0180808080ffff0181f88080ffff05ffff06ffff06ffff06ffff06ff01808080808080ffff04ffff05ffff06ffff06ffff05ffff04ffff04ffff05ffff06ff018080ffff04ffff05ffff06ffff06ff01808080ffff04ffff05ffff06ffff06ffff06ff0180808080ffff04ffff05ffff06ffff06ffff06ffff06ff018080808080ffff04ffff05ffff06ffff06ffff06ffff06ffff06ff01808080808080ffff01808080808080ffff04ffff16ffff12ff05ff0580ffff0181f880ffff04ffff16ffff12ff0bff0b80ffff0181f880ffff018080808080808080ffff04ffff05ffff06ffff06ffff06ffff05ffff04ffff04ffff05ffff06ff018080ffff04ffff05ffff06ffff06ff01808080ffff04ffff05ffff06ffff06ffff06ff0180808080ffff04ffff05ffff06ffff06ffff06ffff06ff018080808080ffff04ffff05ffff06ffff06ffff06ffff06ffff06ff01808080808080ffff01808080808080ffff04ffff16ffff12ff05ff0580ffff0181f880ffff04ffff16ffff12ff0bff0b80ffff0181f880ffff01808080808080808080ffff04ffff10ffff0101ffff05ffff06ffff06ffff06ffff06ffff05ffff04ffff04ffff05ffff06ff018080ffff04ffff05ffff06ffff06ff01808080ffff04ffff05ffff06ffff06ffff06ff0180808080ffff04ffff05ffff06ffff06ffff06ffff06ff018080808080ffff04ffff05ffff06ffff06ffff06ffff06ffff06ff01808080808080ffff01808080808080ffff04ffff16ffff12ff05ff0580ffff0181f880ffff04ffff16ffff12ff0bff0b80ffff0181f880ffff018080808080808080808080ff8080808080808080ff018080ff0180ff0180ffff01ff02ffff01ff11ff5fffff010180ff018080ff0180ff0180ffff02ffff01ff02ffff03ffff15ff17ff0580ffff01ff02ffff01ff04ffff02ff14ffff04ff02ffff04ffff02ff08ffff04ff02ffff04ffff04ffff01896573636170652d6174ffff04ff05ffff04ff0bffff0180808080ffff04ffff02ff1cffff04ff02ffff04ffff0180ffff04ffff0180ffff04ff05ffff04ff0bffff04ffff0180ff8080808080808080ff8080808080ff80808080ffff02ff0affff04ff02ffff04ffff10ff05ff2f80ffff04ff0bffff04ff17ffff04ff2fff8080808080808080ff0180ffff01ff02ffff01ff0180ff018080ff0180ff0180ffff02ffff01ff02ffff04ffff010effff04ffff04ffff0101ffff017c80ff058080ffff018080ff0180ff02ffff01ff02ffff03ffff15ff2fff0b80ffff01ff02ffff01ff04ffff04ffff0101ffff02ff16ffff04ff02ffff04ffff02ff0affff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff5fff80808080808080ff8080808080ffff02ff1effff04ff02ffff04ff05ffff04ffff10ff5fff0b80ffff04ff17ffff04ff2fffff04ff5fff808080808080808080ff0180ffff01ff02ffff01ff0180ff018080ff0180ff0180ff018080
1 change: 1 addition & 0 deletions resources/tests/mandelbrot/mandelbrot.sym

Large diffs are not rendered by default.

59 changes: 57 additions & 2 deletions resources/tests/test_clvm_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
import json
from clvm_tools_rs import start_clvm_program, compose_run_function

def run_until_end(p):
def do_nothing(p):
pass

def run_until_end(p,printing=do_nothing,spam=True):
last = None
location = None

while not p.is_ended():
step_result = p.step()
if step_result is not None:
last = step_result
if 'Print' in last:
printing(last['Print'])
if 'Operator-Location' in last:
location = last['Operator-Location']
print(json.dumps(step_result))
if spam:
print(json.dumps(step_result))

return (last, location)

Expand Down Expand Up @@ -43,6 +49,54 @@ def fact_base_override(env):

assert int(last['Final']) == 11880

def test_with_printing():
mypath = Path(os.path.abspath(__file__))
testpath = mypath.parent.joinpath('mandelbrot')
symbols = json.loads(open(str(testpath.joinpath('mandelbrot.sym'))).read())

p = start_clvm_program(open(str(testpath.joinpath('mandelbrot.clvm.hex'))).read(), 'ff82ff40ff8180ff82ff70ff81a0ff0880', symbols, {})

print_outputs = []
def do_print(p):
print(p)
print_outputs.append(p)

last, location = run_until_end(p,printing=do_print,spam=False)

expected_outcome = "||567AAC|68DEEE|78EEEE|78BEEE"
want_prints = [
"((\"escape-at\" -152 -104) 14)",
"((\"escape-at\" -160 -104) 14)",
"((\"escape-at\" -168 -104) 14)",
"((\"escape-at\" -176 -104) 11)",
"((\"escape-at\" -184 -104) 8)",
"((\"escape-at\" -192 -104) 7)",
"((\"escape-at\" -152 -112) 14)",
"((\"escape-at\" -160 -112) 14)",
"((\"escape-at\" -168 -112) 14)",
"((\"escape-at\" -176 -112) 14)",
"((\"escape-at\" -184 -112) 8)",
"((\"escape-at\" -192 -112) 7)",
"((\"escape-at\" -152 -120) 14)",
"((\"escape-at\" -160 -120) 14)",
"((\"escape-at\" -168 -120) 14)",
"((\"escape-at\" -176 -120) 13)",
"((\"escape-at\" -184 -120) 8)",
"((\"escape-at\" -192 -120) 6)",
"((\"escape-at\" -152 -128) 12)",
"((\"escape-at\" -160 -128) 10)",
"((\"escape-at\" -168 -128) 10)",
"((\"escape-at\" -176 -128) 7)",
"((\"escape-at\" -184 -128) 6)",
"((\"escape-at\" -192 -128) 5)",
f"(\"result\" \"{expected_outcome}\")"
]

assert print_outputs == want_prints
to_hex = hex(int(last['Final']))
have_outcome = bytes.fromhex(to_hex[2:]).decode('utf8')
assert have_outcome == expected_outcome

def single_function_test():
mypath = Path(os.path.abspath(__file__))
testpath = mypath.parent.joinpath('steprun')
Expand All @@ -60,3 +114,4 @@ def single_function_test():
simple_test()
complex_test()
single_function_test()
test_with_printing()
Loading
Loading