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

50 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Original transport normalization and real merchant getter consistency."""
import json,sys
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
from forever_opcode_profile import normalize
names=('SMSG_SELL_RESPONSE','SMSG_BUY_SUCCEEDED','SMSG_BUY_FAILED','SMSG_TRAINER_LIST','SMSG_TRAINER_BUY_FAILED','SMSG_POWER_UPDATE','SMSG_ITEM_ENCHANT_TIME_UPDATE','SMSG_HEALTH_UPDATE','SMSG_DAILY_QUESTS_RESET','SMSG_ACCOUNT_ITEM_COLLECTION_DATA')
r=normalize(names,(0x3f0039,0x3f003b,0x3f003c,0x3f0045,0x3f0046));rows={x['name']:x for x in r['rows'] if x['name']}
# The upstream capture locates the new main-group message after PartyUpdate.
boundary_cases = {
"SMSG_BATTLE_PET_JOURNAL": "0x470092",
"SMSG_BATTLE_PET_DELETED": "0x470093",
"SMSG_BATTLE_PET_REVOKED": "0x470094",
"SMSG_BATTLE_PET_RESTORED": "0x470095",
"SMSG_BATTLE_PETS_HEALED": "0x470096",
"SMSG_PARTY_UPDATE": "0x470097",
"SMSG_UPDATE_RECENT_PLAYER_GUIDS": "0x470099",
"SMSG_READY_CHECK_STARTED": "0x47009a",
}
boundary = normalize(boundary_cases)
assert boundary["environment"]["main_insert_index"] == "0x98"
assert {row["name"]: row["translated_opcode"] for row in boundary["rows"]} == boundary_cases
actual=json.loads((ROOT/'docs/evidence/protocol/merchant-opcodes-70334.json').read_text())
for row in actual['routes']:
target=int.from_bytes(bytes.fromhex(row['getter_code'])[2:6],'little');key='SMSG_'+{'SellResponse':'SELL_RESPONSE','BuySucceeded':'BUY_SUCCEEDED','BuyFailed':'BUY_FAILED'}[row['name']]
assert int(rows[key]['translated_opcode'],16)==target and not rows[key]['blocked'] and rows[key]['stub_bytes'] is None
assert rows['SMSG_HEALTH_UPDATE']['blocked'] is True
assert rows['SMSG_DAILY_QUESTS_RESET']['stub_bytes']==0
assert rows['SMSG_ACCOUNT_ITEM_COLLECTION_DATA']['stub_bytes']==4
assert rows['SMSG_TRAINER_LIST']['translated_opcode']=='0x47018a'
assert rows['SMSG_TRAINER_BUY_FAILED']['translated_opcode']=='0x47018b'
assert rows['SMSG_POWER_UPDATE']['translated_opcode']=='0x47017e'
assert rows['SMSG_ITEM_ENCHANT_TIME_UPDATE']['translated_opcode']=='0x470200'
assert [x['translated_opcode'] for x in r['rows'] if not x['name']]==['0x3e0037','0x3e0039','0x3e003a','0x3e0043','0x3e0044']
for bad in (('NO_OPCODE',()),('SMSG_NONEXISTENT',()),('CMSG_BUY_ITEM',())):
try:normalize((bad[0],),bad[1])
except ValueError:pass
else:raise AssertionError('unreviewed name accepted')
for bad in (-1,0x1000000):
try:normalize(('SMSG_BUY_FAILED',),(bad,))
except ValueError:pass
else:raise AssertionError('client opcode overflow accepted')
defaults=normalize(client_opcodes=(0x440062,0x3e0176))
server=[row for row in defaults['rows'] if row['direction']=='server']
header='// Generated from pinned original ClassicOpcodes normalization for70334.\n#pragma once\nnamespace gateway::forever_opcodes {\n'+''.join(f"inline constexpr unsigned {row['name']}={row['translated_opcode']};\n" for row in server)+'}\n'
assert (ROOT/'include/gateway/forever_opcode_profile.hpp').read_text()==header
assert next(row for row in server if row['name']=='SMSG_SPELL_PERIODIC_AURA_LOG')['translated_opcode']=='0x690008'
assert [r['translated_opcode'] for r in defaults['rows'] if r['direction']=='client']==['0x430062','0x3d0174']
print('Verbatim source normalization matches real70334 merchant getters, verified power/enchant routes, blocked/stub policy and five client requests. Trainer routes are source-only; no gameplay claim.')