Files
WoW-Hybrid-gateway/tests/chrraces_hotfix_language_test.py
2026-11-23 03:28:32 +02:00

63 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""The compiled ChrRaces hotfix agrees with the selected corrected native DB2."""
import hashlib
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "ops"))
from chrraces_hotfix_language import ( # noqa: E402
BASE_LANGUAGE_TRAILING_FIELDS, DEFAULT_HEADER, ROWS, TABLE,
correct_header, inspect_header,
)
ORIGINAL_WIRE_SHA256 = {
9: "4cd17faaa1b18aa91617281a9dd0497994c97c438bbcf4ba7d39123e17e6ebbb",
10: "fef963386a593b1ee551f3a87b8f779a39d7ee03bd72900c3ff67eda2eae1c63",
}
CORRECTED_WIRE_SHA256 = {
9: "f63c8071e4da8204bb68ea5d47071e8eaf8080cea45001e3bf2c01762652b32d",
10: "17563eea2de69e3d27a4e0720bd3faf72b8bcd664acd4dcfb8cf20cff4ac544b",
}
ORIGINAL_HEADER_SHA256 = "a55d81e76413e6665a51ca60f6d26cf6f8b0c5ab1295d281d2b96570c31735a6"
def test_compiled_rows_and_pushes():
raw = DEFAULT_HEADER.read_bytes()
_, blob, records, root_push, page_push = inspect_header(raw)
assert (root_push, page_push) == (141152276, 789481432)
for race, (offset, length, before, after) in ROWS.items():
assert sum(row[0] == TABLE and row[1] == race for row in records) == 1
wire = bytearray(blob[offset:offset + length])
assert wire[-BASE_LANGUAGE_TRAILING_FIELDS] == after
assert hashlib.sha256(wire).hexdigest() == CORRECTED_WIRE_SHA256[race]
wire[-BASE_LANGUAGE_TRAILING_FIELDS] = before
assert hashlib.sha256(wire).hexdigest() == ORIGINAL_WIRE_SHA256[race]
unchanged, result = correct_header(raw)
assert unchanged == raw and result["changed"] == []
# Reconstruct the exact pre-change header to prove that no other compiled
# registry bytes, record IDs, page entries, or other accepted work changed.
restored = bytearray(raw)
marker = b"inline constexpr uint8_t PayloadBlob[]=\n"
payload_at = raw.index(marker) + len(marker)
for _race, (offset, length, before, after) in ROWS.items():
field_offset = offset + length - BASE_LANGUAGE_TRAILING_FIELDS
literal_at = payload_at + (field_offset // 64) * 259 + 1 + (field_offset % 64) * 4
assert restored[literal_at:literal_at + 4] == f"\\{after:03o}".encode()
restored[literal_at:literal_at + 4] = f"\\{before:03o}".encode()
restored = bytes(restored)
for after, before in (
(b"inline constexpr int32_t PushID=141152276;",
b"inline constexpr int32_t PushID=92790178;"),
(b"{789481432,81920,4096}", b"{671895931,81920,4096}"),
):
assert restored.count(after) == 1
restored = restored.replace(after, before, 1)
assert hashlib.sha256(restored).hexdigest() == ORIGINAL_HEADER_SHA256
print("ChrRaces hotfix rows 9/10 and full push identities: PASS")
if __name__ == "__main__":
test_compiled_rows_and_pushes()