"""Offline consistency check. Does not rerun Core or execute exchange orders.
Save alongside address-checks.py.txt, order-model.py.txt and both JSON exports.
Run: python verify-package.py /path/to/package-directory
"""
from pathlib import Path
import importlib.machinery,importlib.util,json,sys
def load(path,name):
    loader=importlib.machinery.SourceFileLoader(name,str(path));spec=importlib.util.spec_from_loader(name,loader);module=importlib.util.module_from_spec(spec);loader.exec_module(module);return module
def main():
    p=Path(sys.argv[1]).resolve();address=load(p/'address-checks.py.txt','lw_address');model=load(p/'order-model.py.txt','lw_order')
    saved=json.loads((p/'address-results.json').read_text());fixtures={x['id']:x for x in address.fixtures()}
    assert saved['fixture_count']==18 and saved['rpc_checks']==36 and len(saved['results'])==36
    assert all(n['height']==0 and n['peers']==0 and n['wallet_disabled'] for n in saved['nodes'].values())
    payload=address.hashlib.sha256(b'Litecoin.watch synthetic address fixture A 2026-10-03').digest()[:20].hex()
    for row in saved['results']:
        f=fixtures[row['id']];assert row['address']==f['address'] and row['observed']['isvalid']==f['expected_'+row['network_mode']]
        if row['id'] in ['ltc_script_M','shared_script_3'] and row['network_mode']=='main':assert row['observed']['scriptPubKey']=='a914'+payload+'87'
    assert len(saved['assertions'])==46 and all(x['passed'] for x in saved['assertions'])
    calculated=model.model();assert calculated==json.loads((p/'order-results.json').read_text())
    print(json.dumps({'address_fixtures_consistent':18,'recorded_rpc_results_checked':36,'synthetic_order_scenarios_recalculated':12,'queue_events':2,
                      'recorded_address_assertions':46,'model_assertions':78,'fresh_Core_validation':False,'actual_orders_executed':False}))
if __name__=='__main__':main()
