Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make userSeat.getPayout(foo) throw if foo is not present #10738

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/zoe/src/zoeService/originalZoeSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { E } from '@endo/eventual-send';
import { M, prepareExoClassKit } from '@agoric/vat-data';
import { deeplyFulfilled } from '@endo/marshal';
import { makePromiseKit } from '@endo/promise-kit';
import { NonNullish } from '@agoric/internal';

import { satisfiesWant } from '../contractFacet/offerSafety.js';
import '../types-ambient.js';
import '../internal-types.js';
import {
AmountKeywordRecordShape,
KeywordShape,
ExitObjectShape,
KeywordShape,
PaymentPKeywordRecordShape,
} from '../typeGuards.js';

Expand Down Expand Up @@ -289,8 +290,10 @@ export const declareOldZoeSeatAdminKind = (baggage, makeDurablePublishKit) => {
// doExit(), which ensures that finalPayouts() has set state.payouts.
return E.when(
state.subscriber.subscribeAfter(),
() => state.payouts[keyword],
() => state.payouts[keyword],
() =>
NonNullish(state.payouts[keyword], `No payout for "${keyword}"`),
() =>
NonNullish(state.payouts[keyword], `No payout for "${keyword}"`),
);
},

Expand Down
4 changes: 3 additions & 1 deletion packages/zoe/src/zoeService/types-ambient.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@
* this seat. The promise will resolve after the seat has exited.
* @property {(keyword: Keyword) => Promise<Payment<any>>} getPayout
* returns a promise for the Payment corresponding to the indicated keyword.
* The promise will resolve after the seat has exited.
* The promise will resolve after the seat has exited. If there is no payment
* corresponding to the keyword, an error will be thrown. (It used to return
* undefined.)
* @property {() => Promise<OR>} getOfferResult
* @property {() => void} [tryExit]
* Note: Only works if the seat's `proposal` has an `OnDemand` `exit` clause. Zoe's
Expand Down
7 changes: 5 additions & 2 deletions packages/zoe/src/zoeService/zoeSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { E } from '@endo/eventual-send';
import { M, prepareExoClassKit } from '@agoric/vat-data';
import { deeplyFulfilled } from '@endo/marshal';
import { makePromiseKit } from '@endo/promise-kit';
import { NonNullish } from '@agoric/internal';

import { satisfiesWant } from '../contractFacet/offerSafety.js';
import '../types-ambient.js';
Expand Down Expand Up @@ -143,8 +144,10 @@ export const makeZoeSeatAdminFactory = baggage => {
// doExit(), which ensures that finalPayouts() has set state.payouts.
return E.when(
state.subscriber.subscribeAfter(),
() => state.payouts[keyword],
() => state.payouts[keyword],
() =>
NonNullish(state.payouts[keyword], `No payout for "${keyword}"`),
() =>
NonNullish(state.payouts[keyword], `No payout for "${keyword}"`),
);
},

Expand Down
4 changes: 4 additions & 0 deletions packages/zoe/test/unitTests/zcf/zcf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@ test(`userSeat.getPayouts, getPayout from zcf.makeEmptySeatKit`, async t => {
const payoutAP = E(userSeat).getPayout('A');
const payoutBP = E(userSeat).getPayout('B');

await t.throwsAsync(() => E(userSeat).getPayout('C'), {
message: /No payout for "C"/,
});

t.deepEqual(await payoutPs.A, await payoutAP);
t.deepEqual(await payoutPs.B, await payoutBP);

Expand Down
Loading