// 5xYourTeam local smoke test. Boots the app in prototype mode (no DOCSTORE_URL: files in a throwaway data dir under qa/out) with // the STUB holding tank and a test clock, against local stand-ins, then checks: copy rules, pages, the promo kit, sign-in (wallet + // network), position orders (line voucher signed by the keeper, already-bound line, hub down), purchases recorded from the chain // (ledger split: sponsor 25%, levels 5%, pot 10%, company; passed over; Telegram card once; hub report), instant picks, a live // draft (on the clock, manual pick, auto-picks, queue), coaching messages (no contact data anywhere), milestones -> cards, Best // Coach + Rookie, picks returning to the pool, the release hold, the Draft Day card, old links, admin, a restart, and Playwright // renders at 1280 and 390 with screenshots in qa/out. // Nothing leaves this machine: hub, chain RPC and Telegram are local stand-ins. No real wallet, no money, nobody adopted. // node qa/smoke.mjs SKIP_UI=1 node qa/smoke.mjs (HTTP only) UI_FONTS=1 (let Google Fonts load) import { spawn, spawnSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; import http from 'node:http'; 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 || 3561), BASE = 'http://127.0.0.1:' + PORT; const ADMIN = 'smoke-admin-token', SSO_SECRET = crypto.randomBytes(32).toString('hex'), HUB_SECRET = 'h'.repeat(40); const KEEPER_PK = '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d'; // anvil's public test key #1 const KEEPER = new ethers.Wallet(KEEPER_PK).address; const SHOP = '0x00000000000000000000000000000000005A5A5A'; const PRIZE = '0x000000000000000000000000000000000000bead'; const TANGEM = '0x7627Fc78876948AC9d95C1C9eB061E7D6d647b70'; 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, (k, v) => typeof v === 'bigint' ? v.toString() : v).slice(0, 600) : '')); } }; const listen = (port, fn) => http.createServer(async (q, r) => { let b = ''; for await (const c of q) b += c; try { await fn(q, r, b); } catch (e) { r.statusCode = 500; r.end(String(e.message)); } }).listen(port, '127.0.0.1').unref(); const H = 3600000, D = 86400000; const POOL = JSON.parse(fs.readFileSync(path.join(APP, 'qa', 'fixtures', 'pool.json'), 'utf8')).people; const pid = name => POOL.find(p => p.username === name).id; // ---- stand-in network hub (signed as fivex) ---- const HUB = { people: new Map(), down: false, badSig: 0, resolves: 0, got: [] }; function person(username, wallet, sponsorId, id) { id = id || 'h_' + crypto.createHash('sha1').update(username).digest('hex').slice(0, 16); HUB.people.set(id, { id, username, wallet: wallet ? wallet.toLowerCase() : null, sponsorId: sponsorId || null }); return id; } const hubView = p => { if (!p) return null; const sp = p.sponsorId && HUB.people.get(p.sponsorId); return { id: p.id, username: p.username, wallet: p.wallet, blocked: false, sponsor: sp ? { id: sp.id, username: sp.username } : null }; }; const HUB_PORT = PORT + 1; listen(HUB_PORT, async (q, r, b) => { r.setHeader('Content-Type', 'application/json'); if (q.method === 'GET' && q.url === '/v1/network-sites') return r.end('[]'); if (HUB.down) { r.statusCode = 503; return r.end('{"error":"down"}'); } 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'] !== 'fivex') { HUB.badSig++; r.statusCode = 401; return r.end('{}'); } const j = JSON.parse(b || '{}'); if (q.url === '/v1/resolve') { HUB.resolves++; const all = [...HUB.people.values()]; let p = null; if (j.id) p = HUB.people.get(j.id); else if (j.wallet) p = all.find(x => x.wallet === String(j.wallet).toLowerCase()); else if (j.ref) { const ref = String(j.ref).toLowerCase(); p = all.find(x => x.wallet === ref || x.username.toLowerCase() === ref); } return r.end(JSON.stringify({ person: hubView(p) })); } HUB.got.push({ route: q.url, body: j }); r.end('{"ok":true}'); }); // ---- stand-in Polygon JSON-RPC (DraftPosition): quoteWei at POL $0.25 ($10 = 40 POL), sponsorOf, contract facts, logs ---- const IFACE = new ethers.Interface(['event Purchase(uint256 indexed orderId, address indexed buyer, uint256 qty, uint256 ref, uint256 usdCents, uint256 weiPaid, uint256 levelsPaid, uint256 prizePaid, uint256 companyPaid)', 'event Paid(uint256 indexed orderId, address indexed to, uint256 amount, uint8 level, uint8 depth)', 'event PassedOver(uint256 indexed orderId, address indexed who, uint8 depth)', 'event SponsorBound(address indexed member, address indexed sponsor)', 'function quoteWei(uint256 qty) view returns (uint256)', 'function sponsorOf(address) view returns (address)', 'function buy(uint256 qty, uint256 ref, address[] line, uint256 deadline, bytes sig) payable returns (uint256)', 'function owner() view returns (address)', 'function company() view returns (address)', 'function prizeWallet() view returns (address)', 'function keeper() view returns (address)', 'function paused() view returns (bool)', 'function totalOwed() view returns (uint256)', 'function orderCount() view returns (uint256)', 'function priceCents() view returns (uint256)']); const CHAIN = { head: 1, logs: [], receipts: {}, bound: new Map(), replayAll: false, down: false, times: {} }; const CHAIN_PORT = PORT + 2; listen(CHAIN_PORT, async (q, r, b) => { const j = JSON.parse(b || '{}'); let result = null; r.setHeader('Content-Type', 'application/json'); if (CHAIN.down) return r.end(JSON.stringify({ jsonrpc: '2.0', id: j.id, error: { code: -1, message: 'down' } })); if (j.method === 'eth_blockNumber') result = '0x' + CHAIN.head.toString(16); if (j.method === 'eth_call') { const tx = IFACE.parseTransaction({ data: j.params[0].data }); const enc = (fn, v) => IFACE.encodeFunctionResult(fn, v); if (tx.name === 'quoteWei') result = enc('quoteWei', [1000n * tx.args[0] * 4n * 10n ** 16n]); if (tx.name === 'sponsorOf') result = enc('sponsorOf', [CHAIN.bound.get(tx.args[0].toLowerCase()) || ethers.ZeroAddress]); if (tx.name === 'owner' || tx.name === 'company') result = enc(tx.name, [TANGEM]); if (tx.name === 'prizeWallet') result = enc('prizeWallet', [PRIZE]); if (tx.name === 'keeper') result = enc('keeper', [KEEPER]); if (tx.name === 'paused') result = enc('paused', [false]); if (tx.name === 'totalOwed') result = enc('totalOwed', [0n]); if (tx.name === 'orderCount') result = enc('orderCount', [BigInt(CHAIN.logs.length)]); if (tx.name === 'priceCents') result = enc('priceCents', [1000n]); } if (j.method === 'eth_getBalance') result = '0x0'; 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_getBlockByNumber') { const n = j.params[0] === 'latest' ? CHAIN.head : parseInt(j.params[0], 16); result = { number: '0x' + n.toString(16), timestamp: '0x' + (CHAIN.times[n] || Math.floor(Date.now() / 1000)).toString(16), baseFeePerGas: '0x' + (30n * 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.end(JSON.stringify({ jsonrpc: '2.0', id: j.id, result })); }); // a position bought on the stand-in chain: Purchase log + a receipt with SponsorBound / PassedOver / Paid logs, like DraftPosition emits let orderId = 0; function chainBuy(o) { const id = ++orderId; const block = ++CHAIN.head; const tx = '0x' + crypto.randomBytes(32).toString('hex'); CHAIN.times[block] = o.blockAt || Math.floor(Date.now() / 1000); const qty = BigInt(o.qty || 1); const weiPaid = 1000n * qty * 4n * 10n ** 16n; const sp = weiPaid * 2500n / 10000n, lv = weiPaid * 500n / 10000n, pot = weiPaid / 10n; const mk = (name, args, li) => { const e = IFACE.encodeEventLog(name, args); return { address: SHOP.toLowerCase(), topics: e.topics, data: e.data, blockNumber: '0x' + block.toString(16), transactionHash: tx, logIndex: '0x' + li.toString(16), removed: false }; }; const logs = []; let li = 0; let lvl = 0n; for (const [m, s] of o.bound || []) { logs.push(mk('SponsorBound', [m, s], li++)); CHAIN.bound.set(m.toLowerCase(), s.toLowerCase()); } for (const [w, d] of o.over || []) logs.push(mk('PassedOver', [id, w, d], li++)); (o.pays || []).forEach(([w, d], i) => { const a = i === 0 ? sp : lv; lvl += a; logs.push(mk('Paid', [id, w, a, i + 1, d], li++)); }); logs.push(mk('Paid', [id, PRIZE, pot, 6, 0], li++)); const company = weiPaid - lvl - pot; logs.push(mk('Paid', [id, TANGEM, company, 0, 0], li++)); const purchase = mk('Purchase', [id, o.buyer, qty, o.ref || 0, 1000n * qty, weiPaid, (o.pays || []).length, pot, company], li++); logs.push(purchase); CHAIN.logs.push(purchase); CHAIN.receipts[tx] = { status: '0x1', blockNumber: '0x' + block.toString(16), to: SHOP.toLowerCase(), from: o.buyer.toLowerCase(), logs }; return { tx, id, weiPaid, sp, lv, pot, company }; } // ---- stand-in Telegram Bot API ---- const TG = []; const TG_PORT = PORT + 3; listen(TG_PORT, async (q, r, b) => { TG.push({ method: q.url.split('/').pop(), token: q.url.split('/')[1], body: JSON.parse(b || '{}') }); r.setHeader('Content-Type', 'application/json'); r.end('{"ok":true,"result":{}}'); }); const ENV = Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, ADMIN_TOKEN: ADMIN, NODE_ENV: 'development', DOCSTORE_URL: '', ALLOW_TEST_CLOCK: '1', TANK_MODE: 'stub', NETWORK_SSO_SECRET: SSO_SECRET, IAP_URL: 'https://iap.invalid', LS_URL: 'https://ls.invalid', NETWORK_SITES_HUB: '0', DRAFT_TICK_MS: '200', DRAFT_PICK_SECONDS: '300', CONTRACT_ADDRESS: SHOP, PRIZE_WALLET: PRIZE, CHAIN_RPC: 'http://127.0.0.1:' + CHAIN_PORT, KEEPER_KEY: KEEPER_PK, SHOP_START_BLOCK: '1', SHOP_CONFIRMATIONS: '0', SHOP_POLL_MS: '200', EXPLORER: 'https://explorer.invalid', HUB_ENABLED: '1', NETKB: '0', HUB_URL: 'http://127.0.0.1:' + HUB_PORT, HUB_SECRET, HUB_SITE: 'fivex', HUB_TICK_MS: '300', HUB_DOWN_MS: '300', HUB_CACHE_MS: '200', TG_LIVE: '1', TG_TOKEN: 'standin-token', TG_CHAT: '-100123', TG_PAY_TOPIC: '632242', TG_API: 'http://127.0.0.1:' + TG_PORT, OWNER_USERNAME: 'coachann' }); process.on('exit', () => { try { srv && srv.kill(); } catch (e) {} }); 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(() => ({}))); } }; } const admin = (p, body) => client().json(p, body, { 'x-admin-token': ADMIN }); async function boot(extraEnv) { const log = fs.openSync(path.join(OUT, 'server.log'), 'a'); srv = spawn(process.execPath, ['server.js'], { cwd: APP, env: Object.assign({}, ENV, extraEnv || {}), stdio: ['ignore', log, log] }); for (let i = 0; i < 80; i++) { try { const r = await fetch(BASE + '/health'); 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)]); } async function walletMember(o = {}) { const w = o.wallet || ethers.Wallet.createRandom(); const c = client(); const a = w.address.toLowerCase(); if (o.hub) c.hubId = person(o.hub.username, a, o.hub.sponsorId, o.hub.id); 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 = a; c.wallet = w; c.ok = v.ok === true && !!c.jar['fx.sid']; return c; } const until = async (fn, ms) => { const end = Date.now() + (ms || 8000); let v; while (Date.now() < end) { v = await fn(); if (v) return v; await sleep(150); } return v; }; const ctToMs = (day, hour) => { const [y, m, d] = day.split('-').map(Number); for (const off of [6, 5]) { const t = Date.UTC(y, m - 1, d, hour + off); const h = Number(new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago', hour: 'numeric', hour12: false })); if (h % 24 === hour) return t; } return Date.UTC(y, m - 1, d, hour + 6); }; const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/; async function main() { if (await fetch(BASE).then(() => true, () => false)) throw new Error('port ' + PORT + ' is already in use; set SMOKE_APP_PORT'); console.log('data dir', DATA); console.log('1. copy rules'); 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')]).concat(['promokit.js', 'proof.js', 'server.js', 'draft.js', 'league.js', 'tools/pages.mjs', 'tools/art.mjs'].map(f => [f, fs.readFileSync(path.join(APP, f), 'utf8')])); ok(texts.every(([, t]) => !/[\u2014\u2013]/.test(t)), 'no em or en dashes in any page, script or copy source', 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: "SafePal or any other crypto wallet"'); ok(!/passive income|guaranteed (income|returns|profit)|earn (cash|money)|make money|get rich|up to \$?\d+ (a|per)|maximum (you|earn)/i.test(html), 'no income promises and no earnings caps in page copy'); ok(/never a subscription/i.test(html) && /A position buys a draft spot and coaching tools, not income\. Nothing is promised\./.test(html), 'position copy: one-time, never a subscription; "not income. Nothing is promised."'); ok(/TrustClickz/.test(html) && /615 Green Valley Drive, Moody, AL 35004/.test(html), 'legal pages name TrustClickz, 615 Green Valley Drive, Moody, AL 35004'); ok(/never their email or any contact details/.test(html) && /never an email, phone number or any other contact details/i.test(html), 'copy: coaches get the right to sponsor and help, never contact data'); console.log('2. boot (prototype mode, stub tank, test clock)'); // the test clock starts on Sunday 2026-11-15 noon Central: last Monday's draft (11-09) is long past and skipped, never run late const SUN = ctToMs('2026-11-15', 12), MON = ctToMs('2026-11-16', 19); await boot(); let r0 = await admin('/api/admin/clock', { now: SUN }); ok(r0.ok, 'admin moves the test clock (ALLOW_TEST_CLOCK=1, never in production)', r0); await sleep(500); const cfg = await (await fetch(BASE + '/api/config')).json(); ok(cfg.position.usd === 10 && cfg.position.picksOnBuy === 5 && cfg.split.sponsorPct === 25 && cfg.split.levelPct === 5 && cfg.split.potPct === 10 && cfg.split.companyPct === 45 && cfg.tank === 'stub', 'config: $10 position, 5 picks, split 25/5x4/10/45, stub tank', cfg); ok(cfg.shop.live === true && cfg.draft.dow === 1 && cfg.draft.hour === 19 && cfg.draft.rounds === 5 && cfg.picks.returnDays === 3, 'shop live (stand-in); draft Monday 7 PM Central, 5 rounds; picks return after 3 days', cfg.draft); let st = await admin('/api/admin/status'); ok(st.draft === null || (st.draft && st.draft.made === 0), 'the app came up after last Monday\'s draft window: that draft is skipped, not run late', st.draft); console.log('3. pages'); const anon = client(); for (const p of ['/', '/team', '/cards', '/join', '/ledger', '/contract', '/promote', '/builder', '/terms', '/disclaimer', '/privacy', '/admin', '/robots.txt', '/sitemap.xml', '/art/og-share.png', '/art/icon-192.png', '/assets/fx.css', '/assets/common.js']) { const r = await anon.req(p); ok(r.status === 200, 'GET ' + p + ' 200', r.status); } let r = await anon.req('/team'); ok(r.headers.get('x-frame-options') === 'DENY', '/team is never framed'); r = await anon.req('/nobody-at-all'); ok(r.status === 404 && /Back to the draft board/.test(await r.text()), 'an unknown coach name: 404'); 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(/