From 1d7a4f973bbad6da5fbe4bf2b9e1519d0430c1dd Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Fri, 11 Oct 2024 14:26:30 -0700 Subject: [PATCH 1/6] feat: add ability to terminate a contract with the AdminFacet --- packages/zoe/src/typeGuards.js | 1 + packages/zoe/src/zoeService/startInstance.js | 5 +++++ packages/zoe/src/zoeService/utils.d.ts | 1 + packages/zoe/test/unitTests/zoe-startInstance.test.js | 7 ++++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/zoe/src/typeGuards.js b/packages/zoe/src/typeGuards.js index a6109a34798..53afe809d9d 100644 --- a/packages/zoe/src/typeGuards.js +++ b/packages/zoe/src/typeGuards.js @@ -370,6 +370,7 @@ export const AdminFacetI = M.interface('ZcfAdminFacet', { getVatShutdownPromise: M.call().returns(M.promise()), restartContract: M.call().optional(M.any()).returns(M.promise()), upgradeContract: M.call(M.string()).optional(M.any()).returns(M.promise()), + terminateContract: M.call(M.error()).returns(M.promise()), }); export const SeatDataShape = M.splitRecord( diff --git a/packages/zoe/src/zoeService/startInstance.js b/packages/zoe/src/zoeService/startInstance.js index ae3d1487cf5..a0a1515f2a5 100644 --- a/packages/zoe/src/zoeService/startInstance.js +++ b/packages/zoe/src/zoeService/startInstance.js @@ -268,6 +268,11 @@ export const makeStartInstance = ( E(state.adminNode).upgrade(bCap, { vatParameters }), ); }, + terminateContract(reason) { + const { state } = this; + + return E(state.adminNode).terminateWithFailure(reason); + }, }, ); diff --git a/packages/zoe/src/zoeService/utils.d.ts b/packages/zoe/src/zoeService/utils.d.ts index 1b27843320c..460c0cf146b 100644 --- a/packages/zoe/src/zoeService/utils.d.ts +++ b/packages/zoe/src/zoeService/utils.d.ts @@ -46,6 +46,7 @@ export type AdminFacet = FarRef<{ restartContract: Parameters[1] extends undefined ? () => Promise : (newPrivateArgs: Parameters[1]) => Promise; + terminateContract: (Error) => void; }>; export type StartParams = SF extends ContractStartFunction diff --git a/packages/zoe/test/unitTests/zoe-startInstance.test.js b/packages/zoe/test/unitTests/zoe-startInstance.test.js index af77e291326..156db3dac1f 100644 --- a/packages/zoe/test/unitTests/zoe-startInstance.test.js +++ b/packages/zoe/test/unitTests/zoe-startInstance.test.js @@ -83,7 +83,12 @@ test('promise for installation', async t => { getStringMethodNames(result.adminFacet).filter( name => !name.startsWith('__'), ), - ['getVatShutdownPromise', 'restartContract', 'upgradeContract'], + [ + 'getVatShutdownPromise', + 'restartContract', + 'terminateContract', + 'upgradeContract', + ], ); }); From f12162a7b9b9224472c45c53ab54307dd038ee38 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Fri, 11 Oct 2024 14:27:13 -0700 Subject: [PATCH 2/6] test: cleanup: replace Object.getOwnPropertyNames() w/Object.keys() --- packages/zoe/test/unitTests/zoe-startInstance.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/zoe/test/unitTests/zoe-startInstance.test.js b/packages/zoe/test/unitTests/zoe-startInstance.test.js index 156db3dac1f..552b0cdf41f 100644 --- a/packages/zoe/test/unitTests/zoe-startInstance.test.js +++ b/packages/zoe/test/unitTests/zoe-startInstance.test.js @@ -23,7 +23,7 @@ test('bad installation', async t => { function isEmptyFacet(t, facet) { t.is(passStyleOf(facet), 'remotable'); t.deepEqual( - Object.getOwnPropertyNames(facet).filter(name => !name.startsWith('__')), + Object.keys(facet).filter(name => !name.startsWith('__')), [], ); } @@ -31,7 +31,7 @@ function isEmptyFacet(t, facet) { function facetHasMethods(t, facet, names) { t.is(passStyleOf(facet), 'remotable'); t.deepEqual( - Object.getOwnPropertyNames(facet).filter(name => !name.startsWith('__')), + Object.keys(facet).filter(name => !name.startsWith('__')), names, ); } @@ -40,7 +40,7 @@ test('no issuerKeywordRecord, no terms', async t => { const result = await setupZCFTest(); // Note that deepEqual treats all empty objects (handles) as interchangeable. t.deepEqual( - Object.getOwnPropertyNames(result.startInstanceResult) + Object.keys(result.startInstanceResult) .filter(name => !name.startsWith('__')) .sort(), [ @@ -65,7 +65,7 @@ test('promise for installation', async t => { const result = await startInstanceResult; // Note that deepEqual treats all empty objects (handles) as interchangeable. t.deepEqual( - Object.getOwnPropertyNames(result) + Object.keys(result) .filter(name => !name.startsWith('__')) .sort(), [ From 5deee288f0a382d152d19515d5b38123151f2df3 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Fri, 11 Oct 2024 17:18:37 -0700 Subject: [PATCH 3/6] test: correctly report which vats are in use --- .../zoe/test/swingsetTests/zoe/bootstrap.js | 5 ++++- .../zoe/test/swingsetTests/zoe/zoe.test.js | 18 +++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/zoe/test/swingsetTests/zoe/bootstrap.js b/packages/zoe/test/swingsetTests/zoe/bootstrap.js index a04e6bbed6d..6f87bfe669a 100644 --- a/packages/zoe/test/swingsetTests/zoe/bootstrap.js +++ b/packages/zoe/test/swingsetTests/zoe/bootstrap.js @@ -51,6 +51,7 @@ const makeVats = (log, vats, zoe, installations, startingValues) => { aliceP, bobP, }; + let logMessage = 'alice and bob'; if (carolValues) { const carolP = E(vats.carol).build( @@ -61,6 +62,7 @@ const makeVats = (log, vats, zoe, installations, startingValues) => { timer, ); result.carolP = carolP; + logMessage = 'alice, bob, and carol'; } if (daveValues) { @@ -72,9 +74,10 @@ const makeVats = (log, vats, zoe, installations, startingValues) => { timer, ); result.daveP = daveP; + logMessage = 'alice, bob, carol and dave'; } - log(`=> alice, bob, carol and dave are set up`); + log(`=> ${logMessage} are set up`); return harden(result); }; diff --git a/packages/zoe/test/swingsetTests/zoe/zoe.test.js b/packages/zoe/test/swingsetTests/zoe/zoe.test.js index 20ca2522fef..70c88378ee9 100644 --- a/packages/zoe/test/swingsetTests/zoe/zoe.test.js +++ b/packages/zoe/test/swingsetTests/zoe/zoe.test.js @@ -86,7 +86,7 @@ async function main(t, argv) { } const expectedAutomaticRefundOkLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', '=> alice.doCreateAutomaticRefund called', 'The offer was accepted', 'The offer was accepted', @@ -106,7 +106,7 @@ test.serial('zoe - automaticRefund - valid inputs', async t => { }); const expectedCoveredCallOkLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', '=> alice.doCreateCoveredCall called', '@@ schedule task for:1, currently: 0 @@', 'The option was exercised. Please collect the assets in your payout.', @@ -183,7 +183,7 @@ test.serial('zoe - secondPriceAuction - valid inputs', async t => { }); const expectedAtomicSwapOkLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', 'The offer has been accepted. Once the contract has been completed, please check your payout', 'aliceMoolaPurse: balance {"brand":{},"value":0}', 'bobMoolaPurse: balance {"brand":{},"value":3}', @@ -200,7 +200,7 @@ test.serial('zoe - atomicSwap - valid inputs', async t => { }); const expectedSimpleExchangeOkLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', 'Order Added', 'Order Added', 'bobMoolaPurse: balance {"brand":{},"value":3}', @@ -219,7 +219,7 @@ test.serial('zoe - simpleExchange - valid inputs', async t => { }); const expectedSimpleExchangeNotificationLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', '{"buys":[],"sells":[]}', '{"buys":[],"sells":[{"give":{"Asset":{"brand":{},"value":3}},"want":{"Price":{"brand":{},"value":4}}}]}', 'Order Added', @@ -253,7 +253,7 @@ test.serial('zoe - simpleExchange - state Update', async t => { }); const expectedAutoswapOkLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', 'Added liquidity.', 'simoleanAmounts {"brand":{},"value":1}', 'Swap successfully completed.', @@ -278,7 +278,7 @@ test.serial('zoe - autoswap - valid inputs', async t => { }); const expectedSellTicketsOkLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', 'availableTickets: {"brand":{},"value":[{"number":3,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":2,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":1,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', 'boughtTicketAmount: {"brand":{},"value":[{"number":1,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', 'after ticket1 purchased: {"brand":{},"value":[{"number":3,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":2,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', @@ -294,7 +294,7 @@ test.serial('zoe - sellTickets - valid inputs', async t => { }); const expectedOTCDeskOkLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', 'Inventory added', '@@ schedule task for:1, currently: 0 @@', 'The option was exercised. Please collect the assets in your payout.', @@ -313,7 +313,7 @@ test('zoe - otcDesk - valid inputs', async t => { }); const expectedBadTimerLog = [ - '=> alice, bob, carol and dave are set up', + '=> alice and bob are set up', '=> alice.doBadTimer called', 'is a zoe invitation: true', 'aliceMoolaPurse: balance {"brand":{},"value":3}', From 6fd03089b54bcfa8bc153db2dbec90a2e8ae8e1d Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Fri, 11 Oct 2024 17:19:10 -0700 Subject: [PATCH 4/6] test: add test showing adminFacet.terminateContract() kills the vat --- .../zoe/test/swingsetTests/zoe/vat-alice.js | 64 +++++++++++++++++++ .../zoe/test/swingsetTests/zoe/zoe.test.js | 15 +++++ 2 files changed, 79 insertions(+) diff --git a/packages/zoe/test/swingsetTests/zoe/vat-alice.js b/packages/zoe/test/swingsetTests/zoe/vat-alice.js index 774c6aa5960..5da11935469 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 70c88378ee9..c4552a7db2e 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); +}); From b0f08d1df09bf753131888a36d87a1c4d498b335 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Tue, 15 Oct 2024 15:42:30 -0700 Subject: [PATCH 5/6] test: use t.snapshot() rather than keeping transcript in test source --- .../zoe/snapshots/zoe.test.js.md | 194 ++++++++++++++++++ .../zoe/snapshots/zoe.test.js.snap | Bin 0 -> 1971 bytes .../zoe/test/swingsetTests/zoe/zoe.test.js | 161 +-------------- 3 files changed, 205 insertions(+), 150 deletions(-) create mode 100644 packages/zoe/test/swingsetTests/zoe/snapshots/zoe.test.js.md create mode 100644 packages/zoe/test/swingsetTests/zoe/snapshots/zoe.test.js.snap diff --git a/packages/zoe/test/swingsetTests/zoe/snapshots/zoe.test.js.md b/packages/zoe/test/swingsetTests/zoe/snapshots/zoe.test.js.md new file mode 100644 index 00000000000..ec2023c50cd --- /dev/null +++ b/packages/zoe/test/swingsetTests/zoe/snapshots/zoe.test.js.md @@ -0,0 +1,194 @@ +# Snapshot report for `test/swingsetTests/zoe/zoe.test.js` + +The actual snapshot is saved in `zoe.test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## zoe - automaticRefund - valid inputs + +> Snapshot 1 + + [ + '=> alice and bob are set up', + '=> alice.doCreateAutomaticRefund called', + 'The offer was accepted', + 'The offer was accepted', + 'bobMoolaPurse: balance {"brand":{},"value":0}', + 'bobSimoleanPurse: balance {"brand":{},"value":17}', + 'aliceMoolaPurse: balance {"brand":{},"value":3}', + 'aliceSimoleanPurse: balance {"brand":{},"value":0}', + ] + +## zoe - coveredCall - valid inputs + +> Snapshot 1 + + [ + '=> alice and bob are set up', + '=> alice.doCreateCoveredCall called', + '@@ schedule task for:1, currently: 0 @@', + 'The option was exercised. Please collect the assets in your payout.', + 'covered call was shut down due to "Swap completed."', + 'bobMoolaPurse: balance {"brand":{},"value":3}', + 'bobSimoleanPurse: balance {"brand":{},"value":0}', + 'aliceMoolaPurse: balance {"brand":{},"value":0}', + 'aliceSimoleanPurse: balance {"brand":{},"value":7}', + ] + +## zoe - swapForOption - valid inputs + +> Snapshot 1 + + [ + '=> alice, bob, carol and dave are set up', + '=> alice.doSwapForOption called', + 'call option made', + '@@ schedule task for:100, currently: 0 @@', + 'swap invitation made', + 'The offer has been accepted. Once the contract has been completed, please check your payout', + 'The option was exercised. Please collect the assets in your payout.', + 'daveMoolaPurse: balance {"brand":{},"value":3}', + 'daveSimoleanPurse: balance {"brand":{},"value":0}', + 'daveBucksPurse: balance {"brand":{},"value":0}', + 'bobMoolaPurse: balance {"brand":{},"value":0}', + 'bobSimoleanPurse: balance {"brand":{},"value":0}', + 'bobBucksPurse;: balance {"brand":{},"value":1}', + 'aliceMoolaPurse: balance {"brand":{},"value":0}', + 'aliceSimoleanPurse: balance {"brand":{},"value":7}', + ] + +## zoe - secondPriceAuction - valid inputs + +> Snapshot 1 + + [ + '=> alice, bob, carol and dave are set up', + 'Carol: The offer has been accepted. Once the contract has been completed, please check your payout', + 'Bob: The offer has been accepted. Once the contract has been completed, please check your payout', + '@@ schedule task for:1, currently: 0 @@', + 'Dave: The offer has been accepted. Once the contract has been completed, please check your payout', + '@@ tick:1 @@', + 'carolMoolaPurse: balance {"brand":{},"value":0}', + 'bobMoolaPurse: balance {"brand":{},"value":1}', + 'daveMoolaPurse: balance {"brand":{},"value":0}', + 'carolSimoleanPurse: balance {"brand":{},"value":7}', + 'bobSimoleanPurse: balance {"brand":{},"value":4}', + 'daveSimoleanPurse: balance {"brand":{},"value":5}', + 'aliceMoolaPurse: balance {"brand":{},"value":0}', + 'aliceSimoleanPurse: balance {"brand":{},"value":7}', + ] + +## zoe - atomicSwap - valid inputs + +> Snapshot 1 + + [ + '=> alice and bob are set up', + 'The offer has been accepted. Once the contract has been completed, please check your payout', + 'aliceMoolaPurse: balance {"brand":{},"value":0}', + 'bobMoolaPurse: balance {"brand":{},"value":3}', + 'aliceSimoleanPurse: balance {"brand":{},"value":7}', + 'bobSimoleanPurse: balance {"brand":{},"value":0}', + ] + +## zoe - simpleExchange - valid inputs + +> Snapshot 1 + + [ + '=> alice and bob are set up', + 'Order Added', + 'Order Added', + 'bobMoolaPurse: balance {"brand":{},"value":3}', + 'bobSimoleanPurse: balance {"brand":{},"value":3}', + 'aliceMoolaPurse: balance {"brand":{},"value":0}', + 'aliceSimoleanPurse: balance {"brand":{},"value":4}', + ] + +## zoe - simpleExchange - state Update + +> Snapshot 1 + + [ + '=> alice and bob are set up', + '{"buys":[],"sells":[]}', + '{"buys":[],"sells":[{"give":{"Asset":{"brand":{},"value":3}},"want":{"Price":{"brand":{},"value":4}}}]}', + 'Order Added', + '{"buys":[],"sells":[]}', + 'Order Added', + 'bobMoolaPurse: balance {"brand":{},"value":0}', + 'bobSimoleanPurse: balance {"brand":{},"value":20}', + '{"buys":[{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":8}}}],"sells":[]}', + 'Order Added', + 'bobMoolaPurse: balance {"brand":{},"value":3}', + 'bobSimoleanPurse: balance {"brand":{},"value":18}', + '{"buys":[{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":8}}},{"give":{"Price":{"brand":{},"value":13}},"want":{"Asset":{"brand":{},"value":20}}}],"sells":[]}', + 'Order Added', + 'bobMoolaPurse: balance {"brand":{},"value":3}', + 'bobSimoleanPurse: balance {"brand":{},"value":5}', + '{"buys":[{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":8}}},{"give":{"Price":{"brand":{},"value":13}},"want":{"Asset":{"brand":{},"value":20}}},{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":5}}}],"sells":[]}', + 'Order Added', + 'bobMoolaPurse: balance {"brand":{},"value":3}', + 'bobSimoleanPurse: balance {"brand":{},"value":3}', + 'aliceMoolaPurse: balance {"brand":{},"value":0}', + 'aliceSimoleanPurse: balance {"brand":{},"value":4}', + ] + +## zoe - autoswap - valid inputs + +> Snapshot 1 + + [ + '=> alice and bob are set up', + 'Added liquidity.', + 'simoleanAmounts {"brand":{},"value":1}', + 'Swap successfully completed.', + 'moola proceeds {"brand":{},"value":5}', + 'Swap successfully completed.', + 'bobMoolaPurse: balance {"brand":{},"value":5}', + 'bobSimoleanPurse: balance {"brand":{},"value":5}', + 'simoleans required {"brand":{},"value":5}', + 'Liquidity successfully removed.', + 'poolAmounts{"Central":{"brand":{},"value":0},"Liquidity":{"brand":{},"value":10},"Secondary":{"brand":{},"value":0}}', + 'aliceMoolaPurse: balance {"brand":{},"value":8}', + 'aliceSimoleanPurse: balance {"brand":{},"value":7}', + 'aliceLiquidityTokenPurse: balance {"brand":{},"value":0}', + ] + +## zoe - sellTickets - valid inputs + +> Snapshot 1 + + [ + '=> alice and bob are set up', + 'availableTickets: {"brand":{},"value":[{"number":3,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":2,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":1,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', + 'boughtTicketAmount: {"brand":{},"value":[{"number":1,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', + 'after ticket1 purchased: {"brand":{},"value":[{"number":3,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":2,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', + 'alice earned: {"brand":{},"value":22}', + ] + +## zoe - otcDesk - valid inputs + +> Snapshot 1 + + [ + '=> alice and bob are set up', + 'Inventory added', + '@@ schedule task for:1, currently: 0 @@', + 'The option was exercised. Please collect the assets in your payout.', + '{"brand":{},"value":3}', + '{"brand":{},"value":0}', + 'Inventory removed', + '{"brand":{},"value":2}', + ] + +## zoe - shutdown autoswap + +> Snapshot 1 + + [ + '=> alice and bob are set up', + 'vat terminated', + 'aliceMoolaPurse: balance {"brand":{},"value":0}', + 'aliceSimoleanPurse: balance {"brand":{},"value":0}', + ] diff --git a/packages/zoe/test/swingsetTests/zoe/snapshots/zoe.test.js.snap b/packages/zoe/test/swingsetTests/zoe/snapshots/zoe.test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..5695e7c8bc26ba1756122a80598fcbc0bcb1a77b GIT binary patch literal 1971 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 F004G!)t>+W literal 0 HcmV?d00001 diff --git a/packages/zoe/test/swingsetTests/zoe/zoe.test.js b/packages/zoe/test/swingsetTests/zoe/zoe.test.js index c4552a7db2e..f5e02db0117 100644 --- a/packages/zoe/test/swingsetTests/zoe/zoe.test.js +++ b/packages/zoe/test/swingsetTests/zoe/zoe.test.js @@ -85,65 +85,24 @@ async function main(t, argv) { return controller.dump(); } -const expectedAutomaticRefundOkLog = [ - '=> alice and bob are set up', - '=> alice.doCreateAutomaticRefund called', - 'The offer was accepted', - 'The offer was accepted', - 'bobMoolaPurse: balance {"brand":{},"value":0}', - 'bobSimoleanPurse: balance {"brand":{},"value":17}', - 'aliceMoolaPurse: balance {"brand":{},"value":3}', - 'aliceSimoleanPurse: balance {"brand":{},"value":0}', -]; - test.serial('zoe - automaticRefund - valid inputs', async t => { const startingValues = [ [3, 0, 0], [0, 17, 0], ]; const dump = await main(t, ['automaticRefundOk', startingValues]); - t.deepEqual(dump.log, expectedAutomaticRefundOkLog); + t.snapshot(dump.log); }); -const expectedCoveredCallOkLog = [ - '=> alice and bob are set up', - '=> alice.doCreateCoveredCall called', - '@@ schedule task for:1, currently: 0 @@', - 'The option was exercised. Please collect the assets in your payout.', - 'covered call was shut down due to "Swap completed."', - 'bobMoolaPurse: balance {"brand":{},"value":3}', - 'bobSimoleanPurse: balance {"brand":{},"value":0}', - 'aliceMoolaPurse: balance {"brand":{},"value":0}', - 'aliceSimoleanPurse: balance {"brand":{},"value":7}', -]; - test.serial('zoe - coveredCall - valid inputs', async t => { const startingValues = [ [3, 0, 0], [0, 7, 0], ]; const dump = await main(t, ['coveredCallOk', startingValues]); - t.deepEqual(dump.log, expectedCoveredCallOkLog); + t.snapshot(dump.log); }); -const expectedSwapForOptionOkLog = [ - '=> alice, bob, carol and dave are set up', - '=> alice.doSwapForOption called', - 'call option made', - '@@ schedule task for:100, currently: 0 @@', - 'swap invitation made', - 'The offer has been accepted. Once the contract has been completed, please check your payout', - 'The option was exercised. Please collect the assets in your payout.', - 'daveMoolaPurse: balance {"brand":{},"value":3}', - 'daveSimoleanPurse: balance {"brand":{},"value":0}', - 'daveBucksPurse: balance {"brand":{},"value":0}', - 'bobMoolaPurse: balance {"brand":{},"value":0}', - 'bobSimoleanPurse: balance {"brand":{},"value":0}', - 'bobBucksPurse;: balance {"brand":{},"value":1}', - 'aliceMoolaPurse: balance {"brand":{},"value":0}', - 'aliceSimoleanPurse: balance {"brand":{},"value":7}', -]; - test.serial('zoe - swapForOption - valid inputs', async t => { const startingValues = [ [3, 0, 0], // Alice starts with 3 moola @@ -152,25 +111,9 @@ test.serial('zoe - swapForOption - valid inputs', async t => { [0, 7, 1], // Dave starts with 7 simoleans and 1 buck ]; const dump = await main(t, ['swapForOptionOk', startingValues]); - t.deepEqual(dump.log, expectedSwapForOptionOkLog); + t.snapshot(dump.log); }); -const expectedSecondPriceAuctionOkLog = [ - '=> alice, bob, carol and dave are set up', - 'Carol: The offer has been accepted. Once the contract has been completed, please check your payout', - 'Bob: The offer has been accepted. Once the contract has been completed, please check your payout', - '@@ schedule task for:1, currently: 0 @@', - 'Dave: The offer has been accepted. Once the contract has been completed, please check your payout', - '@@ tick:1 @@', - 'carolMoolaPurse: balance {"brand":{},"value":0}', - 'bobMoolaPurse: balance {"brand":{},"value":1}', - 'daveMoolaPurse: balance {"brand":{},"value":0}', - 'carolSimoleanPurse: balance {"brand":{},"value":7}', - 'bobSimoleanPurse: balance {"brand":{},"value":4}', - 'daveSimoleanPurse: balance {"brand":{},"value":5}', - 'aliceMoolaPurse: balance {"brand":{},"value":0}', - 'aliceSimoleanPurse: balance {"brand":{},"value":7}', -]; test.serial('zoe - secondPriceAuction - valid inputs', async t => { const startingValues = [ [1, 0, 0], @@ -179,137 +122,61 @@ test.serial('zoe - secondPriceAuction - valid inputs', async t => { [0, 5, 0], ]; const dump = await main(t, ['secondPriceAuctionOk', startingValues]); - t.deepEqual(dump.log, expectedSecondPriceAuctionOkLog); + t.snapshot(dump.log); }); -const expectedAtomicSwapOkLog = [ - '=> alice and bob are set up', - 'The offer has been accepted. Once the contract has been completed, please check your payout', - 'aliceMoolaPurse: balance {"brand":{},"value":0}', - 'bobMoolaPurse: balance {"brand":{},"value":3}', - 'aliceSimoleanPurse: balance {"brand":{},"value":7}', - 'bobSimoleanPurse: balance {"brand":{},"value":0}', -]; test.serial('zoe - atomicSwap - valid inputs', async t => { const startingValues = [ [3, 0, 0], [0, 7, 0], ]; const dump = await main(t, ['atomicSwapOk', startingValues]); - t.deepEqual(dump.log, expectedAtomicSwapOkLog); + t.snapshot(dump.log); }); -const expectedSimpleExchangeOkLog = [ - '=> alice and bob are set up', - 'Order Added', - 'Order Added', - 'bobMoolaPurse: balance {"brand":{},"value":3}', - 'bobSimoleanPurse: balance {"brand":{},"value":3}', - 'aliceMoolaPurse: balance {"brand":{},"value":0}', - 'aliceSimoleanPurse: balance {"brand":{},"value":4}', -]; - test.serial('zoe - simpleExchange - valid inputs', async t => { const startingValues = [ [3, 0, 0], [0, 7, 0], ]; const dump = await main(t, ['simpleExchangeOk', startingValues]); - t.deepEqual(dump.log, expectedSimpleExchangeOkLog); + t.snapshot(dump.log); }); -const expectedSimpleExchangeNotificationLog = [ - '=> alice and bob are set up', - '{"buys":[],"sells":[]}', - '{"buys":[],"sells":[{"give":{"Asset":{"brand":{},"value":3}},"want":{"Price":{"brand":{},"value":4}}}]}', - 'Order Added', - '{"buys":[],"sells":[]}', - 'Order Added', - 'bobMoolaPurse: balance {"brand":{},"value":0}', - 'bobSimoleanPurse: balance {"brand":{},"value":20}', - '{"buys":[{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":8}}}],"sells":[]}', - 'Order Added', - 'bobMoolaPurse: balance {"brand":{},"value":3}', - 'bobSimoleanPurse: balance {"brand":{},"value":18}', - '{"buys":[{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":8}}},{"give":{"Price":{"brand":{},"value":13}},"want":{"Asset":{"brand":{},"value":20}}}],"sells":[]}', - 'Order Added', - 'bobMoolaPurse: balance {"brand":{},"value":3}', - 'bobSimoleanPurse: balance {"brand":{},"value":5}', - '{"buys":[{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":8}}},{"give":{"Price":{"brand":{},"value":13}},"want":{"Asset":{"brand":{},"value":20}}},{"give":{"Price":{"brand":{},"value":2}},"want":{"Asset":{"brand":{},"value":5}}}],"sells":[]}', - 'Order Added', - 'bobMoolaPurse: balance {"brand":{},"value":3}', - 'bobSimoleanPurse: balance {"brand":{},"value":3}', - 'aliceMoolaPurse: balance {"brand":{},"value":0}', - 'aliceSimoleanPurse: balance {"brand":{},"value":4}', -]; - test.serial('zoe - simpleExchange - state Update', async t => { const startingValues = [ [3, 0, 0], [0, 24, 0], ]; const dump = await main(t, ['simpleExchangeNotifier', startingValues]); - t.deepEqual(dump.log, expectedSimpleExchangeNotificationLog); + t.snapshot(dump.log); }); -const expectedAutoswapOkLog = [ - '=> alice and bob are set up', - 'Added liquidity.', - 'simoleanAmounts {"brand":{},"value":1}', - 'Swap successfully completed.', - 'moola proceeds {"brand":{},"value":5}', - 'Swap successfully completed.', - 'bobMoolaPurse: balance {"brand":{},"value":5}', - 'bobSimoleanPurse: balance {"brand":{},"value":5}', - 'simoleans required {"brand":{},"value":5}', - 'Liquidity successfully removed.', - 'poolAmounts{"Central":{"brand":{},"value":0},"Liquidity":{"brand":{},"value":10},"Secondary":{"brand":{},"value":0}}', - 'aliceMoolaPurse: balance {"brand":{},"value":8}', - 'aliceSimoleanPurse: balance {"brand":{},"value":7}', - 'aliceLiquidityTokenPurse: balance {"brand":{},"value":0}', -]; test.serial('zoe - autoswap - valid inputs', async t => { const startingValues = [ [10, 5, 0], [3, 7, 0], ]; const dump = await main(t, ['autoswapOk', startingValues]); - t.deepEqual(dump.log, expectedAutoswapOkLog); + t.snapshot(dump.log); }); -const expectedSellTicketsOkLog = [ - '=> alice and bob are set up', - 'availableTickets: {"brand":{},"value":[{"number":3,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":2,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":1,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', - 'boughtTicketAmount: {"brand":{},"value":[{"number":1,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', - 'after ticket1 purchased: {"brand":{},"value":[{"number":3,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"},{"number":2,"show":"Steven Universe, the Opera","start":"Wed, March 25th 2020 at 8pm"}]}', - 'alice earned: {"brand":{},"value":22}', -]; test.serial('zoe - sellTickets - valid inputs', async t => { const startingValues = [ [0, 0, 0], [22, 0, 0], ]; const dump = await main(t, ['sellTicketsOk', startingValues]); - t.deepEqual(dump.log, expectedSellTicketsOkLog); + t.snapshot(dump.log); }); -const expectedOTCDeskOkLog = [ - '=> alice and bob are set up', - 'Inventory added', - '@@ schedule task for:1, currently: 0 @@', - 'The option was exercised. Please collect the assets in your payout.', - '{"brand":{},"value":3}', - '{"brand":{},"value":0}', - 'Inventory removed', - '{"brand":{},"value":2}', -]; test('zoe - otcDesk - valid inputs', async t => { const startingValues = [ [10000, 10000, 10000], [10000, 10000, 10000], ]; const dump = await main(t, ['otcDeskOk', startingValues]); - t.deepEqual(dump.log, expectedOTCDeskOkLog); + t.snapshot(dump.log); }); const expectedBadTimerLog = [ @@ -330,17 +197,11 @@ test.skip('zoe - bad timer', async t => { 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); + t.snapshot(dump.log); }); From 507c9790c59d902501fff43994a9e64739185f77 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Tue, 15 Oct 2024 15:43:15 -0700 Subject: [PATCH 6/6] test: drop extraneous activity from test --- .../zoe/test/swingsetTests/zoe/vat-alice.js | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/packages/zoe/test/swingsetTests/zoe/vat-alice.js b/packages/zoe/test/swingsetTests/zoe/vat-alice.js index 5da11935469..265c9efbb74 100644 --- a/packages/zoe/test/swingsetTests/zoe/vat-alice.js +++ b/packages/zoe/test/swingsetTests/zoe/vat-alice.js @@ -549,34 +549,6 @@ const build = async (log, zoe, issuers, payments, installations, timer) => { 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')); @@ -589,16 +561,8 @@ const build = async (log, zoe, issuers, payments, installations, timer) => { 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', {