VBB purchases live + weekly prize payouts (Marty 2026-11-14: "why does it say 'coming soon' on all the stuff in it? Shouldn't it all be live already?")
Buying (VBBShop 0x36F6...07D7): Packages page has live Buy buttons for the 10 and 40 credit packs (USD price + live POL from quoteWei, SafePal or any other crypto wallet, one-time, never a subscription, where the payment goes); My Banners has "Add the banner look ($2)" on each waiting or in-loop banner (SKU 3, ref = banner id) and a 40-character teaser editor once it has the look. POST /api/my/order builds the member's buy() call on the server (fresh keeper voucher when the hub knows their sponsor, else no sponsor); the page checks the connected wallet is the member's VBB account (explains how to switch if not), checks the balance, sends with Polygon's fee floor (/api/gas), waits on /api/tx, nudges the watcher (/api/my/paid) and polls until the credits or the look arrive. Public: /api/quote, /api/gas, /api/tx/<hash>; /api/config has shop {live, contract} + explorer. The banner look on the loop: double border + star, hover teaser (always shown on touch screens; default = the link's site). Only Tokens still says coming soon. wallet.js gains sendTx/waitTx/balance (DLB flow).
Weekly prize payouts (prize.js): each Central-time week's pot = 10% of its VBBShop sales (usdCents of Purchase events by block time), $20 floor (company top-up shown to admin), $50 cap internal, half per board, 50/30/20. Every Monday the app prepares last week's plan (winners, wallets, USD; POL quoted live from the Chainlink feed the contract uses). /admin "Approve and pay" (two clicks): refuses unless PRIZE_KEY is the contract's prizeWallet(), the feed is fresh and the wallet holds the POL + gas (says how much more to send); then once per week (docstore.claim in MySQL + plan status), consecutive nonces, each hash saved as sent, stops at the first unclear send (never auto-retried), receipts watched. Ties: earlier to reach the count wins (leaderboards use the same rule). A winner that cannot be paid (the prize or company wallet) is skipped and the rest move up; an unfilled place stays in the prize wallet. /leaders shows past winners with transaction links. Posts nothing anywhere. Compose passes PRIZE_KEY.
Tests: smoke 192/192 (stand-in chain answers quoteWei + receipts: quote, order calldata + voucher, look purchase, teaser, prizes API, UI Buy buttons). New qa/chain.mjs on a local anvil with the real VBBShop + mock feed: buy -> Purchase -> credits, voucher binds sponsor, 30/10/60 split, overpay refunded, banner look; prize prepare -> short refusal -> pay 6 transfers exact POL -> paid once: 29/29. common.js?v=3, vbb.css?v=4.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+68
-7
@@ -30,10 +30,16 @@ require('node:http').createServer((q, r) => { const a = (new URL(q.url, 'http://
|
||||
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 }; const CHAIN_PORT = PORT + 2;
|
||||
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
|
||||
@@ -140,7 +146,7 @@ async function main() {
|
||||
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},{"credits":40,"usd":10}]' && cfg.lookUsd === 2 && cfg.freeCreditsPerDay === 1, 'approved defaults: packs 10 for $3 + 40 for $10, look $2, 1 free credit a day', cfg);
|
||||
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);
|
||||
|
||||
@@ -369,16 +375,65 @@ async function main() {
|
||||
// restart: the dedupe marks survive, the replaying RPC still credits nothing
|
||||
await sleep(1200); await stop(); await boot(); await sleep(900);
|
||||
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)');
|
||||
const cfgNow = await (await fetch(BASE + '/api/config')).json(); ok(cfgNow.shop && cfgNow.shop.live === true && cfgNow.shop.contract === ethers.getAddress(SHOP), 'public config offers the shop (purchases live)', cfgNow.shop);
|
||||
|
||||
// ---- 12a. buying: quote, the member's buy() call, the banner look, the teaser ----
|
||||
console.log('12a. buying: quote, order, banner look, teaser');
|
||||
const BUY_IF = new ethers.Interface(['function buy(uint256 sku, uint256 qty, uint256 ref, address sponsor, uint256 deadline, bytes sig) payable returns (uint256)']);
|
||||
let qt = await anon.json('/api/quote?sku=1&qty=1');
|
||||
ok(qt._status === 200 && qt.wei === (300n * 4n * 10n ** 16n).toString() && qt.sendWei === (BigInt(qt.wei) + BigInt(qt.wei) / 100n).toString() && qt.usd === 3, 'quote: quoteWei from the contract, +1% to send, $3', qt);
|
||||
qt = await anon.json('/api/quote?sku=9&qty=1'); ok(qt._status === 400, 'quote: unknown package refused');
|
||||
qt = await anon.json('/api/quote?sku=3&qty=2'); ok(qt._status === 400, 'quote: one banner look at a time');
|
||||
r = await anon.req('/api/my/order', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{"sku":1}' }); ok(r.status === 401, 'order needs sign-in');
|
||||
let od = await V.json('/api/my/order', { sku: 2, qty: 1 });
|
||||
let dec = od.data ? BUY_IF.decodeFunctionData('buy', od.data) : null;
|
||||
ok(od._status === 200 && od.to === ethers.getAddress(SHOP) && od.buyer === V.address && BigInt(od.value) === BigInt(od.sendWei) && od.sponsor === true && dec && Number(dec[0]) === 2 && Number(dec[1]) === 1 && Number(dec[2]) === 0 && dec[3].toLowerCase() === spW,
|
||||
'order: buy(2, 1, 0, sponsor, deadline, sig) for the member, with the hub sponsor', od);
|
||||
ok(dec && ethers.verifyTypedData(vdom, vt, { buyer: ethers.getAddress(V.address), sponsor: dec[3], deadline: dec[4] }, dec[5]) === keeperAddr, 'order: the voucher inside the call is the keeper\'s EIP-712 signature');
|
||||
od = await A.json('/api/my/order', { sku: 1, qty: 1 }); dec = od.data ? BUY_IF.decodeFunctionData('buy', od.data) : null;
|
||||
ok(od._status === 200 && od.sponsor === false && od.why === 'no-sponsor' && dec && dec[3] === ethers.ZeroAddress && dec[5] === '0x', 'order: no network sponsor = buy without a voucher (zero sponsor, empty sig)', od);
|
||||
od = await V.json('/api/my/order', { sku: 1, qty: 11 }); ok(od._status === 400, 'order: at most 10 packs');
|
||||
// banner look: V posts a banner, orders the look for it; a stranger's banner and a cycled banner are refused
|
||||
const vb = await postBanner(V, 7); const vbId = vb.banner && vb.banner.id;
|
||||
od = await V.json('/api/my/order', { sku: 3, ref: vbId }); dec = od.data ? BUY_IF.decodeFunctionData('buy', od.data) : null;
|
||||
ok(od._status === 200 && dec && Number(dec[0]) === 3 && Number(dec[2]) === vbId && od.usd === 2, 'order: banner look = buy(3, 1, banner id)', od);
|
||||
od = await A.json('/api/my/order', { sku: 3, ref: vbId }); ok(od._status === 400 && /not yours/.test(od.error), 'order: a look for someone else\'s banner is refused', od);
|
||||
r = await V.json('/api/my/banners/' + vbId + '/teaser', { teaser: 'Hello' }); ok(r._status === 400, 'teaser needs the look first', r);
|
||||
CHAIN.replayAll = false;
|
||||
CHAIN.logs.push(mkLog({ orderId: 3, buyer: V.address, sku: 3, qty: 1, ref: vbId, credits: 0, usdCents: 200, wei: 8n * 10n ** 18n, sponsor: spW, sponsorPaid: 24n * 10n ** 17n, block: 14, tx: '0x' + 'ef'.repeat(32), logIndex: 1 }));
|
||||
CHAIN.head = 15; await sleep(900);
|
||||
my = await V.json('/api/my'); const lkb = (my.banners || []).find(x => x.id === vbId);
|
||||
ok(lkb && lkb.look === true && lkb.teaser === "" && lkb.teaserDefault === "example-member.com", "a banner-look Purchase gives that banner the look", lkb);
|
||||
od = await V.json('/api/my/order', { sku: 3, ref: vbId }); ok(od._status === 400 && /already/.test(od.error), 'order: a second look for the same banner is refused', od);
|
||||
let spl = await anon.json('/api/splash'); let lt = [...spl.loop, ...spl.queue].find(x => x.id === vbId);
|
||||
ok(lt && lt.look === true && lt.teaser === 'example-member.com', 'the loop shows the look, teaser = the link\'s site until the member writes one', lt);
|
||||
r = await V.json('/api/my/banners/' + vbId + '/teaser', { teaser: ' Free <b>traffic</b> tools\n inside ' });
|
||||
ok(r.ok && r.teaser === 'Free btraffic/b tools inside', 'teaser saved as plain text (no tags, one line)', r);
|
||||
r = await V.json('/api/my/banners/' + vbId + '/teaser', { teaser: 'x'.repeat(41) }); ok(r._status === 400, 'teaser: 40 characters at most');
|
||||
r = await A.json('/api/my/banners/' + vbId + '/teaser', { teaser: 'mine now' }); ok(r._status === 404, 'teaser: only the owner');
|
||||
spl = await anon.json('/api/splash'); lt = [...spl.loop, ...spl.queue].find(x => x.id === vbId); ok(lt && lt.teaser === 'Free btraffic/b tools inside', 'the loop shows the member\'s teaser', lt);
|
||||
CHAIN.receipts['0x' + '12'.repeat(32)] = { status: '0x1', blockNumber: '0xe', to: SHOP, from: V.address };
|
||||
r = await anon.json('/api/tx/0x' + '12'.repeat(32)); ok(r.found === true && r.status === '0x1', '/api/tx answers a receipt', r);
|
||||
r = await anon.json('/api/tx/0x' + '34'.repeat(32)); ok(r.found === false, '/api/tx: not mined yet = found false');
|
||||
r = await anon.json('/api/gas'); ok(BigInt(r.maxPriorityFeePerGas || 0) >= 30n * 10n ** 9n, 'gas: at least the 30 gwei Polygon tip floor', r);
|
||||
r = await V.json('/api/my/paid', {}); ok(r.ok === true, 'paid nudge answers');
|
||||
// this week's pot now counts the sales: 600 + 1000 + 200 cents = $18, 10% = $1.80, so still the $20 floor
|
||||
const pzn = await anon.json('/api/prizes'); ok(pzn.current && pzn.current.pot === 20 && pzn.current.atFloor === true && Array.isArray(pzn.past) && pzn.past.length === 0, 'prizes: this week at the $20 floor, no past winners yet', pzn);
|
||||
const apz = await anon.json('/api/admin/prizes', undefined, { 'x-admin-token': ADMIN });
|
||||
ok(apz.current && apz.current.salesUsd === 18 && apz.current.purchases === 3 && apz.current.shareUsd === 1.8 && apz.current.topUpUsd === 18.2 && apz.prize && apz.prize.keyOn === false, 'admin prizes: week sales $18 from 3 purchases, 10% $1.80, top-up $18.20, no prize key here', apz.current);
|
||||
r = await anon.json('/api/admin/prizes/prepare', { week: apz.week }, { 'x-admin-token': ADMIN }); ok(r._status === 400 && /not finished/.test(r.error), 'prizes: the current week cannot be prepared', r);
|
||||
r = await anon.json('/api/admin/prizes/pay', { week: apz.lastWeek }, { 'x-admin-token': ADMIN }); ok(r._status === 400 && /confirm/.test(r.error), 'prizes: paying needs {week, confirm: week}', r);
|
||||
r = await anon.json('/api/admin/prizes/pay', { week: apz.lastWeek, confirm: apz.lastWeek }, { 'x-admin-token': ADMIN }); ok(r._status === 400 && !r.ok, 'prizes: without a prepared plan with winners (and without PRIZE_KEY) nothing is paid', r);
|
||||
r = await anon.json('/api/admin/prizes/pay', { week: apz.lastWeek, confirm: apz.lastWeek }); ok(r._status === 401, 'prizes: paying needs the admin token');
|
||||
|
||||
// ---- 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);
|
||||
ok(spends.length === 2 && spends[0].body.wallet === V.address && spends[0].body.cents === 1000 && spends[1].body.cents === 200, 'hub: later purchases are contract-spends (1000 cents, then the 200-cent banner look)', 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);
|
||||
ok(adh.hub && adh.hub.enabled && adh.hub.sent === 3 && adh.hub.site === 'vbb' && !JSON.stringify(adh).includes(HUB_SECRET), 'admin status shows the hub report (3 sent), never the secret', adh.hub);
|
||||
|
||||
// ---- 12c. old site links + health ----
|
||||
console.log('12c. old site links + health');
|
||||
@@ -425,8 +480,14 @@ async function main() {
|
||||
ok(/1st: \$5 in POL/.test(await pg.textContent('#pz')) && /at least \$20, and it grows with sales/.test(await pg.textContent('#prizes')) && !/50/.test(await pg.textContent('#prizes')), name + ': leaderboard page shows the pot, never the cap');
|
||||
await pg.goto(BASE + '/packages', { waitUntil: 'domcontentloaded' }); await pg.waitForTimeout(400);
|
||||
const pk = await pg.textContent('#pk');
|
||||
ok(/10 post credits for \$3/.test(pk) && /40 post credits for \$10/.test(pk) && /\$2 per banner/.test(pk) && /Coming soon/i.test(pk), name + ': packages page shows the planned prices as coming soon', pk.slice(0, 200));
|
||||
ok(!(await pg.$('#pk button, #pk form')), name + ': no purchase controls on the packages page');
|
||||
await pg.waitForFunction(() => /POL right now/.test(document.getElementById('pk').textContent), null, { timeout: 6000 }).catch(() => {});
|
||||
const pkt = await pg.textContent('#pk');
|
||||
ok(/10 post credits/.test(pkt) && /\$3/.test(pkt) && /40 post credits/.test(pkt) && /\$10/.test(pkt) && /\$2 per banner/.test(pkt) && /about 12\.00 POL right now/.test(pkt) && /about 40\.00 POL right now/.test(pkt), name + ': packages page shows USD prices and the live POL price', pkt.slice(0, 300));
|
||||
const buys = await pg.$$eval('#pk button[data-pk=buy]', els => els.map(b => [b.textContent, b.disabled]));
|
||||
ok(buys.length === 2 && buys[0][0] === 'Buy 10 credits' && buys[1][0] === 'Buy 40 credits' && buys.every(b => !b[1]), name + ': two live Buy buttons', buys);
|
||||
const soon = (await pg.textContent('main')).match(/coming soon/gi) || [];
|
||||
ok(soon.length === 1 && /Tokens[\s\S]*Coming soon/i.test(pkt), name + ': only Tokens still says coming soon', soon.length);
|
||||
ok(/SafePal or any other crypto wallet/.test(await pg.textContent('main')) && /Never a subscription/i.test(await pg.textContent('main')), name + ': packages copy: SafePal or any other crypto wallet, never a subscription');
|
||||
await pg.screenshot({ path: path.join(OUT, 'packages-' + name + '.png'), fullPage: true });
|
||||
// My Banners, signed in as the network member (cookie copied from the HTTP client)
|
||||
await ctx.addCookies([{ name: 'vbb.sid', value: L.jar['vbb.sid'], url: BASE }]);
|
||||
|
||||
Reference in New Issue
Block a user