Files
linkspin/qa/carry-activate.test.cjs
T
martbost 2d0413037d Holding tank on LinkSpin (ported from InstantAdPay 4645d56, Marty 2026-10-27): network sponsor ALIGNMENT first, the free activation held (never a purchase), 24-hour rotation, payouts switched on the moment someone is assigned
- Align first, every path (/api/me, /api/sponsor all intents incl. buy, carry.ensureOnChain via tank.gate, 15-min readyTick): a tank member (no sponsorRef, no member number, no resolvable cookie) whose email has a sponsor in the InstantAdPay registry rows, else a signed sponsor-facts call (3 s timeout, 10 min cache, one batch per tick), else the same wallet, is placed under that sponsor through accounts.setSponsorRef when the sponsor has a LinkSpin account; never a sponsor they were adopted/released/rescued away from, never a loop. Recorded in tank-ready.json, listed in Admin tank
- Hold ONLY the plain Switch on payouts (Marty: "I would never want to hold up a purchase ... they'll just pay number one"): the engine's wallet-link activation and seeding wait, /api/sponsor?intent=activate answers sponsorBlocked tankHold; intent=buy and /api/me never block (buys go ahead under #1 as before). A sponsor activated because someone below is buying is never held. Activate buttons now call intent=activate
- Ready badge + hours left (My line tank, Admin tank, Overview count); one shared-payments-topic line per newly ready member (digest when more than 3)
- 24-hour rotation through adopt(): own $25+ buy, fewer than 2 open, seen within 7 days, not company/#1, not a no-payout chain, not own downline; least recently auto-assigned first. Nobody eligible: keep holding, one admin alert. Never #1
- Payouts on at assignment (Marty approved 2026-10-27): adopted, auto-assigned or aligned member with a wallet is activated right away by carry.activateAssigned (strict: sponsor must be on the contract and not on a no-payout chain, never the fallback; retried every tick for 7 days); the auto-assign chat/email say "Your payouts are now on under @sponsor" with the Polygonscan link, a manual adoption gets a follow-up chat + email
- Deploy overlap: marks.js claims for the activation (per member per 10 min), the auto-assign, the ready post and the admin alert
- Cross-site: someone waiting in InstantAdPay's own tank (claimed account there, no sponsor, not a member there, wallet linked) is auto-assigned by InstantAdPay only (live sponsor-facts, registry fallback); LinkSpin defers and does not post them
- Chatbot: tank-hold canned answer, holding-tank answer + facts, KNOWLEDGE_DATE 2026-10-27; cache tags my.js / credits-screen.js / admin.js 20261027th
- QA: qa/tank-hold.test.mjs (unit with mocked clock + fake engine, then a local copy with a mock InstantAdPay and a browser check of Credits), qa/carry-activate.test.cjs (regression for the 10-22 scoping bug), run.sh tankhold + sponsorfollow; run.sh borrows InstantAdPay's node_modules when this checkout has none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 07:26:51 -05:00

29 lines
2.2 KiB
JavaScript

// carry.ensureOnChain after the send (regression, 2026-10-27): txHash / lastErr were declared inside the try block and read
// after its finally, so EVERY engine activation threw "txHash is not defined" once the tx was mined (memberId not saved, no
// notice, in-flight flag stuck, and a buyer whose sponsor needed activating fell back to #1 in /api/sponsor?intent=buy).
// No real chain: the RPC is a dead local port (the send fails at once) and the stub chain then reports the member as on-chain,
// the same "mined although the follow-up read failed" path as the 2026-10-15 seed. node qa/carry-activate.test.cjs
'use strict';
const assert = require('assert');
const os = require('os');
const fs = require('fs');
const path = require('path');
process.env.ENGINE_KEY = '0x' + '11'.repeat(32); // throwaway key, never funded; the RPC below is unreachable
const carry = require(path.join(__dirname, '..', 'carry.js'));
(async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ls-carry-act-'));
let sent = false; const saved = [];
const acct = { email: 'm@x.co', address: '0x' + '2'.repeat(40), sponsorRef: '', memberId: 0 };
carry.init({ dataDir: dir, siteConfig: () => ({ defaultSponsorId: 1, carryNotices: '0' }),
accounts: { byEmail: async () => Object.assign({}, acct), setMemberId: async (e, id) => { saved.push([e, id]); } },
chain: { getConfig: () => ({ rpc: 'http://127.0.0.1:1', rpcs: ['http://127.0.0.1:1'], chainId: 137, contract: '0x' + '3'.repeat(40) }),
memberCount: async () => 50, memberIdByAccount: async () => { if (!sent) { sent = true; return 0; } return 77; } } });
const id = await carry.ensureOnChain(acct, 0, 'wallet');
assert.strictEqual(id, 77, 'returns the member number instead of throwing');
assert.deepStrictEqual(saved, [['m@x.co', 77]], 'member number saved on the account');
assert.ok(!carry.isBinding('m@x.co'), 'in-flight flag cleared');
const log = carry.status().log; assert.ok(log.some(e => e.type === 'activated' && e.id === 77), 'activation logged');
console.log('carry-activate: ok');
fs.rmSync(dir, { recursive: true, force: true });
})().catch(e => { console.error('carry-activate: FAIL', e.message); process.exit(1); });