// VBB local smoke test. Boots the app in prototype mode (no DOCSTORE_URL: files in a throwaway data dir under qa/out), // with a tiny loop (5 places, 3 visitors per shift) so shifts and cycles happen in seconds, then checks the splash, // verified visitors (bots, early, repeats, the per-IP cap), shifts + a cycle + the reward ledger, posting banners // (upload, checks, credits), network sign-in, the leaderboard, the admin endpoint, a restart, the VBBShop hooks (sponsor vouchers, // purchase crediting from a fake chain), and page renders. // Nothing leaves this machine: the network lookup and the chain are local stand-ins, the link probe is off, no real wallet, no money. // // node qa/smoke.mjs (Playwright renders too, if it is installed at PLAYWRIGHT) // SKIP_UI=1 node qa/smoke.mjs (HTTP checks only) import { spawn } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import zlib from 'node:zlib'; import crypto from 'node:crypto'; import { createRequire } from 'node:module'; import { fileURLToPath } from 'node:url'; const require = createRequire(import.meta.url); const { ethers } = require('ethers'); const APP = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const OUT = path.join(APP, 'qa', 'out'); fs.mkdirSync(OUT, { recursive: true }); const DATA = path.join(OUT, 'data-' + Date.now()); fs.mkdirSync(DATA, { recursive: true }); const PW = process.env.PLAYWRIGHT || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright'; const PORT = Number(process.env.SMOKE_APP_PORT || 3217), BASE = 'http://127.0.0.1:' + PORT; const ADMIN = 'smoke-admin-token', SSO_SECRET = crypto.randomBytes(32).toString('hex'); // stand-in for the network member lookup: wallets in NET are network members, everyone else is a stranger // NETSP: wallet -> that member's network sponsor wallet (the hub's `sponsor` field) const NET = new Set(); const NETSP = new Map(); const LOOKUP_PORT = PORT + 1; require('node:http').createServer((q, r) => { const a = (new URL(q.url, 'http://x').searchParams.get('a') || '').toLowerCase(); r.setHeader('Content-Type', 'application/json'); r.end(JSON.stringify(NET.has(a) ? { address: a, username: 'net' + a.slice(2, 10), sponsor: NETSP.get(a) || null } : {})); }).listen(LOOKUP_PORT, '127.0.0.1').unref(); // stand-in Polygon JSON-RPC for the purchase watcher: CHAIN.logs are served by block range (or all of them when replayAll is on, // like a flaky RPC re-sending old logs). Nothing here is a real chain. const CHAIN = { head: 1, logs: [], replayAll: false, receipts: {} }; const QUOTE_SEL = ethers.id('quoteWei(uint256,uint256)').slice(0, 10); const CHAIN_PORT = PORT + 2; const SHOP = '0x00000000000000000000000000000000000B0B05', KEEPER_PK = '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d'; // anvil's public test key #1 require('node:http').createServer(async (q, r) => { let b = ''; for await (const c of q) b += c; const j = JSON.parse(b || '{}'); let result = null; if (j.method === 'eth_blockNumber') result = '0x' + CHAIN.head.toString(16); // quoteWei(sku, qty): $ cents x qty at a stand-in POL price of $0.25 (1 cent = 0.04 POL); a receipt for any hash in CHAIN.receipts if (j.method === 'eth_call') { const d = j.params[0].data || ''; if (d.startsWith(QUOTE_SEL)) { const sku = Number(BigInt('0x' + d.slice(10, 74))), qty = Number(BigInt('0x' + d.slice(74, 138))); const cents = { 1: 300, 2: 1000, 3: 200 }[sku] || 0; result = '0x' + (BigInt(cents * qty) * 4n * 10n ** 16n).toString(16).padStart(64, '0'); } } if (j.method === 'eth_getTransactionReceipt') result = CHAIN.receipts[j.params[0]] || null; if (j.method === 'eth_maxPriorityFeePerGas') result = '0x' + (40n * 10n ** 9n).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), checks each signature, and answers // POST /v1/resolve {wallet | ref | id | email} the way the real hub does for a site without emails. The hub knows every NET wallet // (minus HUBSKIP: wallets only InstantAdPay knows), every sponsor wallet in NETSP, HUBONLY wallets, and HUBMAIL emails. // HUB.down = every hub call fails with 503 (unreachable). const HUB = { got: [], badSig: 0, resolves: 0, down: false }; const HUB_PORT = PORT + 3, HUB_SECRET = 'h'.repeat(40); const HUBSKIP = new Set(), HUBONLY = new Set(), HUBMAIL = new Map(); const hubKnows = w => !!w && ((NET.has(w) && !HUBSKIP.has(w)) || HUBONLY.has(w) || [...NETSP.values()].includes(w)); const hubId = w => 'h_' + w.slice(2, 18); const hubPerson = w => hubKnows(w) ? { id: hubId(w), username: 'net' + w.slice(2, 10), wallet: w, blocked: false, sponsor: NETSP.get(w) && hubKnows(NETSP.get(w)) ? { id: hubId(NETSP.get(w)), username: 'net' + NETSP.get(w).slice(2, 10) } : null } : null; const hubAll = () => [...new Set([...NET, ...HUBONLY, ...NETSP.values()])].filter(hubKnows); require('node:http').createServer(async (q, r) => { let b = ''; for await (const c of q) b += c; 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'] !== 'vbb') { HUB.badSig++; r.statusCode = 401; return r.end('{}'); } if (q.url === '/v1/resolve') { HUB.resolves++; const j = JSON.parse(b || '{}'); const ref = String(j.ref || '').toLowerCase(); let w = null; if (j.wallet) w = String(j.wallet).toLowerCase(); else if (j.id) w = hubAll().find(x => hubId(x) === j.id); else if (ref) w = hubAll().find(x => x === ref || 'net' + x.slice(2, 10) === ref); else if (j.email && HUBMAIL.has(j.email)) return r.end(JSON.stringify({ person: { id: 'h_' + '9'.repeat(16), username: HUBMAIL.get(j.email), wallet: null, sponsor: null, blocked: false } })); return r.end(JSON.stringify({ person: hubPerson(w) })); } HUB.got.push({ route: q.url, body: JSON.parse(b) }); r.end(JSON.stringify({ id: 'p' + HUB.got.length })); }).listen(HUB_PORT, '127.0.0.1').unref(); // stand-in LinkSpin partner API (/api/partner/bl/spins, the Banner Spins call): checks the NETWORK_SSO_SECRET signature and // site 'vbb', answers like LinkSpin (account by wallet, else by network username; 125x125 + 250x250 spins only). LSA: wallet -> // { username, spins: [{ id, name, code, size, paused, banners }] }; LS.tamper(use) may change a "use" answer (bad size, bad host). const LS = { calls: [], badSig: 0, tamper: null }; const LSA = new Map(); const LS_PORT = PORT + 4, LS_HOST = 'rubav-standin.com'; require('node:http').createServer(async (q, r) => { let b = ''; for await (const c of q) b += c; r.setHeader('Content-Type', 'application/json'); const ts = String(q.headers['x-net-ts'] || ''), want = crypto.createHmac('sha256', SSO_SECRET).update('net.v1.' + ts + '\n' + b).digest('hex'); if (q.url !== '/api/partner/bl/spins' || q.headers['x-net-sig'] !== want || Math.abs(Date.now() - Number(ts)) > 300000) { LS.badSig++; r.statusCode = 401; return r.end('{"error":"unauthorized"}'); } const j = JSON.parse(b || '{}'); LS.calls.push(j); let a = LSA.get(j.wallet); if (a && a.byName) a = null; if (!a && j.username) a = [...LSA.values()].find(x => x.byName && x.username === j.username); if (!a) return r.end('{"account":false}'); const sp = a.spins.filter(x => j.site === 'vbb' ? ['125x125', '250x250'].includes(x.size) : x.size === '468x60'); const out = { account: true, username: a.username, host: LS_HOST, spins: sp }; if (j.spinId != null) { const x = sp.find(y => y.id === j.spinId); if (!x) { r.statusCode = 404; return r.end('{"error":"No such 125x125 (or 250x250) Banner Spin on this LinkSpin account."}'); } out.use = { spinId: x.id, name: x.name, size: x.size, img: 'https://' + LS_HOST + '/i/' + x.code + '.gif', link: 'https://' + LS_HOST + '/c/' + x.code + '?clickid={clickid}&placement={spot}&s1={type}', otherSource: !!x.otherSource }; if (LS.tamper) LS.tamper(out.use); } r.end(JSON.stringify(out)); }).listen(LS_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', LS_PARTNER_URL: 'http://127.0.0.1:' + LS_PORT, LS_SPINS_FIRST_MS: '300', LS_SPINS_EVERY_MS: '700', 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', NETKB: '0', HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'vbb', HUB_TICK_MS: '300', HUB_DOWN_MS: '400' }); 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) : '')); } }; process.on('exit', () => { try { srv && srv.kill(); } catch (e) {} }); // ---- tiny cookie-jar HTTP client; each client is one "visitor" (its own IP via X-Forwarded-For and its own user agent) ---- let nextIp = 10; function client(opts = {}) { const jar = {}; const ip = opts.ip || ('203.0.113.' + (nextIp++)); const ua = opts.ua || ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) SmokeBrowser/' + ip); return { jar, ip, ua, async req(p, o = {}) { const headers = Object.assign({ 'User-Agent': ua, 'X-Forwarded-For': ip, Cookie: Object.entries(jar).map(([k, v]) => k + '=' + v).join('; ') }, o.headers || {}); const r = await fetch(BASE + p, { method: o.method || 'GET', headers, body: o.body, redirect: 'manual' }); for (const c of r.headers.getSetCookie ? r.headers.getSetCookie() : []) { const [kv] = c.split(';'); const i = kv.indexOf('='); jar[kv.slice(0, i)] = kv.slice(i + 1); } return r; }, async json(p, body, extra) { const r = await this.req(p, body === undefined ? { headers: extra } : { method: 'POST', headers: Object.assign({ 'Content-Type': 'application/json' }, extra), body: JSON.stringify(body) }); return Object.assign({ _status: r.status }, await r.json().catch(() => ({}))); } }; } function png(w, h, seed) { const crcT = Array.from({ length: 256 }, (_, n) => { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; return c >>> 0; }); const crc = b => { let c = 0xffffffff; for (const x of b) c = crcT[(c ^ x) & 255] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0; }; const chunk = (t, d) => { const len = Buffer.alloc(4); len.writeUInt32BE(d.length); const td = Buffer.concat([Buffer.from(t), d]); const c = Buffer.alloc(4); c.writeUInt32BE(crc(td)); return Buffer.concat([len, td, c]); }; const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4); ihdr[8] = 8; ihdr[9] = 2; const s = seed || 0; const raw = Buffer.alloc((w * 3 + 1) * h); for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) { const o = y * (w * 3 + 1) + 1 + x * 3; const band = ((x + y + s * 17) >> 4) & 1; raw[o] = band ? 255 : 20 + s * 30; raw[o + 1] = band ? 91 + s * 20 : 30; raw[o + 2] = band ? 46 : 80 + y; } return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk('IHDR', ihdr), chunk('IDAT', zlib.deflateSync(raw)), chunk('IEND', Buffer.alloc(0))]); } async function boot() { const log = fs.openSync(path.join(OUT, 'server.log'), 'a'); srv = spawn(process.execPath, ['server.js'], { cwd: APP, env: ENV, stdio: ['ignore', log, log] }); for (let i = 0; i < 60; i++) { try { const r = await fetch(BASE + '/api/config'); if (r.ok) return; } catch (e) {} await sleep(150); } throw new Error('server did not start; see qa/out/server.log'); } async function stop() { const p = srv; srv = null; if (!p) return; const done = new Promise(r => p.once('exit', r)); p.kill('SIGINT'); await Promise.race([done, sleep(3000)]); } // a signed-in member by wallet signature async function walletMember(o = {}) { const w = ethers.Wallet.createRandom(); const c = client(); if (!o.stranger && !o.hubOnly) NET.add(w.address.toLowerCase()); if (o.hubOnly) HUBONLY.add(w.address.toLowerCase()); if (o.iapOnly) HUBSKIP.add(w.address.toLowerCase()); if (o.sponsor) NETSP.set(w.address.toLowerCase(), o.sponsor === 'self' ? w.address.toLowerCase() : o.sponsor.toLowerCase()); const ch = await c.json('/api/auth/challenge', { address: w.address }); const v = await c.json('/api/auth/verify', { address: w.address, signature: await w.signMessage(ch.message) }); c.address = w.address.toLowerCase(); c.ok = v.ok === true && !!c.jar['vbb.sid']; return c; } async function upload(c, buf) { const r = await c.req('/api/my/upload', { method: 'POST', headers: { 'Content-Type': 'application/octet-stream' }, body: buf }); return Object.assign({ _status: r.status }, await r.json()); } async function postBanner(c, seed, link) { const u = await upload(c, png(125, 125, seed)); return c.json('/api/my/banners', { img: u.img, link: link || 'https://example-member.com/offer?id=' + seed }); } // one verified visit: ticket, wait, seen async function visit(c, o = {}) { const s = await c.json('/api/visit/start', { ref: o.ref || '', src: o.src || '' }); if (!s.ticket) return { counted: false, why: 'no-ticket', start: s }; await sleep(o.wait != null ? o.wait : 2100); return Object.assign({ start: s }, await c.json('/api/visit/seen', { ticket: s.ticket, visibleMs: o.visibleMs != null ? o.visibleMs : 2100 })); } async function main() { const appBusy = await fetch(BASE).then(() => true, () => false); if (appBusy) throw new Error('port ' + PORT + ' is already in use; set SMOKE_APP_PORT'); console.log('data dir', DATA); console.log('1. copy rules (no em dashes, no MetaMask recommendation, no income promises)'); const pub = path.join(APP, 'public'); const files = fs.readdirSync(pub).filter(f => f.endsWith('.html')).map(f => path.join(pub, f)).concat(fs.readdirSync(path.join(pub, 'assets')).filter(f => /\.(js|css)$/.test(f) && f !== 'wallet.js').map(f => path.join(pub, 'assets', f))); const texts = files.map(f => [path.basename(f), fs.readFileSync(f, 'utf8')]); ok(texts.every(([, t]) => !/[\u2014\u2013]/.test(t)), 'no em or en dashes in any page or script', texts.filter(([, t]) => /[\u2014\u2013]/.test(t)).map(x => x[0])); const html = texts.filter(([n]) => n.endsWith('.html')).map(x => x[1]).join('\n'); ok(!/metamask/i.test(html), 'pages never name MetaMask'); ok(/SafePal or any other crypto wallet/.test(html), 'wallet copy says "SafePal or any other crypto wallet"'); ok(!/passive income|guaranteed (income|returns|profit)|earn (cash|money)|make money/i.test(html), 'no income promises in page copy'); ok(/never a subscription/i.test(html), 'packages page says never a subscription'); console.log('2. boot (prototype mode, temp data dir)'); await boot(); const cfg = await (await fetch(BASE + '/api/config')).json(); ok(cfg.loopSize === 5 && cfg.perShift === 3 && cfg.viewsPerCycle === 150 && cfg.visitSeconds === 2, 'config from env', cfg); ok(fs.readFileSync(path.join(OUT, 'server.log'), 'utf8').includes('files (prototype mode)'), 'server says prototype mode (no DOCSTORE_URL)'); ok(JSON.stringify(cfg.packs) === '[{"credits":10,"usd":3,"sku":1},{"credits":40,"usd":10,"sku":2}]' && cfg.lookUsd === 2 && cfg.lookSku === 3 && cfg.freeCreditsPerDay === 1, 'approved defaults: packs 10 for $3 + 40 for $10, look $2, 1 free credit a day', cfg); ok(cfg.prizes && cfg.prizes.pot === 20 && JSON.stringify(cfg.prizes.visitors) === '[5,3,2]' && JSON.stringify(cfg.prizes.sources) === '[5,3,2]', 'prize pot: $20 floor with no sales, $5/$3/$2 per board', cfg.prizes); ok(!JSON.stringify(cfg).includes('capUsd') && !JSON.stringify(cfg).includes('"cap'), 'public config never shows the prize cap', cfg); console.log('3. splash'); const anon = client(); let r = await anon.req('/'); const home = await r.text(); ok(r.status === 200 && /Viral Banner Blitz/.test(home) && /id="loop"/.test(home) && /id="bar"/.test(home), 'GET / serves the splash (loop grid + shift bar)'); ok(!r.headers.get('x-frame-options'), 'splash stays frameable (traffic exchanges)'); ok(/og:image" content="https:\/\/viralbannerblitz\.com\/art\/og-share\.png/.test(home) && /application\/ld\+json/.test(home), 'splash has Open Graph + JSON-LD'); let sp = await anon.json('/api/splash'); ok(sp.loopSize === 5 && sp.perShift === 3 && sp.progress === 0 && sp.loop.length === 0 && sp.waiting === 0, 'empty loop at start', sp); for (const pth of ['/leaders', '/how', '/packages', '/robots.txt', '/sitemap.xml', '/art/mark.svg', '/assets/vbb.css', '/assets/splash.js']) { r = await anon.req(pth); ok(r.status === 200, 'GET ' + pth + ' 200', r.status); } r = await anon.req('/my'); ok(r.status === 200 && r.headers.get('x-frame-options') === 'DENY', '/my served, never framed'); // promo kit (2026-11-14): one public feed read by /promote and by InstantAdPay's promo center { const kr = await anon.req('/api/promo-kit?u=smokeleader'); const k = await kr.json(); ok(kr.status === 200 && kr.headers.get('access-control-allow-origin') === '*', 'promo kit: GET /api/promo-kit 200 with CORS open', kr.status); ok(k.username === 'smokeleader' && k.links.length === 3 && k.links.every(l => l.url.startsWith('https://viralbannerblitz.com/') && l.url.endsWith('?ref=smokeleader')), 'promo kit: every link carries ?ref=', k.links); ok(k.links.every(l => /^https:\/\/linkspin\.app\/r\/nwvbb\?src=vbb&s1=smokeleader(&s2=[a-z]+)?$/.test(l.tracked)) && k.links[0].tracked.indexOf('&s2=') < 0 && /&s2=how$/.test(k.links[1].tracked), 'promo kit: every link has a LinkSpin-tracked twin (network link nwvbb, source vbb, the member as s1, the page as s2)', k.links.map(l => l.tracked)); ok(k.lines.length === 5 && k.headlines.length === 3 && k.posts.length === 2 && k.email && k.email.subject && k.email.body.includes('?ref=smokeleader'), 'promo kit: 5 lines, 3 headlines, 1 email, 2 posts, link filled in'); const words = JSON.stringify([k.lines, k.headlines, k.email, k.posts, k.note, k.tagline]); ok(!/[—–]/.test(words) && !/\$50|passive income|guaranteed (income|returns|profit)|earn (cash|money)|make money/i.test(words) && /at least \$20/.test(words), 'promo kit copy: no dashes, no cap, no income promises, pot shown as at least $20'); ok(k.creatives.length === 24 && new Set(k.creatives.map(c => c.angle)).size === 3, 'promo kit: 24 creatives in 3 angles', k.creatives.length); const badName = k.creatives.filter(c => /\d{2,4}x\d{2,4}|banner|[-_/]ads?[-_./]/i.test(c.url.replace('https://viralbannerblitz.com', ''))); ok(badName.length === 0, 'promo kit: creative paths are ad-blocker neutral (no size tokens, no banner/ad words)', badName.map(c => c.url)); let dimOk = true; const dimBad = []; for (const c of k.creatives) { const rr = await anon.req(new URL(c.url).pathname); const buf = Buffer.from(await rr.arrayBuffer()); const w = buf.readUInt32BE(16), h = buf.readUInt32BE(20); if (rr.status !== 200 || rr.headers.get('content-type') !== 'image/png' || w !== c.w || h !== c.h) { dimOk = false; dimBad.push(c.key + ' ' + rr.status + ' ' + w + 'x' + h); } if (!c.html.includes('href="https://viralbannerblitz.com/?ref=smokeleader"')) { dimOk = false; dimBad.push(c.key + ' html'); } } ok(dimOk, 'promo kit: every creative is served as PNG at its exact size, HTML links to the member', dimBad); const k2 = await (await anon.req('/api/promo-kit?u=' + encodeURIComponent('x'))).json(); ok(k2.username === null && k2.links[0].url === 'https://viralbannerblitz.com/', 'promo kit: a bad username is ignored (plain links)', k2.links[0]); r = await anon.req('/promote'); const ph = await r.text(); ok(r.status === 200 && /id="kit"/.test(ph) && /kitpage\.js/.test(ph), 'GET /promote serves the Promote page'); r = await anon.req('/no-such-page'); const nf = await r.text(); ok(r.status === 404 && /Back to the loop/.test(nf), '404 page served'); ok(/script-src[^;]*https:\/\/linkspin\.app/.test(r.headers.get('content-security-policy') || ''), 'CSP admits linkspin.app (network zones)'); r = await anon.req('/sitemap.xml'); ok((await r.text()).includes('/promote'), 'sitemap lists /promote'); } r = await anon.req('/api/my'); ok(r.status === 401, '/api/my needs sign-in'); // the site assistant (2026-11-15): widget on every page, canned answers without AI, account problems hand off, admin KB behind the token { const home = await (await anon.req('/')).text(); ok(/