98 lines
4.0 KiB
Python
98 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Prove the source Meditation rows reach both build 70334 hotfix reply paths."""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import struct
|
|
import sys
|
|
from collections import Counter
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path[:0] = [str(ROOT / 'ops'), str(ROOT / 'tests')]
|
|
from build_source_meditation_compat import INPUT, OUTPUT, SPELL_EFFECT_ID_REMAP, build
|
|
from native_codec_driver import MODES, load, serialize
|
|
|
|
|
|
def run(codec):
|
|
os.environ['GW_TEST_CODEC_PATH'] = str(codec)
|
|
component = json.loads(INPUT.read_text())
|
|
push, header, rows = build()
|
|
assert OUTPUT.read_text() == header
|
|
assert len(rows) == 22
|
|
assert Counter(r['table_name'] for r in component['rows']) == Counter({
|
|
'SpellName': 3, 'Spell': 3, 'SpellMisc': 3, 'SpellEffect': 4,
|
|
'SpellCooldowns': 3, 'SpellCategories': 3, 'SpellXSpellVisual': 3,
|
|
})
|
|
expected = {}
|
|
for row in component['rows']:
|
|
wire = bytes.fromhex(row['wire_hex'])
|
|
assert hashlib.sha256(wire).hexdigest() == row['sha256']
|
|
identity = (int(row['table_hash'], 16), SPELL_EFFECT_ID_REMAP.get(row['id'], row['id']))
|
|
assert identity not in expected
|
|
expected[identity] = wire
|
|
assert len(expected) == 22
|
|
|
|
library = load()
|
|
available = serialize(library, MODES.index('--native-client-initialization'),
|
|
struct.pack('<IIQ', 0x01000031, 0, 0))
|
|
count = struct.unpack_from('<I', available)[0]
|
|
offset = 4
|
|
available_body = None
|
|
for _ in range(count):
|
|
opcode, size = struct.unpack_from('<II', available, offset)
|
|
offset += 8
|
|
body = available[offset:offset + size]
|
|
offset += size
|
|
if opcode == 0x4B0001:
|
|
available_body = body
|
|
assert offset == len(available) and available_body is not None
|
|
realm, push_count = struct.unpack_from('<II', available_body)
|
|
assert realm == 0x01000031 and len(available_body) == 8 + 8 * push_count
|
|
advertised = {struct.unpack_from('<II', available_body, 8 + 8 * i)[0]
|
|
for i in range(push_count)}
|
|
assert push in advertised
|
|
|
|
reply = serialize(library, MODES.index('--native-hotfix-reply'),
|
|
struct.pack('<4I', 70334, 0, 1, push))
|
|
row_count = struct.unpack_from('<I', reply)[0]
|
|
assert row_count == len(expected)
|
|
offset = 4
|
|
metadata = []
|
|
for index in range(1, row_count + 1):
|
|
push_id, unique, table, ident, size, status = struct.unpack_from('<IIIIIB', reply, offset)
|
|
offset += 21
|
|
assert push_id == push and unique == index and status == 0x20
|
|
assert (table, ident) in expected and size == len(expected[(table, ident)])
|
|
metadata.append((table, ident, size))
|
|
body_size = struct.unpack_from('<I', reply, offset)[0]
|
|
offset += 4
|
|
body = reply[offset:]
|
|
assert len(body) == body_size == sum(size for _, _, size in metadata)
|
|
offset = 0
|
|
seen = set()
|
|
for table, ident, size in metadata:
|
|
wire = body[offset:offset + size]
|
|
offset += size
|
|
assert wire == expected[(table, ident)] and (table, ident) not in seen
|
|
seen.add((table, ident))
|
|
assert offset == len(body) and seen == set(expected)
|
|
|
|
for (table, ident), raw in expected.items():
|
|
db_reply = serialize(library, MODES.index('--native-db-reply-missing'),
|
|
struct.pack('<III', table, ident, 12345))
|
|
assert struct.unpack_from('<III', db_reply) == (table, ident, 12345)
|
|
assert db_reply[12] == 0x20
|
|
assert struct.unpack_from('<I', db_reply, 13)[0] == len(raw)
|
|
assert db_reply[17:] == raw
|
|
|
|
assert {ident for table, ident in expected if table == 0xf04238a5} == {1500770, 1500771, 1500772, 1500773}
|
|
print('PASS: 22 Meditation rows advertised, bulk-served, and returned byte-exact by DBReply; '
|
|
'four SpellEffect keys use collision-free IDs.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) != 2:
|
|
raise SystemExit('usage: source_meditation_hotfix_fixture.py CODEC_LIBRARY')
|
|
run(Path(sys.argv[1]))
|