test_6400_hex_gui_v2.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from importlib.util import module_from_spec, spec_from_file_location
  2. from pathlib import Path
  3. ROOT = Path(__file__).resolve().parents[2]
  4. SPEC = spec_from_file_location("hex_gui", ROOT / "tools/6400_hex_gui.py")
  5. assert SPEC and SPEC.loader
  6. GUI = module_from_spec(SPEC)
  7. SPEC.loader.exec_module(GUI)
  8. def test_gui_uses_generated_contract_and_golden_vectors() -> None:
  9. assert GUI.CONTRACT["contract_sha256"] == GUI.GOLDEN["contract_sha256"]
  10. safe_frame = GUI.set_all([0] * 24 + [20] * 8)
  11. assert GUI.frame_hex(safe_frame).replace(" ", "").startswith("A55A0120")
  12. get_frame = GUI.encode(2)
  13. assert GUI.frame_hex(get_frame).replace(" ", "") == "A55A02006D7B"
  14. def test_gui_parses_unified_ack_and_rejects_bad_crc() -> None:
  15. ack = bytes.fromhex("A55A8100A635")
  16. assert "SET_ACK" in GUI.describe(ack)
  17. damaged = ack[:-1] + bytes((ack[-1] ^ 1,))
  18. try:
  19. GUI.decode(damaged)
  20. except ValueError as exc:
  21. assert "CRC mismatch" in str(exc)
  22. else:
  23. raise AssertionError("bad CRC accepted")
  24. def test_gui_has_no_serial_access_path() -> None:
  25. source = (ROOT / "tools/6400_hex_gui.py").read_text(encoding="utf-8")
  26. assert "import serial" not in source
  27. assert "Serial(" not in source
  28. assert "pyserial" not in source.lower()