Files
WoW-Hybrid-gateway/tests/charge_provider_replies_test.py

60 lines
2.5 KiB
Python

"""Reproduce the shipped headers and optionally compare the original and charge-only host replies."""
import argparse
from hashlib import file_digest
import json
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "ops/octo_parity"))
import compose_charge_provider as producer
from spell_aura_restrictions_hotfix_fixture import codec_at, db_query, initialization, request
CHILD_CODEC = "54bad72970d5e7822928cbc59283157565a19d9414527b522d6afc55ab82bd40"
def check_hosts(paths, fixture, direct, pages):
expected = [fixture["baseline_host_sha256"], CHILD_CODEC]
for path, pin in zip(paths, expected, strict=True):
with path.open("rb") as stream:
assert file_digest(stream, "sha256").hexdigest() == pin
old, child = map(codec_at, paths)
missing = 0
for key, (spell, slot) in fixture["charge_rows"].items():
rid = int(key)
before, after = [db_query(c, producer.TABLE, rid) for c in (old, child)]
if rid not in direct:
assert before == after and len(after) == 17 and after[12] == 0x60
missing += 1
continue
assert before[:17] == after[:17] and after[12] == 0x20
offset = producer.update_record(before[17:], fixture["schema"], rid, spell, slot)
desired = bytearray(before)
desired[17 + offset] = 64
assert after == desired
assert missing == 141
for old_id, (new_id, before, after) in pages.items():
assert request(old, [old_id]) == before
assert request(child, [new_id]) == after
assert initialization(old) == initialization(child)
_, advertised = initialization(child)
assert advertised == [(1294782901, 1)] and request(old, [1294782901]) == request(child, [1294782901])
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--codecs", type=Path, nargs=2, metavar=("PRE_CHARGE", "CHARGE_ONLY"))
parser.add_argument("--source-plan", type=Path)
args = parser.parse_args()
fixture = json.loads(producer.FIXTURE.read_bytes())
if args.source_plan:
producer.check_source(fixture, args.source_plan.read_bytes())
_, direct, pages = producer.compose(producer.preimages(), fixture)
if args.codecs:
check_hosts(args.codecs, fixture, direct, pages)
print(f"PASS shipped header SHA-256, {len(direct)} direct rows, 141 physical fallbacks, {len(pages)} pages"
+ ("; both compiled codecs' ordinary replies verified" if args.codecs else ""))
if __name__ == "__main__":
main()