diff --git a/packages/zoe/test/swingsetTests/zoe/vat-alice.js b/packages/zoe/test/swingsetTests/zoe/vat-alice.js index 774c6aa5960f..5da119354697 100644 --- a/packages/zoe/test/swingsetTests/zoe/vat-alice.js +++ b/packages/zoe/test/swingsetTests/zoe/vat-alice.js @@ -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) { @@ -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`); } diff --git a/packages/zoe/test/swingsetTests/zoe/zoe.test.js b/packages/zoe/test/swingsetTests/zoe/zoe.test.js index 70c88378ee96..c4552a7db2e9 100644 --- a/packages/zoe/test/swingsetTests/zoe/zoe.test.js +++ b/packages/zoe/test/swingsetTests/zoe/zoe.test.js @@ -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); +});