Skip to content

Commit 6ba171f

Browse files
authored
fix: stop accepting offers if zcf.shutdown is called (#1772)
1 parent a74eb98 commit 6ba171f

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

packages/zoe/src/internal-types.js

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
* @property {() => IssuerKeywordRecord} getIssuers
9797
* @property {() => BrandKeywordRecord} getBrands
9898
* @property {() => Object} getTerms
99+
* @property {() => boolean} hasShutdown
100+
* @property {() => void} shutdown
99101
*/
100102

101103
/**

packages/zoe/src/zoeService/zoe.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
212212
const makeInstanceAdmin = () => {
213213
/** @type {Set<ZoeSeatAdmin>} */
214214
const zoeSeatAdmins = new Set();
215+
let hasShutdown = false;
215216

216217
/** @type {InstanceAdmin} */
217218
return {
@@ -234,8 +235,11 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
234235
getIssuers: () => instanceRecord.terms.issuers,
235236
getBrands: () => instanceRecord.terms.brands,
236237
getInstance: () => instance,
237-
exitAllSeats: () =>
238-
zoeSeatAdmins.forEach(zoeSeatAdmin => zoeSeatAdmin.exit()),
238+
hasShutdown: () => hasShutdown,
239+
shutdown: () => {
240+
hasShutdown = true;
241+
zoeSeatAdmins.forEach(zoeSeatAdmin => zoeSeatAdmin.exit());
242+
},
239243
};
240244
};
241245

@@ -246,8 +250,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
246250
E(adminNode)
247251
.done()
248252
.then(
249-
() => instanceAdmin.exitAllSeats(),
250-
() => instanceAdmin.exitAllSeats(),
253+
() => instanceAdmin.shutdown(),
254+
() => instanceAdmin.shutdown(),
251255
);
252256

253257
// Unpack the invitationKit.
@@ -303,7 +307,7 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
303307
return { userSeat, notifier, zoeSeatAdmin };
304308
},
305309
shutdown: () => {
306-
instanceAdmin.exitAllSeats();
310+
instanceAdmin.shutdown();
307311
E(adminNode).terminate();
308312
},
309313
makeZoeMint,
@@ -368,6 +372,11 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
368372
invitationAmount.value.length === 1,
369373
'Only one invitation can be redeemed at a time',
370374
);
375+
const {
376+
value: [{ instance, handle: invitationHandle }],
377+
} = invitationAmount;
378+
const instanceAdmin = instanceToInstanceAdmin.get(instance);
379+
assert(!instanceAdmin.hasShutdown(), `No further offers are accepted`);
371380

372381
const proposal = cleanProposal(getAmountMath, uncleanProposal);
373382
const { give, want } = proposal;
@@ -390,9 +399,6 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
390399
return getAmountMath(proposal.want[keyword].brand).getEmpty();
391400
}
392401
});
393-
const {
394-
value: [{ instance, handle: invitationHandle }],
395-
} = invitationAmount;
396402

397403
return Promise.all(paymentDepositedPs).then(amountsArray => {
398404
const initialAllocation = arrayToObj(amountsArray, proposalKeywords);
@@ -403,7 +409,6 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
403409
const exitObjPromiseKit = makePromiseKit();
404410
// Don't trigger Node.js's UnhandledPromiseRejectionWarning
405411
exitObjPromiseKit.promise.catch(_ => {});
406-
const instanceAdmin = instanceToInstanceAdmin.get(instance);
407412
const seatHandle = makeHandle('SeatHandle');
408413

409414
const { userSeat, notifier, zoeSeatAdmin } = makeZoeSeatAdminKit(

packages/zoe/test/unitTests/zcf/test-zcf.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,7 @@ test(`zcf.shutdown - zcfSeat exits`, async t => {
12181218
t.truthy(await E(userSeat).hasExited());
12191219
});
12201220

1221-
// TODO: Any new offers should throw after zcf.shutdown() is called
1222-
// https://github.com/Agoric/agoric-sdk/issues/1756
1223-
test.failing(`zcf.shutdown - no further offers accepted`, async t => {
1221+
test(`zcf.shutdown - no further offers accepted`, async t => {
12241222
const { zoe, zcf } = await setupZCFTest({});
12251223
const invitation = await zcf.makeInvitation(() => {}, 'seat');
12261224
zcf.shutdown();

0 commit comments

Comments
 (0)