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