Hub rule 2 (Marty 2026-11-14): every paid Purchase on the LinkSpin contract goes to the hub's /v1/contract-spend from its own retried queue (spends, sent after the binds, tx hash so a resend counts once, POL-in only; activation alone is not a spend), so when two contracts lock different sponsors the one with money spent decides the network sponsor. Still one way, only with HUB_ENABLED; needs network-hub 296aa5d. qa/hubsync.test.cjs 11 checks ok

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 07:55:25 -06:00
parent 9c4a6458f6
commit 5fbaf4f17d
2 changed files with 49 additions and 2 deletions
+19 -1
View File
@@ -125,7 +125,25 @@ const W = n => '0x' + String(n).padStart(40, '0');
await hooks.tick(); assert.strictEqual(hubsync.adminView().lastSeq, seqNow, 'not advanced while the hub cannot be asked');
process.env.HUB_URL = `http://127.0.0.1:${hubPort}`; await hooks.tick();
assert.ok(await accounts.byEmail(E('rose')), 'arrived on the retry');
console.log('hubsync: ok (10 checks)');
// 11. rule 2 (2026-11-14): a LinkSpin activation alone does not decide against a contract with money spent; a paid
// LinkSpin Purchase is reported once (tx) and only after its bind
const per = e => hstore.byEmailKey(e);
await ctb('/v1/join', { email: E('ptw'), username: 'ptw' }); await ctb('/v1/wallet', { email: E('ptw'), wallet: W(91) });
await ctb('/v1/join', { email: E('sil'), username: 'sil' }); await ctb('/v1/wallet', { email: E('sil'), wallet: W(92) });
await ctb('/v1/join', { email: E('tur'), ref: 'ptw', username: 'tur' });
await ctb('/v1/contract-bind', { contract: 'iap', email: E('tur'), wallet: W(93), sponsorRef: W(91), spentCents: 3500 });
const members = { 7: { account: W(92) }, 8: { account: W(93) } };
hubsync.init({ dataDir: LS_DIR, accounts, registry, carry, follow: null, chain: { member: async id => members[id] || null } });
hubsync.onChain({ type: 'MemberActivated', id: 8, account: W(93), sponsorId: 7 });
hubsync.onChain({ type: 'Purchase', buyerId: 8, priceCents: 1000, paidWei: '5', tx: '0xls1', ts: Date.now() + 60000 });
hubsync.onChain({ type: 'Purchase', buyerId: 8, priceCents: 1000, paidWei: '5', tx: '0xls1', ts: Date.now() + 60000 });
await new Promise(r => setTimeout(r, 50)); await hubsync.flush();
const tur = per(E('tur'));
assert.strictEqual(tur.bindings.linkspin.sponsorId, per(E('sil')).id, 'LinkSpin lock under its own sponsor');
assert.strictEqual(tur.bindings.linkspin.spentCents, 1000, 'one purchase counted once');
assert.strictEqual(tur.sponsorId, per(E('ptw')).id, 'the earlier spend (InstantAdPay) still decides');
assert.strictEqual(hubsync.adminView().stats.spends, 1);
console.log('hubsync: ok (11 checks)');
} finally { hub.close(); ls.close(); }
process.exit(0);
})().catch(e => { console.error('hubsync: FAIL', e.stack || e.message); process.exit(1); });