Support immediate payments in group travel deals
Verify and publish checkpoint container / container (push) Successful in 10m49s
Verify and publish checkpoint container / container (push) Successful in 10m49s
This commit is contained in:
1 parent
3987c5c16b
commit
6c1530382d
10 files changed
+207
-24
No files matched your search
@@ -73,7 +73,10 @@ void test('future two-party and group terms retain due turns across consent and
|
||||
}
|
||||
const backwardsGroup = {...group, travel:{...term, actor:'c', dueTurn:2}};
|
||||
assert.throws(() => validatePublicDeals([backwardsGroup], seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{...group, payment, travel:{...term, actor:'c', dueTurn:5}}], seats), PublicDealError);
|
||||
const paidGroup = { ...group, payment, travel: { ...term, actor: 'c', dueTurn: 5 } };
|
||||
validatePublicDeals([paidGroup], seats);
|
||||
assert.equal(publicDealTravelDueTurn(paidGroup), 5);
|
||||
assert.deepEqual(paidGroup.payment, payment);
|
||||
});
|
||||
|
||||
void test('a recipient accepts and both release an unchanged current-turn travel term', () => {
|
||||
@@ -155,7 +158,7 @@ void test('multiparty travel requires the committed recipient to accept last and
|
||||
}
|
||||
});
|
||||
|
||||
void test('multiparty travel rejects forged actors, early votes, payments and nonfresh offers', () => {
|
||||
void test('multiparty travel rejects forged actors, early votes and nonfresh offers', () => {
|
||||
const multi = createMultipartyPublicDeal(seats, 'a', ['b','c'], 'Terms', 3, 'multi');
|
||||
for (const actor of ['a','d','',undefined]) {
|
||||
const invalid = {...term, actor};
|
||||
@@ -168,7 +171,6 @@ void test('multiparty travel rejects forged actors, early votes, payments and no
|
||||
}
|
||||
const acceptedOther = respondPublicDeal(offered, seats, 'c', true);
|
||||
assert.throws(() => setPublicDealTravel(respondPublicDeal(multi, seats, 'c', true), {...term,actor:'b'}, seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{...offered,payment:{kind:'immediateBribe',payer:'a',recipient:'b',amount:1}}], seats), PublicDealError);
|
||||
assert.equal(respondPublicDeal(acceptedOther, seats, 'b', true).status, 'active');
|
||||
});
|
||||
|
||||
@@ -193,7 +195,7 @@ 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, multiparty and forged persisted payment shapes', () => {
|
||||
void test('paid travel rejects deferred and forged persisted payment shapes', () => {
|
||||
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]) {
|
||||
@@ -202,7 +204,6 @@ void test('paid travel rejects deferred, multiparty and forged persisted payment
|
||||
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 },
|
||||
@@ -222,3 +223,38 @@ void test('legacy two-party and multi-party records validate without acquiring t
|
||||
assert.equal(Object.hasOwn(legacy, 'travel'), false);
|
||||
assert.equal(Object.hasOwn(multi, 'travel'), false);
|
||||
});
|
||||
|
||||
for (const payer of ['a', 'b', 'c']) for (const recipient of ['a', 'b', 'c']) {
|
||||
if (payer === recipient) continue;
|
||||
void test(`group travel holds ${payer}-to-${recipient} payment until every party accepts`, () => {
|
||||
const payment = { kind: 'immediateBribe', payer, recipient, amount: 3 } as const;
|
||||
const group = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Travel and payment.', 3,
|
||||
`group-${payer}-${recipient}`, payment);
|
||||
const offered = setPublicDealTravel(group, { ...term, actor: 'b' }, seats);
|
||||
assert.throws(() => respondPublicDeal(offered, seats, 'b', true), PublicDealError);
|
||||
const partial = respondPublicDeal(offered, seats, 'c', true);
|
||||
assert.equal(partial.status, 'offered');
|
||||
const active = respondPublicDeal(partial, seats, 'b', true);
|
||||
assert.equal(active.status, 'active');
|
||||
assert.deepEqual(active.acceptVotes, ['a', 'b', 'c']);
|
||||
assert.deepEqual(active.payment, payment);
|
||||
assert.deepEqual(active.travel, { ...term, actor: 'b' });
|
||||
for (const deal of [offered, partial, active, respondPublicDeal(offered, seats, 'c', false),
|
||||
withdrawPublicDeal(offered, seats, 'a')]) validatePublicDeals([JSON.parse(JSON.stringify(deal))], seats);
|
||||
const released = ['a', 'b', 'c'].reduce((deal, actor) => releasePublicDeal(deal, seats, actor, true), active);
|
||||
assert.equal(released.status, 'released');
|
||||
validatePublicDeals([released], seats);
|
||||
});
|
||||
}
|
||||
|
||||
void test('group travel still rejects deferred payments and 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 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);
|
||||
assert.throws(() => validatePublicDeals([{ ...paid, payment: { ...immediate, payer: 'd' } }], seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{ ...paid, acceptVotes: ['a', 'b'] }], seats), PublicDealError);
|
||||
});
|
||||
Reference in new issue
Block a user