Support group travel agreements
Verify and publish checkpoint container / container (push) Successful in 11m13s
Verify and publish checkpoint container / container (push) Successful in 11m13s
This commit is contained in:
1 parent
82d857b667
commit
e1e02fc1a1
10 files changed
+432
-56
No files matched your search
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createMultipartyPublicDeal, createPublicDeal, parsePublicDealTravel, PublicDealError,
|
||||
publicDealTravelActor,
|
||||
releasePublicDeal, respondPublicDeal, setPublicDealTravel, validatePublicDeals, withdrawPublicDeal,
|
||||
type PublicDeal, type PublicDealSeat,
|
||||
} from '../game/public-deals';
|
||||
@@ -22,8 +23,10 @@ void test('travel terms accept only exact bounded native actions and an explicit
|
||||
{ ...term, kind: 'fly' }, { ...term, territory: 'not_a_territory' },
|
||||
...[0, -1, 21, 1.5, Infinity, Number.MAX_SAFE_INTEGER + 1, '1'].map(minimum => ({ ...term, minimum })),
|
||||
{ ...term, answer: 'yes' }, { ...term, answer: undefined },
|
||||
{ ...term, sector: 0 }, { ...term, turn: 4 }, { ...term, actor: 'a' },
|
||||
{ ...term, sector: 0 }, { ...term, turn: 4 }, { ...term, actor: '' }, { ...term, actor: undefined },
|
||||
{ ...term, actor: ' c ' },
|
||||
]) assert.throws(() => parsePublicDealTravel(invalid), PublicDealError);
|
||||
assert.deepEqual(parsePublicDealTravel({...term, actor:'c'}), {...term, actor:'c'});
|
||||
});
|
||||
|
||||
void test('a recipient accepts and both release an unchanged current-turn travel term', () => {
|
||||
@@ -34,6 +37,7 @@ void test('a recipient accepts and both release an unchanged current-turn travel
|
||||
assert.equal(source.travel, undefined);
|
||||
assert.deepEqual(offered.travel, term);
|
||||
assert.equal(offered.turn, 3);
|
||||
assert.equal(publicDealTravelActor(offered), 'b');
|
||||
assert.throws(() => respondPublicDeal(offered, seats, 'a', true), PublicDealError);
|
||||
assert.throws(() => respondPublicDeal(offered, seats, 'c', true), PublicDealError);
|
||||
const active = respondPublicDeal(offered, seats, 'b', true);
|
||||
@@ -57,7 +61,7 @@ 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, replacement and malformed persisted terms', () => {
|
||||
void test('travel requires an actor for multiparty offers and cannot replace an existing term', () => {
|
||||
const multi = createMultipartyPublicDeal(seats, 'a', ['b', 'c'], 'Terms', 3, 'multi');
|
||||
const offered = setPublicDealTravel(fresh(), term, seats);
|
||||
const active = respondPublicDeal(offered, seats, 'b', true);
|
||||
@@ -65,11 +69,62 @@ void test('travel is incompatible with multi-party, replacement and malformed pe
|
||||
assert.throws(() => setPublicDealTravel(deal, term, seats), PublicDealError);
|
||||
for (const invalid of [
|
||||
{ ...multi, travel: term },
|
||||
{ ...fresh(), travel: {...term, actor:'b'} },
|
||||
{ ...fresh(), travel: undefined }, { ...fresh(), travel: { ...term, sector: 0 } },
|
||||
{ ...offered, paymentStatus: 'pending' }, { ...offered, travelStatus: 'pending' },
|
||||
]) assert.throws(() => validatePublicDeals([invalid], seats), PublicDealError);
|
||||
});
|
||||
|
||||
void test('multiparty travel requires the committed recipient to accept last and all parties to release', () => {
|
||||
const people: PublicDealSeat[] = ['a','b','c','d','e','f'].map(id => ({id}));
|
||||
for (const actor of ['b','c','d','e','f']) {
|
||||
const multi = createMultipartyPublicDeal(people, 'a', ['b','c','d','e','f'], 'Travel together.', 3, `multi-${actor}`);
|
||||
const offered = setPublicDealTravel(multi, {...term,actor}, people);
|
||||
assert.deepEqual(offered.travel, {...term,actor});
|
||||
assert.equal(publicDealTravelActor(offered), actor);
|
||||
assert.equal(multi.travel, undefined);
|
||||
assert.throws(() => respondPublicDeal(offered, people, actor, true), PublicDealError);
|
||||
assert.equal(respondPublicDeal(offered, people, actor, false).status, 'declined');
|
||||
assert.equal(withdrawPublicDeal(offered, people, 'a').status, 'withdrawn');
|
||||
let current = offered;
|
||||
// Deliberately vote in reverse roster order; serialization stays canonical.
|
||||
for (const voter of ['f','e','d','c','b'].filter(id => id !== actor)) {
|
||||
current = respondPublicDeal(current, people, voter, true);
|
||||
assert.equal(current.status, 'offered');
|
||||
if (current.acceptVotes!.length < people.length - 1)
|
||||
assert.throws(() => respondPublicDeal(current, people, actor, true), PublicDealError);
|
||||
}
|
||||
const last = respondPublicDeal(current, people, actor, true);
|
||||
assert.equal(last.status, 'active');
|
||||
assert.deepEqual(last.acceptVotes, ['a','b','c','d','e','f']);
|
||||
let released = last;
|
||||
for (const voter of ['f','e','d','c','b','a']) released = releasePublicDeal(released, people, voter, true);
|
||||
assert.equal(released.status, 'released');
|
||||
for (const snapshot of [offered,current,last,released]) {
|
||||
const copy = JSON.parse(JSON.stringify(snapshot)) as PublicDeal;
|
||||
validatePublicDeals([copy], people);
|
||||
assert.deepEqual(copy.travel, {...term,actor});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
void test('multiparty travel rejects forged actors, early votes, payments and nonfresh offers', () => {
|
||||
const multi = createMultipartyPublicDeal(seats, 'a', ['b','c'], 'Terms', 3, 'multi');
|
||||
for (const actor of ['a','d','',undefined]) {
|
||||
const invalid = {...term, actor};
|
||||
assert.throws(() => setPublicDealTravel(multi, invalid, seats), PublicDealError);
|
||||
assert.throws(() => validatePublicDeals([{...multi, travel:invalid}], seats), PublicDealError);
|
||||
}
|
||||
const offered = setPublicDealTravel(multi, {...term,actor:'b'}, seats);
|
||||
for (const status of ['offered','withdrawn','declined'] as const) {
|
||||
assert.throws(() => validatePublicDeals([{...offered,status,acceptVotes:['a','b']}], seats), PublicDealError);
|
||||
}
|
||||
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');
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user