Rewrite simulator_api to use ws, hex, and client script by mcelrath · Pull Request #145 · braidpool/braidpool · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions tests/requirements.txt
11 changes: 7 additions & 4 deletions tests/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import random
import hashlib
import re
import string
import struct
import sys
import time
Expand Down Expand Up @@ -92,16 +93,18 @@ def print_hash(h):
Prints a string to the console with the color specified by the hash for easy visual
identification.
"""
if type(h) == int:
hex_string = f"{h:064x}"
color = re.search(r'0*.([^0].{5})', hex_string).group(1)
if type(h) == str and len(h) == 64 and all(c in string.hexdigits for c in h):
color = re.search(r'0*.([^0].{5})', h).group(1)
# Convert hex to RGB
r, g, b = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
# ANSI escape code for setting color
color_code = f"\033[38;2;{r};{g};{b}m"
reset_code = "\033[0m" # Reset to default color
# Print with color
return f"{color_code}{h>>(256-32):08x}{reset_code}"
return f"{color_code}{h[0:8]}{reset_code}"
elif type(h) == int:
hex_string = f"{h:064x}"
return print_hash(hex_string)
elif isinstance(h, dict):
retval = "{"
for k,v in h.items():
Expand Down
212 changes: 115 additions & 97 deletions tests/simulator_api.py
65 changes: 0 additions & 65 deletions tests/simulator_api_tests.py

This file was deleted.

Loading