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

36 lines
1.6 KiB
Python

"""Pinned native chest-loot writer parity; synthetic offline input only."""
import struct
import subprocess
import sys
from native_codec_driver import require_optional_cli
P = struct.pack
codec = sys.argv[1]
require_optional_cli(codec)
source = 0xF1100006C36AE04A
owner = P('<QQ', source & 0xffffff, (11 << 58) | (70 << 42) | (1731 << 6))
creature = P('<QQ', 42, (8 << 58) | (70 << 42) | (6 << 6))
obj = P('<QQ', 9, (15 << 58) | (70 << 42))
def packed(raw):
return P('<H', sum((b != 0) << i for i, b in enumerate(raw))) + bytes(b for b in raw if b)
def run(body):
return subprocess.run([codec, '--loot-event'], input=body, capture_output=True, timeout=15)
rows = [(0, 25, 2, 100, 0), (2, 26, 1, 200, 1)]
def event(typ=2):
return P('<QBIB', source, typ, 0, len(rows)) + b''.join(P('<BIIIIiB', slot, entry, count, display, 0, 0, ui) for slot, entry, count, display, ui in rows)
def context(data, world=owner):
return bytes([10]) + P('<Q', source) + world + obj + bytes([0, 2]) + data
expected = packed(owner) + packed(obj) + bytes([17, 9, 0, 2]) + P('<III', 0, len(rows), 0)
for slot, entry, count, display, ui in rows:
expected += bytes([ui << 3]) + P('<IBBI', count, 0, slot, entry) + bytes(2)
expected += bytes([0x80])
payload = context(event())
result = run(payload)
assert result.returncode == 0 and result.stdout == expected, (result.stderr, result.stdout.hex(), expected.hex())
for bad in (context(event(), creature), context(event(1)), payload[:-1], payload+b'\0'):
assert run(bad).returncode != 0
print('PASS original native chest LootResponse writer, actual Source type2 mapping and context rejection')