From f7ca1b91577ffd2bfe94ee3cda41131cd7aec7cf Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 17 Jan 2022 15:26:17 +0200 Subject: Cleanup test_vectors code --- nostr/bip340.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'nostr') diff --git a/nostr/bip340.py b/nostr/bip340.py index 7712500..f9758d9 100644 --- a/nostr/bip340.py +++ b/nostr/bip340.py @@ -168,3 +168,37 @@ def schnorr_verify(msg: bytes, pubkey: bytes, sig: bytes) -> bool: return False debug_print_vars() return True + + +# +# The following code is only used for debugging +# +import inspect + + +def pretty(v: Any) -> Any: + if isinstance(v, bytes): + return "0x" + v.hex() + if isinstance(v, int): + return pretty(bytes_from_int(v)) + if isinstance(v, tuple): + return tuple(map(pretty, v)) + return v + + +def debug_print_vars() -> None: + if DEBUG: + current_frame = inspect.currentframe() + assert current_frame is not None + frame = current_frame.f_back + assert frame is not None + print( + " Variables in function ", + frame.f_code.co_name, + " at line ", + frame.f_lineno, + ":", + sep="", + ) + for var_name, var_val in frame.f_locals.items(): + print(" " + var_name.rjust(11, " "), "==", pretty(var_val)) -- cgit v1.3.1