Skip to content

Commit

Permalink
fix: exit zcfSeats immediately on shutdown. (Agoric#1770)
Browse files Browse the repository at this point in the history
* fix: exit zcfSeats immediately on shutdown.

* fix: check if hasExited before trying to update

* fix: contract get shutdown if no more tickets are left, so sellerSeat is exited, making this assertion throw:

      assert(sellerSeat && !sellerSeat.hasExited(), `no items are for sale`);
  • Loading branch information
katelynsills authored Sep 15, 2020
1 parent 7c7bcca commit 2409eb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
14 changes: 11 additions & 3 deletions packages/zoe/src/contractFacet/contractFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { assert, details } from '@agoric/assert';
import { E } from '@agoric/eventual-send';
import makeWeakStore from '@agoric/weak-store';
import makeStore from '@agoric/store';

import { makeAmountMath, MathKind } from '@agoric/ertp';
import { makeNotifierKit, updateFromNotifier } from '@agoric/notifier';
Expand Down Expand Up @@ -45,8 +46,8 @@ export function buildRootObject(_powers, _params, testJigSetter = undefined) {

const invitationHandleToHandler = makeWeakStore('invitationHandle');

/** @type {WeakStore<ZCFSeat,ZCFSeatAdmin>} */
const zcfSeatToZCFSeatAdmin = makeWeakStore('zcfSeat');
/** @type {Store<ZCFSeat,ZCFSeatAdmin>} */
const zcfSeatToZCFSeatAdmin = makeStore('zcfSeat');
/** @type {WeakStore<ZCFSeat,SeatHandle>} */
const zcfSeatToSeatHandle = makeWeakStore('zcfSeat');

Expand Down Expand Up @@ -345,7 +346,14 @@ export function buildRootObject(_powers, _params, testJigSetter = undefined) {
return invitationP;
},
// Shutdown the entire vat and give payouts
shutdown: () => E(zoeInstanceAdmin).shutdown(),
shutdown: () => {
E(zoeInstanceAdmin).shutdown();
zcfSeatToZCFSeatAdmin.entries().forEach(([zcfSeat, zcfSeatAdmin]) => {
if (!zcfSeat.hasExited()) {
zcfSeatAdmin.updateHasExited();
}
});
},
makeZCFMint,
makeEmptySeatKit,

Expand Down
15 changes: 2 additions & 13 deletions packages/zoe/test/unitTests/contracts/test-sellTickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,7 @@ test(`mint and sell opera tickets`, async t => {
};

// === Final Opera part ===
const ticketSellerClosesContract = async (
sellItemsCreatorSeat,
sellItemsCreatorFacet,
) => {
const availableTickets = await E(sellItemsCreatorFacet).getAvailableItems();
const ticketIssuer = await E(sellItemsCreatorFacet).getItemsIssuer();
const ticketAmountMath = await makeLocalAmountMath(ticketIssuer);
t.truthy(
ticketAmountMath.isEmpty(availableTickets),
'All the tickets have been sold',
);

const ticketSellerClosesContract = async sellItemsCreatorSeat => {
const operaPurse = moolaIssuer.makeEmptyPurse();

const moneyPayment = await E(sellItemsCreatorSeat).getPayout('Money');
Expand Down Expand Up @@ -534,5 +523,5 @@ test(`mint and sell opera tickets`, async t => {
ticketSalesInvitation4,
moolaMint.mintPayment(moola(100)),
);
await ticketSellerClosesContract(sellItemsCreatorSeat, sellItemsCreatorFacet);
await ticketSellerClosesContract(sellItemsCreatorSeat);
});
7 changes: 3 additions & 4 deletions packages/zoe/test/unitTests/zcf/test-zcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1208,13 +1208,12 @@ test(`zcf.shutdown - userSeat exits`, async t => {
t.truthy(await E(userSeat).hasExited());
});

// TODO: Currently the zcfSeat does not exit
// https://github.com/Agoric/agoric-sdk/issues/1755
test.failing(`zcf.shutdown - zcfSeat exits`, async t => {
test(`zcf.shutdown - zcfSeat exits`, async t => {
const { zoe, zcf } = await setupZCFTest({});
const { zcfSeat, userSeat } = await makeOffer(zoe, zcf);
t.falsy(zcfSeat.hasExited());
t.falsy(await E(userSeat).hasExited());
zcf.shutdown();
// @ts-ignore
t.truthy(zcfSeat.hasExited());
t.truthy(await E(userSeat).hasExited());
});
Expand Down

0 comments on commit 2409eb5

Please sign in to comment.