Launch prep: /health + Dockerfile HEALTHCHECK; old site links (/?<old username>, /splashpg.php?pid=N&r=, /lcp.php?pid=N&r= -> /?ref=<network username> from the oldrefs.json MySQL document, loaded by POST /api/admin/oldrefs; any other *.php -> /), checked before any page; hubreport.js (DLB pattern): each VBBShop purchase reported to the network hub by wallet, first as contract-bind with the sponsor, later as contract-spend, signed as vbb, off unless HUB_ENABLED; compose passes HUB_* + RPC_URLS + CHAIN_ID. Smoke 134/134

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 08:03:26 -06:00
parent 07cc1944e6
commit be9de262db
6 changed files with 159 additions and 3 deletions
+36 -1
View File
@@ -36,10 +36,17 @@ require('node:http').createServer(async (q, r) => { let b = ''; for await (const
if (j.method === 'eth_blockNumber') result = '0x' + CHAIN.head.toString(16);
if (j.method === 'eth_getLogs') { const f = j.params[0], lo = parseInt(f.fromBlock, 16), hi = parseInt(f.toBlock, 16); result = CHAIN.logs.filter(l => CHAIN.replayAll || (parseInt(l.blockNumber, 16) >= lo && parseInt(l.blockNumber, 16) <= hi)); }
r.setHeader('Content-Type', 'application/json'); r.end(JSON.stringify({ jsonrpc: '2.0', id: j.id, result })); }).listen(CHAIN_PORT, '127.0.0.1').unref();
// stand-in network hub: records the signed reports (contract-bind / contract-spend) and checks each signature
const HUB = { got: [], badSig: 0 }; const HUB_PORT = PORT + 3, HUB_SECRET = 'h'.repeat(40);
require('node:http').createServer(async (q, r) => { let b = ''; for await (const c of q) b += c;
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'] !== 'vbb') { HUB.badSig++; r.statusCode = 401; return r.end('{}'); }
HUB.got.push({ route: q.url, body: JSON.parse(b) }); r.setHeader('Content-Type', 'application/json'); r.end(JSON.stringify({ id: 'p' + HUB.got.length })); }).listen(HUB_PORT, '127.0.0.1').unref();
const ENV = Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, ADMIN_TOKEN: ADMIN, NODE_ENV: 'development', DOCSTORE_URL: '',
LOOP_SIZE: '5', VISITORS_PER_SHIFT: '3', VIEWS_PER_CYCLE: '150', VISIT_SECONDS: '2', VISITS_PER_IP_DAY: '2', LINK_PROBE: '0', NETWORK_LOOKUP_URL: 'http://127.0.0.1:' + (PORT + 1) + '/api/network/member',
NETWORK_SSO_SECRET: SSO_SECRET, IAP_URL: 'https://iap.invalid', LS_URL: 'https://ls.invalid',
CONTRACT_ADDRESS: SHOP, CHAIN_RPC: 'http://127.0.0.1:' + CHAIN_PORT, KEEPER_KEY: KEEPER_PK, SHOP_START_BLOCK: '1', SHOP_CONFIRMATIONS: '0', SHOP_POLL_MS: '200' });
CONTRACT_ADDRESS: SHOP, CHAIN_RPC: 'http://127.0.0.1:' + CHAIN_PORT, KEEPER_KEY: KEEPER_PK, SHOP_START_BLOCK: '1', SHOP_CONFIRMATIONS: '0', SHOP_POLL_MS: '200',
HUB_ENABLED: '1', HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'vbb', HUB_TICK_MS: '300' });
const sleep = ms => new Promise(r => setTimeout(r, ms));
let pass = 0, fail = 0; let srv = null;
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, 400) : '')); } };
@@ -300,6 +307,34 @@ async function main() {
my = await V.json('/api/my'); ok(my.credits === credits0 + 60, 'after a restart the replayed logs still credit nothing', my.credits);
const cfgNow = await (await fetch(BASE + '/api/config')).json(); ok(!JSON.stringify(cfgNow).toLowerCase().includes(SHOP.slice(2).toLowerCase()), 'public config does not offer the contract yet (packages stay coming soon)');
// ---- 12b. hub report: each purchase reported once, signed as vbb (first = bind with the sponsor, later = spend) ----
console.log('12b. hub report');
await sleep(1200);
const binds = HUB.got.filter(x => x.route === '/v1/contract-bind'), spends = HUB.got.filter(x => x.route === '/v1/contract-spend');
ok(HUB.badSig === 0 && binds.length === 1 && binds[0].body.contract === 'viralbannerblitz' && binds[0].body.wallet === V.address && binds[0].body.sponsorRef === spW && binds[0].body.spentCents === 600 && binds[0].body.tx === tx1, 'hub: the first purchase is a signed contract-bind with the sponsor wallet and 600 cents', HUB);
ok(spends.length === 1 && spends[0].body.wallet === V.address && spends[0].body.cents === 1000, 'hub: the second purchase is a contract-spend of 1000 cents', spends);
const adh = await anon.json('/api/admin/status', undefined, { 'x-admin-token': ADMIN });
ok(adh.hub && adh.hub.enabled && adh.hub.sent === 2 && adh.hub.site === 'vbb' && !JSON.stringify(adh).includes(HUB_SECRET), 'admin status shows the hub report (2 sent), never the secret', adh.hub);
// ---- 12c. old site links + health ----
console.log('12c. old site links + health');
r = await anon.req('/health'); let hj = await r.json(); ok(r.status === 200 && hj.ok === true && hj.store === 'files', '/health answers ok (files in the smoke test)', hj);
r = await anon.json('/api/admin/oldrefs', { oldrefs: { oldguy: 'netguy', 'bad key!': 'x', other: 'bad value!' } }); ok(r._status === 401, 'loading old refs needs the admin token');
r = await anon.json('/api/admin/oldrefs', { oldrefs: { oldguy: 'netguy', '224411': 'berninisonia80', 'bad key!': 'x', other: 'bad value!' } }, { 'x-admin-token': ADMIN });
ok(r.ok && r.total === 2 && r.skipped === 2, 'admin loads the old username map, bad rows skipped', r);
const oloc = async q => { const x = await anon.req(q); return x.status + ' ' + x.headers.get('location'); };
ok(await oloc('/?oldguy') === '301 /?ref=netguy', '/?<old username> -> /?ref=<network username>');
ok(await oloc('/?OldGuy&fbclid=abc') === '301 /?ref=netguy', 'old username is case-insensitive and fbclid may follow');
ok(await oloc('/?224411') === '301 /?ref=berninisonia80', 'a numeric old username maps too');
ok(await oloc('/splashpg.php?pid=3&r=oldguy') === '301 /?ref=netguy', '/splashpg.php?pid=N&r=<old> -> /?ref=<network>');
ok(await oloc('/lcp.php?pid=12&r=oldguy') === '301 /?ref=netguy', '/lcp.php?pid=N&r=<old> -> /?ref=<network>');
ok(await oloc('/?nobodyhere') === '301 /', 'an unknown old username goes home');
ok(await oloc('/splashpg.php?pid=3&r=nobodyhere') === '301 /', 'an unknown old splash ref goes home');
ok(await oloc('/members.php') === '301 /' && await oloc('/login.php?x=1') === '301 /', 'any other old *.php page goes home');
r = await anon.req('/?ref=netguy'); ok(r.status === 200, 'the new ?ref= link is served, not redirected');
r = await anon.req('/'); ok(r.status === 200, 'the plain home page is served');
const adr = await anon.json('/api/admin/status', undefined, { 'x-admin-token': ADMIN }); ok(adr.oldrefs === 2, 'admin status counts the old refs', adr.oldrefs);
// ---- 13. page renders (Playwright, if installed) ----
if (!process.env.SKIP_UI && fs.existsSync(PW)) {
console.log('13. page renders (Playwright)');