0254f933be
One box: member ID or wallet address -> member ID, wallet (short, full on hover + Copy), level and tier, join date, sponsor ID (clickable), direct referral count, Polygonscan link, public dashboard link. Chain facts only, never names or emails. RM Circle only; nothing from any other site. - chain.lookupPublic: served from the indexed state (zero RPC); only a position or wallet the index has not seen yet falls back to one eth_call (memberId(address) 0x39106821, verified live: 0x7c7D...d3c2 -> 7230) - /api/public/lookup: own 12/min per-IP limiter, 3-minute answer cache (negative answers too), global budget of 60 RPC fallbacks per minute - page lookup.html + lookup.js (no inline script), ?q= deep links, /find alias - "Find a Member" in every site footer; chat.js?v=20261114a - chatbot: canned answer in chat.js + FACT line and Site pages entry in the AI system prompt - tests: qa/lookup-unit.mjs (25), qa/lookup-e2e.mjs (51, desktop + phone, CSP, no-email, rate limit) against qa/harness-server.js LOOKUP_SEED Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
3.3 KiB
JavaScript
63 lines
3.3 KiB
JavaScript
// Find a member (/lookup): chain.lookupPublic against a seeded index, no RPC.
|
|
// node qa/lookup-unit.mjs
|
|
import { createRequire } from 'node:module';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
const require = createRequire(import.meta.url);
|
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
const chain = require('../chain.js');
|
|
chain.__test.setState(JSON.parse(fs.readFileSync(path.join(here, 'fixtures', 'lookup-index.json'), 'utf8')));
|
|
|
|
const ok = [], bad = [];
|
|
const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || !extra ? '' : ' -> ' + extra)); };
|
|
const off = { allowRpc: false };
|
|
|
|
// input validation
|
|
const P = chain.parseLookupQuery;
|
|
t('a plain number is an id', P('21').kind === 'id' && P('21').id === 21);
|
|
t('a #-prefixed number is an id', P('#7230').id === 7230);
|
|
t('whitespace is trimmed', P(' 21 ').id === 21);
|
|
t('zero is refused', !!P('0').error);
|
|
t('a 16-digit number is refused', !!P('1234567890123456').error);
|
|
t('a full address is an address, lowercased', P('0x7c7D9F0F11bbc66a700245795c374971BfBed3c2').address === '0x7c7d9f0f11bbc66a700245795c374971bfbed3c2');
|
|
t('a short address is refused', !!P('0x7c7D9F0F11bbc66a').error);
|
|
t('non-hex address is refused', !!P('0xZZ7D9F0F11bbc66a700245795c374971BfBed3c2').error);
|
|
t('free text is refused', !!P('marty').error);
|
|
t('script text is refused', !!P('<script>alert(1)</script>').error);
|
|
t('empty is refused', !!P('').error);
|
|
|
|
// by id, from the index
|
|
const a = await chain.lookupPublic('7230', off);
|
|
t('#7230 is found from the index', a.found && a.source === 'index', JSON.stringify(a));
|
|
t('#7230 wallet is lowercased', a.account === '0x7c7d9f0f11bbc66a700245795c374971bfbed3c2');
|
|
t('#7230 sponsor is #21', a.sponsorId === 21);
|
|
t('#7230 level/tier names', a.levelName === 'Scintilla' && a.tierName === 'Premium' && a.level === 1);
|
|
t('#7230 direct count', a.directCount === 1);
|
|
t('#7230 join time', a.joinedAt === 1762900000);
|
|
|
|
// by wallet, mixed case, from the index
|
|
const b = await chain.lookupPublic('0x7C7D9F0F11BBC66A700245795C374971BFBED3C2', off);
|
|
t('wallet lookup resolves to #7230 with no RPC', b.found && b.id === 7230 && b.source === 'index', JSON.stringify(b));
|
|
|
|
const c = await chain.lookupPublic('21', off);
|
|
t('#21 is Apex, qualified, sponsored by root', c.levelName === 'Apex' && c.directCount === 2 && c.sponsorId === 1);
|
|
t('never copies unknown index fields (no email)', !('email' in c) && !JSON.stringify(c).includes('example.com'));
|
|
|
|
const r = await chain.lookupPublic('1', off);
|
|
t('the root shows no sponsor', r.found && r.sponsorId === null);
|
|
|
|
// misses never call RPC when RPC is not allowed
|
|
const m1 = await chain.lookupPublic('99999', off);
|
|
t('an unknown id reports busy (needs a chain read)', m1.busy === true && !m1.found);
|
|
const m2 = await chain.lookupPublic('0x3333333333333333333333333333333333333333', off);
|
|
t('an unknown wallet reports busy (needs a chain read)', m2.busy === true && !m2.found);
|
|
const m3 = await chain.lookupPublic('7231', off);
|
|
t('a provisional (preIndexed) entry is re-read from the chain, not trusted', m3.busy === true);
|
|
const e = await chain.lookupPublic('hello', off);
|
|
t('bad input returns an error, not a lookup', !!e.error);
|
|
|
|
console.log(ok.map(x => 'ok ' + x).join('\n'));
|
|
if (bad.length) { console.log(bad.map(x => 'FAIL ' + x).join('\n')); process.exit(1); }
|
|
console.log(`\n${ok.length} passed`);
|