Support paid current-turn travel deals
Verify and publish checkpoint container / container (push) Successful in 10m34s
Verify and publish checkpoint container / container (push) Successful in 10m34s
This commit is contained in:
1 parent
82c639c977
commit
a1b2aacbac
9 files changed
+371
-23
No files matched your search
@@ -57,21 +57,61 @@ void test('a recipient accepts and both release an unchanged current-turn travel
|
||||
assert.deepEqual(withdrawPublicDeal(offered, seats, 'a').travel, term);
|
||||
});
|
||||
|
||||
void test('travel is incompatible with multi-party, payment, replacement and malformed persisted terms', () => {
|
||||
void test('travel is incompatible with multi-party, replacement and malformed persisted terms', () => {
|
||||
const multi = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'multi');
|
||||
const payment = createPublicDeal(seats, 'a', 'b', 'Terms', 3, 'paid',
|
||||
{ kind: 'immediateBribe', payer: 'a', recipient: 'b', amount: 1 });
|
||||
const offered = setPublicDealTravel(fresh(), term, seats);
|
||||
const active = respondPublicDeal(offered, seats, 'b', true);
|
||||
for (const deal of [multi, payment, offered, active])
|
||||
for (const deal of [multi, offered, active])
|
||||
assert.throws(() => setPublicDealTravel(deal, term, seats), PublicDealError);
|
||||
for (const invalid of [
|
||||
{ ...multi, travel: term }, { ...payment, travel: term },
|
||||
{ ...multi, travel: term },
|
||||
{ ...fresh(), travel: undefined }, { ...fresh(), travel: { ...term, sector: 0 } },
|
||||
{ ...offered, paymentStatus: 'pending' }, { ...offered, travelStatus: 'pending' },
|
||||
]) assert.throws(() => validatePublicDeals([invalid], seats), PublicDealError);
|
||||
});
|
||||
|
||||
void test('a proposer-to-recipient immediate payment can accompany travel through the complete deal lifecycle', () => {
|
||||
const payment = { kind: 'immediateBribe', payer: 'a', recipient: 'b', amount: 3 } as const;
|
||||
const original = createPublicDeal(seats, 'a', 'b', 'Payment for travel.', 3, 'paid-travel', payment);
|
||||
const offered = setPublicDealTravel(original, term, seats);
|
||||
assert.equal(original.travel, undefined);
|
||||
const active = respondPublicDeal(offered, seats, 'b', true);
|
||||
const released = releasePublicDeal(releasePublicDeal(active, seats, 'a', true), seats, 'b', true);
|
||||
for (const deal of [offered, active, released, respondPublicDeal(offered, seats, 'b', false),
|
||||
withdrawPublicDeal(offered, seats, 'a')]) {
|
||||
const roundtrip = JSON.parse(JSON.stringify(deal)) as PublicDeal;
|
||||
const before = JSON.stringify(roundtrip);
|
||||
validatePublicDeals([roundtrip], seats);
|
||||
assert.equal(JSON.stringify(roundtrip), before);
|
||||
assert.deepEqual(roundtrip.payment, payment);
|
||||
assert.deepEqual(roundtrip.travel, term);
|
||||
assert.equal(Object.hasOwn(roundtrip, 'paymentStatus'), false);
|
||||
}
|
||||
assert.equal(active.status, 'active');
|
||||
assert.equal(released.status, 'released');
|
||||
});
|
||||
|
||||
void test('paid travel rejects reverse, deferred, multiparty and forged persisted payment shapes', () => {
|
||||
const reverse = { kind: 'immediateBribe', payer: 'b', recipient: 'a', amount: 1 } as const;
|
||||
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 [reverse, 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 multi = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'multi-paid', paid);
|
||||
assert.throws(() => setPublicDealTravel(multi, term, seats), PublicDealError);
|
||||
for (const invalid of [
|
||||
{ ...multi, travel: term },
|
||||
{ ...fresh(), payment: { ...paid, recipient: 'c' }, travel: term },
|
||||
{ ...fresh(), payment: { ...paid, amount: 0 }, travel: term },
|
||||
{ ...fresh(), payment: { ...paid, extra: true }, travel: term },
|
||||
{ ...fresh(), payment: undefined, travel: term },
|
||||
{ ...fresh(), payment: paid, paymentStatus: 'paid', travel: term },
|
||||
]) assert.throws(() => validatePublicDeals([invalid], seats), PublicDealError);
|
||||
});
|
||||
|
||||
void test('legacy two-party and multi-party records validate without acquiring travel fields', () => {
|
||||
const legacy = fresh();
|
||||
const multi = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'multi');
|
||||
|
||||
Reference in new issue
Block a user