"""Authenticated T726 generator verification and stored-interval checks. No writes."""
import os,sys,json,hashlib
from pathlib import Path
from decimal import Decimal
import numberdb.sage as numberdb
from generate import HardyZLehmerCondition,PAIR_INDICES,pair_value
from checks import inside,_decimal_rational
from numberdb._generate import _stored_entries
if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1': os.environ['NUMBERDB_API_KEY']=sys.stdin.read().strip()
g=HardyZLehmerCondition(); report=g.verify(sample=None)
assert report.ok
stored=_stored_entries(numberdb.table('T726'))
assert list(stored)==[str(n) for n in PAIR_INDICES]
evidence=json.loads(Path(__file__).with_name('numerical-evidence.json').read_text())
rows={str(r['n']):r for r in evidence['rows']}
for n,text in stored.items():
 assert text==rows[n]['number']
 assert inside(pair_value(int(n),100),text)
 for dps in [130,165]: assert inside(_decimal_rational(rows[n][f'mpmath_{dps}dps']),text)
for c in evidence['contour_checks']: assert inside(_decimal_rational(c['value']),stored[str(c['n'])])
print('READBACK_JSON '+json.dumps({'table':'T726','checked_entries':len(stored),'generator_verify_all':True,'stored_intervals_rechecked_against_mpmath_and_contours':True,'selection_matches_default_enumeration':True,'source_sha256':{name:hashlib.sha256(Path(__file__).with_name(name).read_bytes()).hexdigest() for name in ['generate.py','hardy_arb.pyx','checks.py','readback.py']}}))
