Support deferred payments with travel deals
Verify and publish checkpoint container / container (push) Successful in 11m29s
Verify and publish checkpoint container / container (push) Successful in 11m29s
This commit is contained in:
1 parent
9536c77062
commit
5e294215be
16 files changed
+603
-100
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createMultipartyPublicDeal, createPublicDeal, parsePublicDealTravel, PublicDealError,
|
||||
createMultipartyPublicDeal, createPublicDeal, markPublicDealPaid, parsePublicDealTravel, PublicDealError,
|
||||
publicDealTravelActor, publicDealTravelDueTurn,
|
||||
releasePublicDeal, respondPublicDeal, setPublicDealTravel, validatePublicDeals, withdrawPublicDeal,
|
||||
type PublicDeal, type PublicDealSeat,
|
||||
@@ -195,13 +195,19 @@ for (const [payer, recipient] of [['a', 'b'], ['b', 'a']] as const) void test(`a
|
||||
assert.equal(released.status, 'released');
|
||||
});
|
||||
|
||||
void test('paid travel rejects deferred and forged persisted payment shapes', () => {
|
||||
void test('deferred paid travel survives the two-party lifecycle and forged payment shapes reject', () => {
|
||||
const deferred = { kind: 'deferredBribe', payer: 'a', recipient: 'b', amount: 1, dueTurn: 3 } as const;
|
||||
const paid = { kind: 'immediateBribe', payer: 'a', recipient: 'b', amount: 1 } as const;
|
||||
for (const payment of [deferred]) {
|
||||
const offer = createPublicDeal(seats, 'a', 'b', 'Terms', 3, `invalid-${payment.kind}`, payment);
|
||||
assert.throws(() => setPublicDealTravel(offer, term, seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{ ...offer, travel: term }], seats), PublicDealError);
|
||||
const offer = setPublicDealTravel(createPublicDeal(seats, 'a', 'b', 'Terms', 3, 'deferred-travel', deferred), term, seats);
|
||||
const active = respondPublicDeal(offer, seats, 'b', true);
|
||||
assert.equal(active.paymentStatus, 'pending');
|
||||
const paidDeal = markPublicDealPaid(active, seats, 'a');
|
||||
assert.equal(paidDeal.paymentStatus, 'paid');
|
||||
for (const deal of [offer,active,paidDeal]) {
|
||||
const roundtrip = JSON.parse(JSON.stringify(deal)) as PublicDeal;
|
||||
validatePublicDeals([roundtrip], seats);
|
||||
assert.deepEqual(roundtrip.payment, deferred);
|
||||
assert.deepEqual(roundtrip.travel, term);
|
||||
}
|
||||
const multi = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'multi-paid', paid);
|
||||
for (const invalid of [
|
||||
@@ -247,11 +253,19 @@ for (const payer of ['a', 'b', 'c']) for (const recipient of ['a', 'b', 'c']) {
|
||||
});
|
||||
}
|
||||
|
||||
void test('group travel still rejects deferred payments and forged party identities', () => {
|
||||
void test('group travel accepts deferred payments but rejects forged party identities', () => {
|
||||
const deferred = { kind: 'deferredBribe', payer: 'a', recipient: 'b', amount: 1, dueTurn: 3 } as const;
|
||||
const group = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'group-deferred', deferred);
|
||||
assert.throws(() => setPublicDealTravel(group, { ...term, actor: 'b' }, seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{ ...group, travel: { ...term, actor: 'b' } }], seats), PublicDealError);
|
||||
const offered = setPublicDealTravel(group, { ...term, actor: 'b' }, seats);
|
||||
assert.throws(() => respondPublicDeal(offered, seats, 'b', true), PublicDealError);
|
||||
const active = respondPublicDeal(respondPublicDeal(offered, seats, 'c', true), seats, 'b', true);
|
||||
assert.equal(active.paymentStatus, 'pending');
|
||||
const settled = markPublicDealPaid(active, seats, 'a');
|
||||
for (const deal of [offered,active,settled]) {
|
||||
validatePublicDeals([JSON.parse(JSON.stringify(deal))], seats);
|
||||
assert.deepEqual(deal.payment, deferred);
|
||||
assert.deepEqual(deal.travel, { ...term, actor: 'b' });
|
||||
}
|
||||
const immediate = { kind: 'immediateBribe', payer: 'a', recipient: 'b', amount: 1 } as const;
|
||||
const paid = setPublicDealTravel(createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'group-paid', immediate),
|
||||
{ ...term, actor: 'b' }, seats);
|
||||
|
||||
Reference in new issue
Block a user