// 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); });