Skip to content

Commit

Permalink
refactor: satisfies() no longer needs zcf param
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jan 22, 2025
1 parent bd7ae9e commit 7854c0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
4 changes: 2 additions & 2 deletions packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export const assertIssuerKeywords = (zcf, expected) => {
* false and 1 for true. When multiples are introduced, any
* positive return value will mean true.
*
* @param {ZCF} zcf
* @param {any} _ignored no longer used.
* @param {ZcfSeatPartial} seat
* @param {AmountKeywordRecord} update
* @returns {0|1}
*/
export const satisfies = (zcf, seat, update) => {
export const satisfies = (_ignored, seat, update) => {
const currentAllocation = seat.getCurrentAllocation();
const newAllocation = { ...currentAllocation, ...update };
const proposal = seat.getProposal();
Expand Down
48 changes: 10 additions & 38 deletions packages/zoe/test/unitTests/contractSupport/zoeHelpers.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
import { Far } from '@endo/marshal';

import { makeScalarMapStore } from '@agoric/store';
import { setup } from '../setupBasicMints.js';

import {
Expand All @@ -16,27 +15,6 @@ test('ZoeHelpers messages', t => {
);
});

function makeMockTradingZcfBuilder() {
const offers = makeScalarMapStore('offerHandle');
const allocs = makeScalarMapStore('offerHandle');
const reallocatedStagings = [];

return Far('mockTradingZcfBuilder', {
addOffer: (keyword, offer) => offers.init(keyword, offer),
addAllocation: (keyword, alloc) => allocs.init(keyword, alloc),
/** @returns {ZCF} */
build: () =>
Far('mockZCF', {
// @ts-expect-error mock
getZoeService: () => {},
reallocate: (...seatStagings) => {
reallocatedStagings.push(...seatStagings);
},
getReallocatedStagings: () => reallocatedStagings,
}),
});
}

test('ZoeHelpers satisfies blank proposal', t => {
const { moola } = setup();
/** @type {ZCFSeat} */
Expand All @@ -45,10 +23,8 @@ test('ZoeHelpers satisfies blank proposal', t => {
getCurrentAllocation: () => harden({ Asset: moola(10n) }),
getProposal: () => harden({}),
});
const mockZCFBuilder = makeMockTradingZcfBuilder();
const mockZCF = mockZCFBuilder.build();
t.truthy(
satisfies(mockZCF, fakeZcfSeat, { Gift: moola(3n) }),
satisfies({}, fakeZcfSeat, { Gift: moola(3n) }),
`giving anything to a blank proposal is satisifying`,
);
});
Expand All @@ -61,29 +37,27 @@ test('ZoeHelpers satisfies simple proposal', t => {
getCurrentAllocation: () => harden({ Asset: moola(10n) }),
getProposal: () => harden({ want: { Desire: moola(30n) } }),
});
const mockZCFBuilder = makeMockTradingZcfBuilder();
const mockZCF = mockZCFBuilder.build();
t.falsy(
satisfies(mockZCF, fakeZcfSeat, { Desire: moola(3n) }),
satisfies({}, fakeZcfSeat, { Desire: moola(3n) }),
`giving less than specified to a proposal is not satisifying`,
);
t.falsy(
satisfies(mockZCF, fakeZcfSeat, { Gift: moola(3n) }),
satisfies({}, fakeZcfSeat, { Gift: moola(3n) }),
`giving other than what's specified to a proposal is not satisifying`,
);
t.truthy(
satisfies(mockZCF, fakeZcfSeat, { Desire: moola(30n) }),
satisfies({}, fakeZcfSeat, { Desire: moola(30n) }),
`giving exactly what's proposed is satisifying`,
);
t.truthy(
satisfies(mockZCF, fakeZcfSeat, {
satisfies({}, fakeZcfSeat, {
Desire: moola(30n),
Gift: simoleans(1n),
}),
`giving extras beyond what's proposed is satisifying`,
);
t.truthy(
satisfies(mockZCF, fakeZcfSeat, { Desire: moola(40n) }),
satisfies({}, fakeZcfSeat, { Desire: moola(40n) }),
`giving more than what's proposed is satisifying`,
);
});
Expand All @@ -97,22 +71,20 @@ test('ZoeHelpers satisfies() with give', t => {
getProposal: () =>
harden({ give: { Charge: moola(30n) }, want: { Desire: bucks(5n) } }),
});
const mockZCFBuilder = makeMockTradingZcfBuilder();
const mockZCF = mockZCFBuilder.build();
t.falsy(
satisfies(mockZCF, fakeZcfSeat, { Charge: moola(0n), Desire: bucks(1n) }),
satisfies({}, fakeZcfSeat, { Charge: moola(0n), Desire: bucks(1n) }),
`providing neither give nor want is not satisfying`,
);
t.falsy(
satisfies(mockZCF, fakeZcfSeat, { Charge: moola(30n) }),
satisfies({}, fakeZcfSeat, { Charge: moola(30n) }),
`providing less than what's wanted is not satisfying`,
);
t.truthy(
satisfies(mockZCF, fakeZcfSeat, { Charge: moola(0n), Desire: bucks(40n) }),
satisfies({}, fakeZcfSeat, { Charge: moola(0n), Desire: bucks(40n) }),
`providing more than what's wanted is satisfying`,
);
t.truthy(
satisfies(mockZCF, fakeZcfSeat, { Desire: bucks(40n), Charge: moola(3n) }),
satisfies({}, fakeZcfSeat, { Desire: bucks(40n), Charge: moola(3n) }),
`providing what's wanted makes it possible to reduce give`,
);
});

0 comments on commit 7854c0a

Please sign in to comment.