Skip to content

Commit

Permalink
fix: stop accepting offers if zcf.shutdown is called
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills committed Sep 15, 2020
1 parent 7c7bcca commit a70095f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/zoe/src/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
* @property {() => IssuerKeywordRecord} getIssuers
* @property {() => BrandKeywordRecord} getBrands
* @property {() => Object} getTerms
* @property {() => boolean} hasShutdown
* @property {() => void} shutdown
*/

/**
Expand Down
23 changes: 14 additions & 9 deletions packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
const makeInstanceAdmin = () => {
/** @type {Set<ZoeSeatAdmin>} */
const zoeSeatAdmins = new Set();
let hasShutdown = false;

/** @type {InstanceAdmin} */
return {
Expand All @@ -234,8 +235,11 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
getIssuers: () => instanceRecord.terms.issuers,
getBrands: () => instanceRecord.terms.brands,
getInstance: () => instance,
exitAllSeats: () =>
zoeSeatAdmins.forEach(zoeSeatAdmin => zoeSeatAdmin.exit()),
hasShutdown: () => hasShutdown,
shutdown: () => {
hasShutdown = true;
zoeSeatAdmins.forEach(zoeSeatAdmin => zoeSeatAdmin.exit());
},
};
};

Expand All @@ -246,8 +250,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
E(adminNode)
.done()
.then(
() => instanceAdmin.exitAllSeats(),
() => instanceAdmin.exitAllSeats(),
() => instanceAdmin.shutdown(),
() => instanceAdmin.shutdown(),
);

// Unpack the invitationKit.
Expand Down Expand Up @@ -303,7 +307,7 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
return { userSeat, notifier, zoeSeatAdmin };
},
shutdown: () => {
instanceAdmin.exitAllSeats();
instanceAdmin.shutdown();
E(adminNode).terminate();
},
makeZoeMint,
Expand Down Expand Up @@ -368,6 +372,11 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
invitationAmount.value.length === 1,
'Only one invitation can be redeemed at a time',
);
const {
value: [{ instance, handle: invitationHandle }],
} = invitationAmount;
const instanceAdmin = instanceToInstanceAdmin.get(instance);
assert(!instanceAdmin.hasShutdown(), `No further offers are accepted`);

const proposal = cleanProposal(getAmountMath, uncleanProposal);
const { give, want } = proposal;
Expand All @@ -390,9 +399,6 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
return getAmountMath(proposal.want[keyword].brand).getEmpty();
}
});
const {
value: [{ instance, handle: invitationHandle }],
} = invitationAmount;

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

const { userSeat, notifier, zoeSeatAdmin } = makeZoeSeatAdminKit(
Expand Down
4 changes: 1 addition & 3 deletions packages/zoe/test/unitTests/zcf/test-zcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,7 @@ test.failing(`zcf.shutdown - zcfSeat exits`, async t => {
t.truthy(await E(userSeat).hasExited());
});

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

0 comments on commit a70095f

Please sign in to comment.