Skip to content

Commit

Permalink
test: add test showing adminFacet.terminateContract() kills the vat
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Oct 12, 2024
1 parent b55cf5e commit 8bd303e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
64 changes: 64 additions & 0 deletions packages/zoe/test/swingsetTests/zoe/vat-alice.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,67 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
await showPurseBalance(simoleanPurseP, 'aliceSimoleanPurse', log);
};

const doShutdownAutoswap = async () => {
const issuerKeywordRecord = harden({
Central: moolaIssuer,
Secondary: simoleanIssuer,
});
const { publicFacet, adminFacet } = await E(zoe).startInstance(
installations.autoswap,
issuerKeywordRecord,
);
const liquidityIssuer = await E(publicFacet).getLiquidityIssuer();
const liquidityBrand = await E(liquidityIssuer).getBrand();
const liquidity = value => AmountMath.make(liquidityBrand, value);

// Alice adds liquidity
// 10 moola = 5 simoleans at the time of the liquidity adding
// aka 2 moola = 1 simolean
const addLiquidityProposal = harden({
give: { Central: moola(10n), Secondary: simoleans(5n) },
want: { Liquidity: liquidity(10n) },
});
const paymentKeywordRecord = harden({
Central: moolaPayment,
Secondary: simoleanPayment,
});
const addLiquidityInvitation = E(publicFacet).makeAddLiquidityInvitation();
const addLiqSeatP = await E(zoe).offer(
addLiquidityInvitation,
addLiquidityProposal,
paymentKeywordRecord,
);

console.log(await E(addLiqSeatP).getOfferResult());

const liquidityPayout = await E(addLiqSeatP).getPayout('Liquidity');

const liquidityTokenPurseP = E(liquidityIssuer).makeEmptyPurse();
await E(liquidityTokenPurseP).deposit(liquidityPayout);

console.log(' ALICE terminating autoswap');
await E(adminFacet).terminateContract(Error('end of the line'));

try {
const poolAmountsPre = await E(publicFacet).getPoolAllocation();
console.log('ALICE', poolAmountsPre);
} catch (e) {
console.log('ALICE caught', e.message, e);
log(e.message);
}

// Bob is incommunicado
// await E(bobP).doAutoswap(instance);

await showPurseBalance(moolaPurseP, 'aliceMoolaPurse', log);
await showPurseBalance(simoleanPurseP, 'aliceSimoleanPurse', log);
await showPurseBalance(
liquidityTokenPurseP,
'aliceLiquidityTokenPurse',
console.log,
);
};

return Far('build', {
startTest: async (testName, bobP, carolP, daveP) => {
switch (testName) {
Expand Down Expand Up @@ -576,6 +637,9 @@ const build = async (log, zoe, issuers, payments, installations, timer) => {
case 'badTimer': {
return doBadTimer();
}
case 'shutdownAutoswap': {
return doShutdownAutoswap();
}
default: {
assert.fail(X`testName ${testName} not recognized`);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/zoe/test/swingsetTests/zoe/zoe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,18 @@ test.skip('zoe - bad timer', async t => {
const dump = await main(t, ['badTimer', startingValues]);
t.deepEqual(dump.log, expectedBadTimerLog);
});

const expectedShutdownAutoswapOkLog = [
'=> alice and bob are set up',
'vat terminated',
'aliceMoolaPurse: balance {"brand":{},"value":0}',
'aliceSimoleanPurse: balance {"brand":{},"value":0}',
];
test.serial('zoe - shutdown autoswap', async t => {
const startingValues = [
[10, 5, 0],
[3, 7, 0],
];
const dump = await main(t, ['shutdownAutoswap', startingValues]);
t.deepEqual(dump.log, expectedShutdownAutoswapOkLog);
});

0 comments on commit 8bd303e

Please sign in to comment.