One-tap switch on payouts after a holding-tank assignment + reminders (Marty approved 2026-10-27)
- Assignment chat + member email (manual adoption and the 24h auto-assign) carry "Switch on payouts" -> https://instantadpay.com/my?activate=1#wallet - /my?activate=1: signed in, wallet linked, real sponsor, no hold -> Wallet tab, explainer line, the Activate button's own flow (injected wallet or the WalletConnect picker on a phone). Survives sign-in and the wallet link (sessionStorage); never starts on tankHold, a blocked/routed sponsor or the #1 fallback (/api/me sponsorFallback) - payTick (in the 15-min readyTick): not activated 24h after the assignment -> ONE member email + ONE in-app notice to the sponsor; 72h -> last member email; stops on memberId / MemberActivated / sponsor change. State tank-ready.json `pay`, each send gated by marks.claim (deploy overlap), record saved before the send; Admin tank view gets payReminders - Chatbot: tank-activate-link canned answer + system prompt; my.js ?v=20261027pa - qa/tank-hold.mjs: link texts, reminder schedule on a mocked clock, overlap copy, ?activate=1 browser flows (stubbed wallet) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+131
-11
@@ -8,7 +8,8 @@
|
||||
// reaches LinkSpin): a tank account links a wallet -> /api/me + /api/sponsor answer tankHold with no fallback sponsor,
|
||||
// the Wallet tab hides Activate payouts and shows the hold text, the Getting started card has no activate button,
|
||||
// Admin tank shows the ready badge; a member who joined through a link is never held; a LinkSpin row naming a sponsor
|
||||
// aligns a tank member instead of holding them. Never production. Exit code 1 on any failure.
|
||||
// aligns a tank member instead of holding them; the one-tap /my?activate=1#wallet link (stubbed wallet) starts the Activate
|
||||
// flow only with a wallet, a real sponsor and no hold, and carries on after an on-page sign-in. Never production. Exit code 1 on any failure.
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
@@ -42,22 +43,25 @@ function fakeAccounts() {
|
||||
async sponsorOf(e) { const a = by.get(e); if (!a || !a.sponsorRef) return null; return (await this.byUsername(a.sponsorRef)) || (await this.byCode(a.sponsorRef)); }
|
||||
};
|
||||
}
|
||||
function bench() {
|
||||
function bench(o) {
|
||||
o = o || {};
|
||||
const tankPath = path.join(SITE, 'tank.js'); delete require.cache[require.resolve(tankPath)];
|
||||
const tank = require(tankPath);
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-tankhold-'));
|
||||
const accounts = fakeAccounts(); const events = []; const chats = []; const mails = []; const alerts = []; const assigned = []; const net = {};
|
||||
const dir = o.dir || fs.mkdtempSync(path.join(os.tmpdir(), 'iap-tankhold-'));
|
||||
const accounts = o.accounts || fakeAccounts(); const events = []; const chats = []; const mails = []; const alerts = []; const assigned = []; const net = {};
|
||||
const notices = []; const claims = o.claims || new Set(); const onChain = o.onChain || new Set();
|
||||
const blocked = new Set();
|
||||
const env = { now: Date.now() };
|
||||
const env = o.env || { now: Date.now() };
|
||||
tank.init({ dataDir: dir, accounts, chain: { recentEvents: () => events.slice().reverse(), getConfig: () => ({}) },
|
||||
messages: { sendChat: async (id, from, to, text) => { chats.push({ from, to, text }); }, lastFrom: async () => 0 },
|
||||
mailer: { hasKey: () => true, send: async (to, subject) => { mails.push({ to, subject }); } }, site: 'https://iap.test',
|
||||
mailer: { hasKey: () => true, send: async (to, subject, body) => { mails.push({ to, subject, body }); } }, site: 'https://iap.test',
|
||||
hooks: { network: e => net[e] || null, isSuspended: () => false, excluded: () => false, payoutBlocked: async id => blocked.has(id), companyId: () => 1,
|
||||
assigned: r => { assigned.push(r); }, adminAlert: t => { alerts.push(t); } } });
|
||||
assigned: r => { assigned.push(r); }, adminAlert: t => { alerts.push(t); },
|
||||
claim: k => { if (claims.has(k)) return false; claims.add(k); return true; }, activated: a => onChain.has(a.address), notify: async (to, subject, text) => { notices.push({ to, subject, text }); } } });
|
||||
tank.setClock(() => env.now);
|
||||
let block = 1000;
|
||||
const buyer = (email, memberId, o) => { const a = accounts.add(email, Object.assign({ memberId, address: '0x' + crypto.randomBytes(20).toString('hex'), lastSeen: env.now - H }, o || {})); events.push({ type: 'Purchase', buyerId: memberId, priceCents: 2000, block: block++ }); return a; };
|
||||
return { tank, accounts, events, chats, mails, alerts, assigned, net, blocked, env, buyer, dir };
|
||||
return { tank, accounts, events, chats, mails, alerts, assigned, net, blocked, env, buyer, dir, notices, claims, onChain };
|
||||
}
|
||||
async function partA() {
|
||||
console.log('-- Part A: tank.js with a mocked clock');
|
||||
@@ -94,6 +98,9 @@ async function partA() {
|
||||
ok(recs[0] && recs[0].note === 'auto-assigned after 24 hours in the tank' && recs[0].status === 'open', 'adoption record note', recs[0] && recs[0].note);
|
||||
ok(B.chats.some(c => c.from === 'a@x.co' && c.to === 'free@x.co'), 'sponsor chat opened');
|
||||
ok(B.mails.some(m => m.to === 'free@x.co') && B.mails.some(m => m.to === 'a@x.co' && /holding tank is now in your line/.test(m.subject)), 'both sides emailed');
|
||||
const LINK = 'https://iap.test/my?activate=1#wallet';
|
||||
ok(B.chats.some(c => c.to === 'free@x.co' && c.text.includes('Switch on payouts in one tap') && c.text.includes(LINK)), 'auto-assign chat carries the one-tap link');
|
||||
ok(B.mails.some(m => m.to === 'free@x.co' && m.body.includes('Switch on payouts: ' + LINK) && m.body.includes('locks @a in as your sponsor')), 'auto-assign member email carries the one-tap link');
|
||||
ok(B.assigned.length === 1, 'assigned hook fired (Telegram pickup line with "(auto-assigned)")');
|
||||
// second ready member: rotation moves to B (A was just auto-assigned)
|
||||
accounts.add('free2@x.co', { address: '0x' + 'c'.repeat(40) });
|
||||
@@ -124,6 +131,64 @@ async function partA() {
|
||||
const h5 = await tank.holdFor(f5);
|
||||
ok(h5 && h5.hold && h5.hold.until <= env.now, 'still held past the clock (client shows "Any minute now")');
|
||||
}
|
||||
{ // one-tap link + switch-on-payouts reminders (24 h member + sponsor, 72 h member only), mocked clock
|
||||
const B = bench(); const { tank, accounts, env } = B; const LINK = 'https://iap.test/my?activate=1#wallet';
|
||||
B.buyer('sp@x.co', 41);
|
||||
accounts.add('m1@x.co', { address: '0x' + '7'.repeat(40) }); accounts.add('m2@x.co'); accounts.add('m3@x.co', { address: '0x' + '8'.repeat(40) }); accounts.add('m4@x.co', { address: '0x' + '9'.repeat(40) });
|
||||
const r = await tank.adopt('sp@x.co', 'm1', 'Hey, I am your new sponsor.');
|
||||
ok(r && r.ok && !r.auto, 'manual adoption (setup)', JSON.stringify(r && r.error));
|
||||
const chat = B.chats.find(c => c.to === 'm1@x.co');
|
||||
ok(chat && chat.text === 'Hey, I am your new sponsor.\n\nSwitch on payouts in one tap (one free transaction, it locks me in as your sponsor): ' + LINK, 'manual adoption chat: own note + the one-tap line', chat && chat.text);
|
||||
const mail = B.mails.find(m => m.to === 'm1@x.co');
|
||||
ok(mail && mail.body.includes('Switch on payouts: ' + LINK) && !mail.body.includes('No wallet linked yet'), 'manual adoption email: link, no wallet sentence when linked');
|
||||
await tank.adopt('sp@x.co', 'm2'); // no wallet yet
|
||||
ok(B.mails.some(m => m.to === 'm2@x.co' && m.body.includes('No wallet linked yet? The same link shows you how')), 'no wallet: the email says the link walks them through linking');
|
||||
const t0 = env.now;
|
||||
env.now = t0 + 23 * H; let p = await tank.payTick();
|
||||
ok(p.sent.length === 0, 'no reminder before 24 h');
|
||||
accounts._by.get('m2@x.co').memberId = 51; // m2 switched on payouts: no reminder ever
|
||||
env.now = t0 + 24 * H + 60000; const mailsBefore = B.mails.length;
|
||||
p = await tank.payTick();
|
||||
const r1 = B.mails.slice(mailsBefore);
|
||||
ok(p.sent.length === 1 && p.sent[0].email === 'm1@x.co' && p.sent[0].stage === 1, '24 h: one reminder, only for the member still off', JSON.stringify(p.sent));
|
||||
ok(r1.length === 1 && r1[0].to === 'm1@x.co' && r1[0].subject === 'Reminder: switch on payouts with @sp on InstantAdPay' && r1[0].body.includes(LINK), '24 h member email: subject + one-tap link', r1[0] && r1[0].subject);
|
||||
ok(B.notices.length === 1 && B.notices[0].to === 'sp@x.co' && B.notices[0].subject === "@m1 hasn't switched on payouts yet" && B.notices[0].text.startsWith("@m1 hasn't switched on payouts yet; a nudge from you helps.") && B.notices[0].text.includes(LINK), '24 h sponsor notice', B.notices[0] && B.notices[0].text.slice(0, 80));
|
||||
ok(!r1.some(m => m.to === 'sp@x.co'), 'the sponsor gets a notice, not an email');
|
||||
await tank.payTick(); env.now += 15 * 60000; p = await tank.payTick();
|
||||
ok(p.sent.length === 0 && B.notices.length === 1, 'idempotent: later ticks send nothing more before 72 h');
|
||||
ok(tank.payView().find(x => x.email === 'm2@x.co').done === 'activated', 'activated member: record closed (activated)');
|
||||
env.now = t0 + 72 * H + 60000; const m72 = B.mails.length;
|
||||
p = await tank.payTick();
|
||||
ok(p.sent.length === 1 && p.sent[0].stage === 2 && B.mails.length === m72 + 1 && B.mails[m72].subject === 'Last reminder: switch on payouts with @sp on InstantAdPay' && B.mails[m72].body.includes(LINK), '72 h: the last reminder, member only', JSON.stringify(p.sent));
|
||||
ok(B.notices.length === 1, '72 h: no second sponsor notice');
|
||||
env.now += 24 * H; p = await tank.payTick();
|
||||
ok(p.sent.length === 0 && tank.payView().find(x => x.email === 'm1@x.co').done === 'reminded', 'after 72 h: done, nothing more');
|
||||
ok(!/—/.test(B.chats.map(c => c.text).join(' ') + B.mails.map(m => m.subject + m.body).join(' ') + B.notices.map(n => n.subject + n.text).join(' ')), 'no em dashes in member texts');
|
||||
// m3 activated on chain (MemberActivated) before the account has a memberId; m4 moved away before 24 h: both stop
|
||||
B.buyer('sp2@x.co', 42);
|
||||
const r3 = await tank.adopt('sp2@x.co', 'm3'); ok(r3 && r3.ok, 'second sponsor adopts m3 (setup)', JSON.stringify(r3 && r3.error));
|
||||
const r4 = await tank.adopt('sp2@x.co', 'm4'); ok(r4 && r4.ok, 'second sponsor adopts m4 (setup)', JSON.stringify(r4 && r4.error));
|
||||
const t3 = env.now; B.onChain.add(accounts._by.get('m3@x.co').address);
|
||||
accounts._by.get('m4@x.co').sponsorRef = '';
|
||||
env.now = t3 + 25 * H; p = await tank.payTick();
|
||||
ok(p.sent.length === 0, 'activated on chain / sponsor changed: no reminder', JSON.stringify(p.sent));
|
||||
const pv = tank.payView();
|
||||
ok(pv.find(x => x.email === 'm3@x.co').done === 'activated' && pv.find(x => x.email === 'm4@x.co').done === 'moved', 'records closed as activated / moved');
|
||||
ok((await tank.adminView()).payReminders.length >= 4, 'adminView lists the reminder records');
|
||||
}
|
||||
{ // deploy overlap: a second app copy with a stale tank-ready.json and the shared claim table sends nothing twice
|
||||
const accounts = fakeAccounts(); const claims = new Set(); const env = { now: Date.now() };
|
||||
const A = bench({ accounts, claims, env });
|
||||
A.buyer('ov@x.co', 61); accounts.add('ovm@x.co', { address: '0x' + '6'.repeat(40) });
|
||||
await A.tank.adopt('ov@x.co', 'ovm');
|
||||
const stale = fs.readFileSync(path.join(A.dir, 'tank-ready.json'), 'utf8');
|
||||
env.now += 25 * H;
|
||||
const pa = await A.tank.payTick();
|
||||
const dir2 = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-tankhold-ov-')); fs.writeFileSync(path.join(dir2, 'tank-ready.json'), stale);
|
||||
const Bc = bench({ accounts, claims, env, dir: dir2 }); // copy B: same accounts + claims, stale state
|
||||
const pb = await Bc.tank.payTick();
|
||||
ok(pa.sent.length === 1 && pb.sent.length === 0 && Bc.mails.length === 0 && Bc.notices.length === 0, 'overlap: copy A sends the 24 h reminder, stale copy B sends nothing', JSON.stringify({ a: pa.sent.length, b: pb.sent.length }));
|
||||
}
|
||||
{ // own-downline adopter skipped
|
||||
const B = bench(); const { tank, accounts, env } = B;
|
||||
accounts.add('top@x.co', { address: '0x' + '1'.repeat(40) });
|
||||
@@ -173,9 +238,10 @@ async function partB() {
|
||||
const api = async (p, body, hdr) => { const r = await fetch(BASE + p, body ? { method: body.method || 'POST', headers: Object.assign({ 'Content-Type': 'application/json' }, hdr || {}), body: JSON.stringify(body.data || body) } : { headers: hdr || {} }); let j = null; try { j = await r.json(); } catch (e) {} return { status: r.status, j }; };
|
||||
const adminH = { Authorization: 'Bearer ' + ADMIN };
|
||||
await api('/api/admin/site', { method: 'PATCH', data: { fraudMaxSignupsPerIpDay: 20 } }, adminH);
|
||||
async function signIn(email, username, extraCookie) {
|
||||
const s = await api('/api/auth/email/start', { email, fts: Date.now() - 5000 }, extraCookie ? { Cookie: extraCookie } : null);
|
||||
const v = await fetch(BASE + '/api/auth/email/verify', { method: 'POST', headers: Object.assign({ 'Content-Type': 'application/json' }, extraCookie ? { Cookie: extraCookie } : {}), body: JSON.stringify({ email, code: s.j && s.j.devCode }) });
|
||||
async function signIn(email, username, extraCookie, ip) { // ip: X-Forwarded-For of its own (the code guard allows 5 sends per IP per 10 min)
|
||||
const xf = ip ? { 'X-Forwarded-For': ip } : {};
|
||||
const s = await api('/api/auth/email/start', { email, fts: Date.now() - 5000 }, Object.assign({}, xf, extraCookie ? { Cookie: extraCookie } : {}));
|
||||
const v = await fetch(BASE + '/api/auth/email/verify', { method: 'POST', headers: Object.assign({ 'Content-Type': 'application/json' }, xf, extraCookie ? { Cookie: extraCookie } : {}), body: JSON.stringify({ email, code: s.j && s.j.devCode }) });
|
||||
const cookie = (v.headers.getSetCookie ? v.headers.getSetCookie() : [v.headers.get('set-cookie')]).map(c => String(c).split(';')[0]).filter(c => /^iap\./.test(c) || c.includes('=')).join('; ');
|
||||
if (username) await api('/api/my/profile', { username }, { Cookie: cookie });
|
||||
return cookie;
|
||||
@@ -234,6 +300,60 @@ async function partB() {
|
||||
ok(/Matching you with a sponsor/.test(st.gs) && !st.gsBtn, 'Getting started: hold text, no activate button', st.gs.slice(0, 120));
|
||||
await page.screenshot({ path: path.join(SITE, 'qa/out/tank-hold-wallet.png') }).catch(() => {});
|
||||
ok(!errs.length, 'no page errors', errs.join(' | ').slice(0, 200));
|
||||
// 5. one-tap link /my?activate=1#wallet (2026-10-27): IAPWallet.activate is stubbed in the page (records the sponsor id,
|
||||
// never reaches a wallet); it must start only for a signed-in member with a wallet, a real sponsor and no hold
|
||||
const STUB = () => { window.__act = []; let real; Object.defineProperty(window, 'IAPWallet', { configurable: true, get() { return real; },
|
||||
set(v) { if (v && v.activate) v.activate = async id => { window.__act.push(id); throw new Error('qa: activation stub'); }; real = v; } });
|
||||
try { sessionStorage.setItem('iap.welcome.v1', '1'); } catch (e) {} };
|
||||
async function actCtx(cookie, ip) { // ip: its own address for the on-page sign-in (the code guard allows 5 sends per IP per 10 min)
|
||||
const c = await browser.newContext(Object.assign({ viewport: { width: 390, height: 844 } }, ip ? { extraHTTPHeaders: { 'X-Forwarded-For': ip } } : {})); await c.addInitScript(STUB);
|
||||
if (cookie) await c.addCookies(cookie.split('; ').filter(Boolean).map(x => { const i = x.indexOf('='); return { name: x.slice(0, i), value: x.slice(i + 1), url: BASE }; }));
|
||||
const pg = await c.newPage(); pg.on('pageerror', e => errs.push(e.message)); return { c, pg };
|
||||
}
|
||||
const actState = pg => pg.evaluate(() => { const n = document.getElementById('actIntentNote'); return { act: window.__act, note: n && !n.hidden ? n.textContent : null, url: location.pathname + location.search + location.hash, hold: (document.getElementById('tankHoldNote') || {}).hidden === false }; });
|
||||
{ // held tank member: never triggers, the param is dropped, the hold text shows
|
||||
const { c, pg } = await actCtx(tc); await pg.goto(BASE + '/my?activate=1#wallet', { waitUntil: 'load' }); await pg.waitForTimeout(4000);
|
||||
const s1 = await actState(pg);
|
||||
ok(s1.act.length === 0 && !s1.note && s1.hold && !/activate=1/.test(s1.url), '?activate=1 on a held tank member: no activation, hold text, param dropped', JSON.stringify(s1));
|
||||
await c.close();
|
||||
}
|
||||
{ // sponsor link to a member who never switched on payouts (walk-up / routed): no real sponsor, never triggers
|
||||
ok(me2 && me2.sponsorRouted, 'setup: the link-joined member routes past an unactivated sponsor', JSON.stringify(me2 && me2.sponsorRouted));
|
||||
const { c, pg } = await actCtx(jc); await pg.goto(BASE + '/my?activate=1#wallet', { waitUntil: 'load' }); await pg.waitForTimeout(4000);
|
||||
const s2 = await actState(pg);
|
||||
ok(s2.act.length === 0 && !s2.note, '?activate=1 when no real sponsor resolves: no activation', JSON.stringify(s2));
|
||||
await c.close();
|
||||
}
|
||||
// a member with a real sponsor (#21) and a wallet: the Activate flow starts at once with #21
|
||||
const pc = await signIn('qa-pay@example.com', 'qapayone', 'iap.sponsor=21', '10.78.0.1'); await linkWallet(pc);
|
||||
const mp = (await api('/api/me', null, { Cookie: pc })).j;
|
||||
ok(mp && mp.sponsorId === 21 && !mp.sponsorFallback && !mp.tankHold && !mp.memberId, 'setup: sponsored member, sponsor #21 resolves', JSON.stringify({ id: mp && mp.sponsorId, f: mp && mp.sponsorFallback }));
|
||||
{ const { c, pg } = await actCtx(pc); await pg.goto(BASE + '/my?activate=1#wallet', { waitUntil: 'load' }); await pg.waitForTimeout(4500);
|
||||
const s3 = await actState(pg);
|
||||
ok(s3.act.length === 1 && s3.act[0] === 21, '?activate=1: the Activate flow starts once with the sponsor prefilled (#21)', JSON.stringify(s3));
|
||||
ok(s3.note === 'One free transaction switches on your payouts and locks member #21 in as your sponsor. Confirm it in your wallet.', 'explainer line above the Activate button', s3.note);
|
||||
ok(/#wallet$/.test(s3.url) && !/activate=1/.test(s3.url), 'Wallet tab open, param consumed', s3.url);
|
||||
await pg.reload({ waitUntil: 'load' }); await pg.waitForTimeout(3500);
|
||||
ok((await actState(pg)).act.length === 0, 'a reload does not start it again');
|
||||
await pg.screenshot({ path: path.join(SITE, 'qa/out/tank-activate-link.png') }).catch(() => {});
|
||||
await c.close(); }
|
||||
{ // signed out: sign in on the page, then the same flow carries on
|
||||
const c2 = await signIn('qa-pay2@example.com', 'qapaytwo', 'iap.sponsor=21', '10.78.0.2'); await linkWallet(c2);
|
||||
const { c, pg } = await actCtx(null, '10.77.' + (1 + Math.floor(Math.random() * 250)) + '.9'); await pg.goto(BASE + '/my?activate=1#wallet', { waitUntil: 'load' }); await pg.waitForTimeout(4000);
|
||||
ok((await actState(pg)).act.length === 0, 'signed out: nothing starts before sign-in');
|
||||
await pg.fill('#mcEmail', 'qa-pay2@example.com'); await pg.click('#mcSendBtn');
|
||||
await pg.waitForFunction(() => (document.getElementById('mcCode') || {}).value, null, { timeout: 15000 }).catch(() => {});
|
||||
await pg.click('#mcVerifyBtn'); await pg.waitForTimeout(5000);
|
||||
const s4 = await actState(pg);
|
||||
ok(s4.act.length === 1 && s4.act[0] === 21, 'signed out -> sign in -> the Activate flow continues with #21', JSON.stringify(s4));
|
||||
await c.close(); }
|
||||
{ // sponsored, no wallet yet: link first (note), nothing starts; the intent waits for the link
|
||||
const c3 = await signIn('qa-pay3@example.com', 'qapaythree', 'iap.sponsor=21', '10.78.0.3');
|
||||
const { c, pg } = await actCtx(c3); await pg.goto(BASE + '/my?activate=1#wallet', { waitUntil: 'load' }); await pg.waitForTimeout(4000);
|
||||
const s5 = await actState(pg);
|
||||
ok(s5.act.length === 0 && s5.note === 'Step 1: link your wallet (one free signature). Then switching on payouts with member #21 starts by itself.', 'no wallet yet: asks to link first, nothing starts', JSON.stringify(s5));
|
||||
await c.close(); }
|
||||
ok(!errs.length, 'no page errors (one-tap link pages)', errs.join(' | ').slice(0, 200));
|
||||
} finally {
|
||||
if (browser) await browser.close().catch(() => {});
|
||||
try { srv.kill(); } catch (e) {}
|
||||
|
||||
Reference in New Issue
Block a user