Member lookups through the network hub (Marty 2026-11-14: "want everything looped through the hub to verify membership"): hubpeople.js asks POST /v1/resolve (ref / wallet / hub id, signed as bannerline, cached 5 minutes, 2.5 s timeout, hub skipped 30 s after a failure); netMember / nameOf ask the hub first and InstantAdPay's /api/network/member only when the hub is unreachable (wallet-aliases.json still first). Sponsor pick: the hub network sponsor for the wallet that will own the spot (the buy page asks /api/sponsor?for=<owner> just before the buy; else the signed-in wallet), resolved to a wallet by hub id, nearest up the network line who owns a spot here, none = no sponsor; then the /w/ welcome line (usernames resolved through the hub), then the ?ref= cookie. Admin status shows hubLookup. join.js?v=20261114h. Smoke 91/91 (stand-in hub + stand-in InstantAdPay)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 09:25:46 -06:00
parent 7c2aab8f65
commit 57e733b55d
5 changed files with 167 additions and 11 deletions
+55 -2
View File
@@ -25,6 +25,26 @@ const ADMIN = 'smoke-admin';
const sleep = ms => new Promise(r => setTimeout(r, ms));
let pass = 0, fail = 0; const procs = [];
const ok = (cond, what, extra) => { if (cond) { pass++; console.log(' ok ' + what); } else { fail++; console.log(' FAIL ' + what + (extra !== undefined ? ' -> ' + JSON.stringify(extra).slice(0, 300) : '')); } };
// stand-in network hub (POST /v1/resolve, signed as bannerline) and stand-in InstantAdPay member lookup (the fallback when the
// hub is unreachable). HUB.people: {id, username, wallet, sponsorId}; HUB.down makes every hub call fail with 503.
const HUB = { people: [], down: false, calls: 0, badSig: 0 }; const HUB_PORT = APP_PORT + 7, HUB_SECRET = 'b'.repeat(40);
const IAPNET = new Map(); const IAP_PORT = APP_PORT + 8;
const hubView = p => p ? { id: p.id, username: p.username, wallet: p.wallet, sponsor: (x => x ? { id: x.id, username: x.username } : null)(HUB.people.find(y => y.id === p.sponsorId)), blocked: false, locked: false } : null;
function startStandIns() {
const http = require('node:http'); const crypto = require('node:crypto');
http.createServer(async (q, r) => { let b = ''; for await (const c of q) b += c; HUB.calls++;
r.setHeader('Content-Type', 'application/json');
if (HUB.down) { r.statusCode = 503; return r.end('{"error":"superseded"}'); }
const want = crypto.createHmac('sha256', HUB_SECRET).update(q.headers['x-hub-ts'] + '\n' + b).digest('hex');
if (q.headers['x-hub-sig'] !== want || q.headers['x-hub-site'] !== 'bannerline') { HUB.badSig++; r.statusCode = 401; return r.end('{"error":"unauthorized"}'); }
if (q.url !== '/v1/resolve') { r.statusCode = 404; return r.end('{"error":"not_found"}'); }
const j = JSON.parse(b || '{}'); const ref = String(j.ref || '').toLowerCase();
const p = j.id ? HUB.people.find(x => x.id === j.id) : j.wallet ? HUB.people.find(x => x.wallet === String(j.wallet).toLowerCase()) : ref ? HUB.people.find(x => x.username === ref || x.wallet === ref) : null;
r.end(JSON.stringify({ person: hubView(p) })); }).listen(HUB_PORT, '127.0.0.1').unref();
http.createServer((q, r) => { const u = new URL(q.url, 'http://x'); const un = (u.searchParams.get('u') || '').toLowerCase(), a = (u.searchParams.get('a') || '').toLowerCase();
const hit = [...IAPNET].find(([n, w]) => n === un || w === a); r.setHeader('Content-Type', 'application/json');
r.end(JSON.stringify(hit ? { address: hit[1], username: hit[0] } : {})); }).listen(IAP_PORT, '127.0.0.1').unref();
}
function cleanup() { for (const p of procs) { try { p.kill(); } catch (e) {} } }
process.on('exit', cleanup);
@@ -86,7 +106,14 @@ async function main() {
// house list for tests: reserved example domains only, so no real site sees test traffic
fs.writeFileSync(path.join(DATA, 'house.json'), JSON.stringify([{ key: 'one', title: 'Test house 1', img: '/art/house-iap.svg', link: 'https://example.com/' }, { key: 'two', title: 'Test house 2', img: '/art/house-linkspin.svg', link: 'https://example.net/' }]));
const env = Object.assign({}, process.env, { PORT: String(APP_PORT), DATA_DIR: DATA, CHAIN_ID: '31337', RPC_URLS: 'http://127.0.0.1:' + RPC_PORT, CONTRACT_ADDRESS: CA,
DEPLOY_BLOCK: String(deployBlock), POLL_MS: '1000', ADMIN_TOKEN: ADMIN, KEEPER_ENABLED: '1', KEEPER_KEY: W[7].signer.privateKey, KEEPER_STALL_HOURS: '0.01', KEEPER_EVERY_MIN: '0.25', NODE_ENV: 'development' });
DEPLOY_BLOCK: String(deployBlock), POLL_MS: '1000', ADMIN_TOKEN: ADMIN, KEEPER_ENABLED: '1', KEEPER_KEY: W[7].signer.privateKey, KEEPER_STALL_HOURS: '0.01', KEEPER_EVERY_MIN: '0.25', NODE_ENV: 'development',
HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'bannerline', HUB_ENABLED: '0', HUB_DOWN_MS: '400', NETWORK_LOOKUP_URL: 'http://127.0.0.1:' + IAP_PORT + '/api/network/member' });
startStandIns();
const hid = n => 'h_' + String(n).padStart(16, '0');
const ZW = ethers.Wallet.createRandom().address.toLowerCase(); // a network member with no spot here
HUB.people.push({ id: hid(1), username: 'alpha', wallet: addr[A].toLowerCase(), sponsorId: null }, { id: hid(2), username: 'beta', wallet: addr[B].toLowerCase(), sponsorId: hid(1) },
{ id: hid(3), username: 'zed', wallet: ZW, sponsorId: hid(2) }, { id: hid(4), username: 'zeta', wallet: null, sponsorId: null });
IAPNET.set('iaponly', addr[Cc].toLowerCase()); IAPNET.set('iapfallback', addr[D].toLowerCase());
const srv = spawn(process.execPath, ['server.js'], { cwd: APP, env, stdio: ['ignore', 'pipe', 'pipe'] }); procs.push(srv);
const log = fs.createWriteStream(path.join(OUT, 'server.log')); srv.stdout.pipe(log); srv.stderr.pipe(log);
const u = client();
@@ -151,7 +178,7 @@ async function main() {
ok(BigInt(my2.paidOutWei) === onChain && onChain > 0n, 'A paid out matches Paid events on chain (' + ethers.formatEther(onChain) + ' POL)', my2.paidOutWei);
ok(BigInt(my.paidInWei) === 2n * q, 'A paid in = 2 spots', my.paidInWei);
ok(my.directs && my.directs.length === 2 && my.directs.some(x => x.address === addr[B].toLowerCase()), 'A directs = B and E (buyFor sponsor)', my.directs);
ok(my.share.endsWith('?ref=' + addr[A].toLowerCase()), 'share link');
ok(my.share.endsWith('?ref=alpha'), 'share link uses the network username the hub has for the wallet', my.share);
const sid = my.spots[my.spots.length - 1].id;
ok((await m.json('/api/my/spot/' + sid, { link: 'http://example.org/' }))._status === 400, 'http link refused');
ok((await m.json('/api/my/spot/' + sid, { link: 'https://192.168.1.1/' }))._status === 400, 'IP link refused');
@@ -172,6 +199,32 @@ async function main() {
ok(t && t.img === up.img, 'board shows the uploaded image for that spot');
const go = await v.req('/go/' + sid); ok(go.headers.get('location') === 'https://example.org/landing', 'click relay goes to the member link');
// ---- 5b. network hub lookups (Marty 2026-11-14: everything through the hub; InstantAdPay only when the hub is unreachable) ----
console.log('5b. network hub lookups');
const nb = [1, 2, 3].map(() => ethers.Wallet.createRandom().address.toLowerCase());
HUB.people.push({ id: hid(11), username: 'newone', wallet: nb[0], sponsorId: hid(1) }, { id: hid(12), username: 'newtwo', wallet: nb[1], sponsorId: hid(3) }, { id: hid(13), username: 'newthree', wallet: nb[2], sponsorId: hid(4) });
ok((await m.json('/api/my')).username === 'alpha', 'My Spots shows the network username the hub has for the wallet');
let sp = await u.json('/api/sponsor?ref=alpha'); ok(sp.address === addr[A].toLowerCase() && sp.member, '?ref=<username> resolves through the hub', sp);
sp = await u.json('/api/sponsor?ref=iaponly'); ok(sp.address === null, 'a username only InstantAdPay knows: unknown while the hub answers', sp);
const rv = client(); await rv.req('/?ref=' + addr[Cc]);
sp = await rv.json('/api/sponsor?for=' + nb[0]); ok(sp.address === addr[A].toLowerCase() && sp.via === 'hub', 'buyer the hub knows: the hub network sponsor (resolved to a wallet by hub id) beats the ?ref= cookie', sp);
sp = await rv.json('/api/sponsor?for=' + nb[1]); ok(sp.address === addr[B].toLowerCase() && sp.via === 'hub', 'network sponsor without a spot here: the next one up the network line who has one', sp);
sp = await rv.json('/api/sponsor?for=' + nb[2]); ok(sp.address === null && sp.via === 'hub', 'network sponsor with no wallet and nobody above: no sponsor (never the ?ref= cookie, never the company)', sp);
sp = await rv.json('/api/sponsor?for=' + ethers.Wallet.createRandom().address); ok(sp.address === addr[Cc].toLowerCase() && sp.via === 'ref', 'a wallet the hub does not know: the ?ref= cookie as before', sp);
sp = await rv.json('/api/sponsor?for=' + addr[E]); ok(sp.via === 'ref', 'already a member here: the hub does not pick (the contract keeps the bound sponsor)', sp);
const wc = 'smokewl0001'; ok((await u.json('/api/admin/welcome', { codes: { [wc]: { line: ['nobodyhere', 'zed', 'beta'] } } }, { 'x-admin-token': ADMIN })).ok, 'welcome code saved');
const wv = client(); await wv.req('/w/' + wc); sp = await wv.json('/api/sponsor');
ok(sp.address === addr[B].toLowerCase() && sp.via === 'line', '/w/ welcome line: usernames resolved through the hub, first one with a spot here', sp);
ok(HUB.badSig === 0 && HUB.calls > 0, 'every hub call is signed as bannerline with HUB_SECRET', HUB);
HUB.down = true;
sp = await u.json('/api/sponsor?ref=iapfallback'); ok(sp.address === addr[D].toLowerCase(), 'hub unreachable: InstantAdPay answers the username lookup', sp);
const t0 = Date.now(); sp = await rv.json('/api/sponsor?for=' + ethers.Wallet.createRandom().address); ok(sp.via === 'ref' && Date.now() - t0 < 2000, 'hub unreachable: the sponsor pick falls back at once (no wait on the hub)', [sp, Date.now() - t0]);
const ah = await u.json('/api/admin/status', undefined, { 'x-admin-token': ADMIN });
ok(ah.hubLookup && ah.hubLookup.on && ah.hubLookup.stats.failed >= 1 && !JSON.stringify(ah).includes(HUB_SECRET), 'admin status shows the hub lookup (failures counted, no secret)', ah.hubLookup);
HUB.down = false; await sleep(500);
HUB.people.push({ id: hid(21), username: 'later', wallet: addr[Cc].toLowerCase(), sponsorId: null });
sp = await u.json('/api/sponsor?ref=later'); ok(sp.address === addr[Cc].toLowerCase(), 'the hub answers again after it comes back', sp);
// ---- 6. keeper ----
console.log('6. keeper (stall set to 36 s for the test)');
const adm = await u.json('/api/admin/status', undefined, { 'x-admin-token': ADMIN });