Files
linkspin/qa/carry-hold.test.cjs
T
martbost a5c2c38106 Sponsor follow + one network holding tank + Sponsor check (Marty, 2026-10-22, approved 1-3)
Same design as InstantAdPay (shared sponsorfollow.js). Deliberate sponsor changes (tank adoption, rescue, release,
adoption window ending, admin edit) are recorded and travel on the iapsync rows; InstantAdPay's deliberate changes are
applied here only when the member is not bound or binding on the LinkSpin contract (memberId, wallet on chain, or an
engine activation in flight), newer than our own, and both sides agreed before (or no sponsor here). Bound / diverged /
race cases change nothing and are logged. Ordinary rows keep the fill-empty rule, except a sponsor emptied on purpose
here is not refilled by an ordinary row.

Carry: an InstantAdPay batch holds its members (carry.hold) so no auto-activation starts mid-batch; ensureOnChain waits,
then re-reads the account so the contract binds the settled sponsor; wallets from a batch are linked after every sponsor
decision; the wallet hook skips activation while a follow is pending and activates once it is settled.
Registry keeps the follow record (loop guard) and a deliberate clear. Network tank, Admin > Members > Sponsor check and
the partner endpoints as on InstantAdPay. Rows without the new facts hash as before (no resend on deploy).

Tests: qa/sponsorfollow.test.cjs 27/27, qa/carry-hold.test.cjs ok, two-server e2e (in the InstantAdPay repo) 20/20,
QA member walk 0 bugs. No sponsor was changed on production.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 09:05:20 -05:00

23 lines
1.7 KiB
JavaScript

// carry.js guards for the sponsor follow (2026-10-22): an activation that starts while an InstantAdPay registry batch is
// settling the member's sponsor waits for the batch and then re-reads the account; isBinding() is on while an engine
// activation is in flight. No chain, no engine key: the chain is a stub. node qa/carry-hold.test.cjs
'use strict';
const assert = require('assert');
const path = require('path');
const carry = require(path.join(__dirname, '..', 'carry.js'));
(async () => {
let acct = { email: 'm@x.co', address: '0x' + '1'.repeat(40), sponsorRef: 'old', memberId: 0 };
const reads = []; let unheldAt = 0;
carry.init({ dataDir: require('os').tmpdir(), accounts: { byEmail: async e => { reads.push(Date.now()); return Object.assign({}, acct); }, setMemberId: async () => {} },
chain: { memberIdByAccount: async () => { reads.push('chain@' + Date.now()); return 0; }, getConfig: () => ({}) }, siteConfig: () => ({}) });
carry.hold(['M@x.co']); assert.ok(carry.isHeld('m@x.co'));
const run = carry.ensureOnChain({ email: 'm@x.co', address: acct.address, sponsorRef: 'old' }, 0, 'wallet');
await new Promise(r => setTimeout(r, 900));
assert.strictEqual(reads.length, 0, 'nothing read while the batch holds the member');
acct.sponsorRef = 'new'; unheldAt = Date.now(); carry.unhold(['m@x.co']);
const id = await run; assert.strictEqual(id, 0); // no engine key: returns 0 without sending
assert.ok(reads.length >= 2 && reads[0] >= unheldAt, 'account re-read after the batch, then the chain checked');
assert.ok(!carry.isBinding('m@x.co'), 'not binding after it returned');
console.log('carry-hold: ok');
})().catch(e => { console.error('carry-hold: FAIL', e.message); process.exit(1); });