Hub rule 2 (Marty 2026-11-14): every paid Purchase on the InstantAdPay contract goes to the hub's /v1/contract-spend (keyed by the position wallet so its bind is sent first, tx hash so a resend counts once, POL-in only), 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 15/15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -164,6 +164,29 @@ const IAP_DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'hubsync-iap-'));
|
||||
const v = hubsync.adminView(); assert.strictEqual(v.outbox, 0); assert.ok(v.recent.find(l => l.type === 'out-refused' && l.code === 'wallet_taken'));
|
||||
});
|
||||
|
||||
await t('rule 2: a paid Purchase on the InstantAdPay contract reaches the hub and moves the network sponsor to this contract (2026-11-14)', async () => {
|
||||
// tureia2003's shape: locked on LinkSpin under silverstussy (activated only), then bound AND paid here under paidtowatch
|
||||
await ctb('/v1/join', { email: 'ptw@example.test', username: 'ptw' }); await ctb('/v1/wallet', { email: 'ptw@example.test', wallet: W('d') });
|
||||
await ctb('/v1/join', { email: 'sil@example.test', username: 'sil' }); await ctb('/v1/wallet', { email: 'sil@example.test', wallet: W('f') });
|
||||
await ctb('/v1/join', { email: 'tur@example.test', ref: 'sil', username: 'tur' });
|
||||
await ctb('/v1/contract-bind', { contract: 'linkspin', email: 'tur@example.test', wallet: W('7'), sponsorRef: W('f') });
|
||||
assert.strictEqual(hubPerson('tur@example.test').sponsorId, hubPerson('sil@example.test').id);
|
||||
const members = { 5: { account: W('d') }, 12: { account: W('7') } };
|
||||
hubsync.init({ dataDir: IAP_DATA, accounts, lsinbound, chain: { member: async id => members[id] || null } });
|
||||
hubsync.onChain({ type: 'MemberActivated', id: 12, account: W('7'), sponsorId: 5 });
|
||||
hubsync.onChain({ type: 'Purchase', buyerId: 12, priceCents: 0, paidWei: '0', tx: '0xfree' }); // nothing paid in: not a spend
|
||||
hubsync.onChain({ type: 'Purchase', buyerId: 12, priceCents: 3500, paidWei: '1000', tx: '0xpaid', ts: 1700000000000 });
|
||||
hubsync.onChain({ type: 'Purchase', buyerId: 12, priceCents: 3500, paidWei: '1000', tx: '0xpaid', ts: 1700000000000 }); // seen twice
|
||||
await settle(); await hubsync.flush(true);
|
||||
const p = hubPerson('tur@example.test');
|
||||
assert.strictEqual(p.bindings.iap.sponsorId, hubPerson('ptw@example.test').id);
|
||||
assert.strictEqual(p.bindings.iap.spentCents, 3500, 'one purchase counted once');
|
||||
assert.strictEqual(p.bindings.linkspin.sponsorId, hubPerson('sil@example.test').id, 'the LinkSpin lock keeps its sponsor');
|
||||
assert.strictEqual(p.sponsorId, hubPerson('ptw@example.test').id, 'network sponsor = the contract with money spent');
|
||||
assert.strictEqual(hubsync.adminView().outbox, 0);
|
||||
hubsync.init({ dataDir: IAP_DATA, accounts, lsinbound });
|
||||
});
|
||||
|
||||
await t('sponsor.changed and unknown event types are acknowledged and ignored', async () => {
|
||||
const s = signed([{ seq: 99001, type: 'sponsor.changed', personId: hubPerson('bob@example.test').id, data: { by: 'admin' } }, { seq: 99002, type: 'member.blocked', personId: 'h_0000000000000000', data: {} }]);
|
||||
assert.strictEqual((await hubsync.receive(s.headers, s.raw)).status, 200);
|
||||
|
||||
Reference in New Issue
Block a user