#!/usr/bin/env python3 """Regression tests for deterministic Bitflash Python tooling.""" import json import os import struct import subprocess import sys import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[2] SCRIPTS = ROOT / "scripts" FIXTURES = ROOT / "tests" / "fixtures" / "chain-tools" sys.path.insert(0, str(SCRIPTS)) import bitflash_chain as chain # noqa: E402 def run(args, **kwargs): env = dict(os.environ) env["PYTHONIOENCODING"] = "utf-8" return subprocess.run( [sys.executable] + [str(a) for a in args], cwd=str(ROOT), env=env, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs ) def write_block_file(path, blocks): with Path(path).open("wb") as f: f.write(b"noise") f.write(chain.MAGIC) f.write(struct.pack("