From eeb8053b50558fe7a7371cbbb0c0d2a7e6bd65c0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 9 Jul 2024 17:40:28 +0200 Subject: [PATCH] print EvalError in a slightly more user friendly way --- wheel/python/clvm_rs/eval_error.py | 5 +++++ wheel/python/tests/test_program.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/wheel/python/clvm_rs/eval_error.py b/wheel/python/clvm_rs/eval_error.py index 5174e324..23d3d703 100644 --- a/wheel/python/clvm_rs/eval_error.py +++ b/wheel/python/clvm_rs/eval_error.py @@ -1,4 +1,9 @@ +from .ser import sexp_to_bytes + class EvalError(ValueError): def __init__(self, message: str, sexp): super().__init__(message) self._sexp = sexp + + def __str__(self) -> str: + return f"({self.args[0]}, {sexp_to_bytes(self._sexp).hex()})" diff --git a/wheel/python/tests/test_program.py b/wheel/python/tests/test_program.py index 52510a86..32f43448 100644 --- a/wheel/python/tests/test_program.py +++ b/wheel/python/tests/test_program.py @@ -493,3 +493,15 @@ def test_tree_hash_no_caching(self): self.assertEqual(p3p._cached_sha256_treehash.hex(), eh3) self.assertEqual(p._cached_sha256_treehash.hex(), eh) self.assertEqual(p2._cached_sha256_treehash.hex(), eh2) + +def test_repr() -> None: + temp = Program.to([8, (1, "foo")]) + assert f"{temp}" == "ff08ffff0183666f6f80" + + Program.set_run_unsafe_max_cost(11000000000) + + try: + temp.run([]) + assert False + except EvalError as e: + assert f"{e}" == "(clvm raise, 83666f6f)"