Game Pass: no pass is ever bought with credits again (Marty, 2026-10-22). Buy only opens a waiting order and sends the member to buy a package of at least the tier price; the order is fulfilled only by a fresh on-chain package Purchase by one of the member's own positions (main or linked), mined after the order was opened (block time, 30 s clock grace), each purchase tx used once across every account. The member keeps the package credits for ads; sponsors and team are paid by the package as usual. Existing passes untouched. Card and confirm copy say so; my.js tag bumped. qa/gamepass.mjs updated for the new flow (older-than-order, too small, another member, replayed tx): ALL PASS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-22 12:42:59 -05:00
parent 839c867595
commit 6a3313a861
5 changed files with 100 additions and 58 deletions
+28 -13
View File
@@ -71,24 +71,39 @@ try {
g = (await api('/api/my/gamepass', null, hA)).j;
ok(g && g.enabled === true && g.caps && g.caps.enforced === false && g.caps.daily === 0.3 && g.caps.total === 2, 'pass ON: GET shows free caps 0.30 / 2 and enforced false (no capsStartDate)', JSON.stringify(g.caps));
// 2. buy without purchased credits -> waiting order; a $5 package fulfils it
// 2. buy (2026-10-22: no pass is ever bought with credits) -> waiting order; only a FRESH package by the member's own position fulfils it.
// A's purchases are stamped Sun Oct 18 (week of Oct 12) and B's Tue Oct 20 (week of Oct 19), so the tournament below sees one sale.
const SUN = Date.parse('2026-10-18T17:00:00Z'), TUE = Date.parse('2026-10-20T17:00:00Z');
r = await api('/api/my/gamepass/buy', { data: {} }, hA);
ok(r.status === 200 && r.j && r.j.needPay === true && r.j.payUrl === '/my?from=gamepass#buy' && r.j.order, 'buy with no purchased credits -> needPay + payUrl + waiting order', JSON.stringify(r.j && { needPay: r.j.needPay, payUrl: r.j.payUrl, need: r.j.need }));
const order1 = r.j && r.j.order;
r = await api('/api/my/gamepass/buy', { data: {} }, hA);
ok(r.j && r.j.order === order1, 'a second buy attempt reuses the same waiting order', r.j && r.j.order);
ok(r.status === 200 && r.j && r.j.needPay === true && r.j.payUrl === '/my?from=gamepass#buy' && r.j.order && r.j.package === 5 && /package/.test(r.j.message || ''), 'buy -> needPay + payUrl + waiting order (never a credit charge)', JSON.stringify(r.j && { needPay: r.j.needPay, payUrl: r.j.payUrl, pkg: r.j.package }));
const order1 = r.j && r.j.order, order1Ts = r.j && r.j.orderTs;
r = await api('/api/my/gamepass/buy', { data: { devPaid: true } }, hA);
ok(r.j && r.j.order === order1 && r.j.needPay === true && !r.j.ok, 'a second buy (even with the retired devPaid flag) reuses the same waiting order, no pass', r.j && r.j.order);
g = (await api('/api/my/gamepass', null, hA)).j; ok(g.waiting === true && g.active === false, 'GET shows waiting: true', '');
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500 } });
ok(r.j && r.j.order && r.j.order.order === order1, 'a $5 package purchase event fulfils the waiting order', JSON.stringify(r.j));
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, minedAt: order1Ts - 10 * 60000 } });
ok(r.j && r.j.order === null, 'a package mined BEFORE the order was opened does not fulfil it', JSON.stringify(r.j));
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 200 } });
ok(r.j && r.j.order === null, 'a $2 package does not fulfil a $5 pass order', JSON.stringify(r.j));
r = await api('/api/dev/gamepass-purchase', { data: { email: Bm, cents: 500 } });
ok(r.j && r.j.order === null, 'another member’s package does not fulfil A’s order', JSON.stringify(r.j));
const tx1 = '0x' + crypto.randomBytes(32).toString('hex');
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, tx: tx1, now: SUN } });
ok(r.j && r.j.order && r.j.order.order === order1, 'a fresh $5 package by A fulfils the waiting order', JSON.stringify(r.j));
g = (await api('/api/my/gamepass', null, hA)).j; const until1 = g.until;
ok(g.active === true && g.waiting === false && near(g.until, Date.now() + 7 * 86400000, 60000) && g.bought === 1, 'pass active for 7 days, waiting cleared', new Date(g.until).toISOString());
ok(g.active === true && g.waiting === false && g.until === SUN + 7 * 86400000 && g.bought === 1, 'pass active for 7 days from the purchase, waiting cleared', new Date(g.until).toISOString());
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500 } });
ok(r.j && r.j.order === null, 'another package with no waiting order does nothing', JSON.stringify(r.j));
// 3. buy while active -> extends from the current until (charge stubbed: devPaid, local only)
r = await api('/api/my/gamepass/buy', { data: { devPaid: true } }, hA);
ok(r.status === 200 && r.j.ok && near(r.j.until, until1 + 7 * 86400000, 1000) && r.j.paid === 'credits', 'buy while active extends by 7 days from the current until', new Date(r.j.until).toISOString());
r = await api('/api/my/gamepass/buy', { data: { devPaid: true, devDay: '2026-10-20' } }, hB);
ok(r.status === 200 && r.j.ok && r.j.active === true, 'member B: buy -> active (sale stamped in the week of Oct 19 for the tournament)', '');
// 3. buy while active -> a new order; the same tx again is refused, a new package extends from the current until
r = await api('/api/my/gamepass/buy', { data: {} }, hA);
ok(r.j && r.j.needPay && r.j.order && r.j.order !== order1, 'buy while active opens a new waiting order', r.j && r.j.order);
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, tx: tx1, now: SUN } });
ok(r.j && r.j.order === null, 'replaying a purchase tx that already paid a pass does nothing (each tx once)', JSON.stringify(r.j));
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, now: SUN } });
ok(r.j && r.j.order && near(r.j.order.until, until1 + 7 * 86400000, 1000), 'a fresh package while active extends by 7 days from the current until', r.j && r.j.order && new Date(r.j.order.until).toISOString());
r = await api('/api/my/gamepass/buy', { data: {} }, hB);
r = await api('/api/dev/gamepass-purchase', { data: { email: Bm, cents: 1000, now: TUE } });
g = (await api('/api/my/gamepass', null, hB)).j;
ok(r.j && r.j.order && g.active === true, 'member B: order + a $10 package -> active (sale stamped in the week of Oct 19 for the tournament)', JSON.stringify(r.j));
// 4. partner auth + /api/partner/player
let pl = await gameGet('/api/partner/player', { game: 'gemkingdom', m: 0, e: A }, A, GK);