From 06031cd79953ee3e4826cb69458b06cf30268d99 Mon Sep 17 00:00:00 2001 From: Kate Sills Date: Fri, 13 Aug 2021 18:43:02 -0700 Subject: [PATCH] chore: change select Zoe methods to take a feePurse (#3663) * chore: change Zoe methods to require a fee purse Co-authored-by: Mark S. Miller --- .../dapp-svelte-wallet/api/src/lib-wallet.js | 2 +- .../api/test/test-getPursesNotifier.js | 5 +- .../api/test/test-lib-wallet.js | 30 ++-- .../test/unitTests/test-install.js | 5 +- .../test/unitTests/test-offer.js | 6 +- .../test/unitTests/test-startInstance.js | 6 +- .../swingsetTests/committeeBinary/vat-zoe.js | 5 +- .../test/unitTests/test-committee.js | 8 +- packages/pegasus/test/test-peg.js | 4 +- .../demo/exchangeBenchmark/vat-zoe.js | 5 +- .../demo/swapBenchmark/vat-zoe.js | 5 +- .../swingset-runner/demo/zoeTests/vat-zoe.js | 5 +- .../treasury/test/swingsetTests/bootstrap.js | 4 +- .../treasury/test/swingsetTests/vat-zoe.js | 1 - .../treasury/test/test-bootstrapPayment.js | 12 +- packages/treasury/test/test-stablecoin.js | 9 +- packages/treasury/test/test-vault-interest.js | 9 +- packages/treasury/test/test-vault.js | 9 +- .../zoe/src/contractFacet/internal-types.js | 1 + packages/zoe/src/contractFacet/vatRoot.js | 2 + packages/zoe/src/contractFacet/zcfZygote.js | 3 +- packages/zoe/src/internal-types.js | 1 + packages/zoe/src/issuerStorage.js | 2 +- packages/zoe/src/zoeService/feePurse.js | 66 +++++++- .../zoe/src/zoeService/installationStorage.js | 11 +- .../src/zoeService/instanceAdminStorage.js | 20 ++- packages/zoe/src/zoeService/internal-types.js | 12 ++ packages/zoe/src/zoeService/offer/offer.js | 7 +- packages/zoe/src/zoeService/startInstance.js | 8 +- packages/zoe/src/zoeService/types.js | 101 ++++++++++- packages/zoe/src/zoeService/zoe.js | 29 ++-- .../zoe/src/zoeService/zoeStorageManager.js | 8 +- packages/zoe/test/autoswapJig.js | 8 +- .../swingsetTests/brokenContracts/vat-zoe.js | 5 +- .../test/swingsetTests/makeKind/vat-zoe.js | 5 +- .../test/swingsetTests/offerArgs/vat-zoe.js | 5 +- .../test/swingsetTests/privateArgs/vat-zoe.js | 5 +- .../swingsetTests/zoe-metering/vat-zoe.js | 5 +- .../zoe/test/swingsetTests/zoe/vat-zoe.js | 5 +- .../contractSupport/test-depositTo.js | 6 +- .../unitTests/contractSupport/test-offerTo.js | 6 +- .../contractSupport/test-withdrawFrom.js | 6 +- .../contracts/attestation/test-attestation.js | 4 +- .../attestation/test-exampleVotingUsage.js | 4 +- .../test/unitTests/contracts/loan/helpers.js | 2 +- .../test-multipoolAutoswap.js | 160 ++++++++++-------- .../contracts/newSwap/test-newSwap-swap.js | 102 ++++++----- .../contracts/newSwap/test-newswap-bug.js | 20 ++- .../unitTests/contracts/test-atomicSwap.js | 30 ++-- .../contracts/test-automaticRefund.js | 57 ++++--- .../test/unitTests/contracts/test-autoswap.js | 28 +-- .../test/unitTests/contracts/test-barter.js | 10 +- .../contracts/test-brokenContract.js | 9 +- .../unitTests/contracts/test-callSpread.js | 68 ++++---- .../unitTests/contracts/test-coveredCall.js | 88 +++++----- .../unitTests/contracts/test-escrowToVote.js | 6 +- .../unitTests/contracts/test-mintPayments.js | 10 +- .../test/unitTests/contracts/test-oracle.js | 4 +- .../test/unitTests/contracts/test-otcDesk.js | 20 ++- .../contracts/test-priceAggregator.js | 4 +- .../contracts/test-secondPriceAuction.js | 52 +++--- .../unitTests/contracts/test-sellTickets.js | 16 +- .../contracts/test-simpleExchange.js | 36 ++-- .../contracts/test-throwInOfferHandler.js | 4 +- .../test/unitTests/contracts/test-useObj.js | 14 +- .../zoe/test/unitTests/installFromSource.js | 3 +- .../zoe/test/unitTests/setupBasicMints.js | 7 +- .../zoe/test/unitTests/setupMixedMints.js | 5 +- .../test/unitTests/setupNonFungibleMints.js | 5 +- .../unitTests/test-bindDefaultFeePurse.js | 85 ++++++++++ packages/zoe/test/unitTests/test-makeKind.js | 6 +- .../zoe/test/unitTests/test-scriptedOracle.js | 4 +- packages/zoe/test/unitTests/test-zoe.js | 20 +-- .../zoe/test/unitTests/zcf/setupZcfTest.js | 4 +- .../test/unitTests/zcf/test-feeMintAccess.js | 4 +- packages/zoe/test/unitTests/zcf/test-zcf.js | 4 +- .../test/unitTests/zcf/test-zcfSeat-exit.js | 6 +- .../zoe/test/unitTests/zcf/test-zcfSeat.js | 6 +- .../zoe/test/unitTests/zoe/test-feePurse.js | 18 +- .../unitTests/zoe/test-installationStorage.js | 34 ++-- .../zoe/test-instanceAdminStorage.js | 18 +- 81 files changed, 957 insertions(+), 477 deletions(-) create mode 100644 packages/zoe/test/unitTests/test-bindDefaultFeePurse.js diff --git a/packages/dapp-svelte-wallet/api/src/lib-wallet.js b/packages/dapp-svelte-wallet/api/src/lib-wallet.js index 7e40719216a..cc0682f15d7 100644 --- a/packages/dapp-svelte-wallet/api/src/lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/src/lib-wallet.js @@ -55,7 +55,7 @@ const cmp = (a, b) => { /** * @typedef {Object} MakeWalletParams - * @property {ZoeService} zoe + * @property {ERef} zoe * @property {Board} board * @property {NameHub} [agoricNames] * @property {NameHub} [namesByAddress] diff --git a/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js b/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js index 93bd44c889a..b55eba6f9f9 100644 --- a/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js +++ b/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js @@ -8,6 +8,7 @@ import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import { makeBoard } from '@agoric/vats/src/lib-board.js'; // eslint-disable-next-line import/no-extraneous-dependencies import { makeNameHubKit } from '@agoric/vats/src/nameHub.js'; +import { E } from '@agoric/eventual-send'; import { Far } from '@agoric/marshal'; import { makeWallet } from '../src/lib-wallet.js'; @@ -24,7 +25,9 @@ function makeFakeMyAddressNameAdmin() { } const setup = async () => { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); const pursesStateChangeHandler = _data => {}; diff --git a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js index d7a0099d9b4..be2768c867c 100644 --- a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js @@ -7,9 +7,9 @@ import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp'; import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; +import { E } from '@agoric/eventual-send'; import { assert } from '@agoric/assert'; -import { E } from '@agoric/eventual-send'; // eslint-disable-next-line import/no-extraneous-dependencies import { makeBoard } from '@agoric/vats/src/lib-board.js'; // eslint-disable-next-line import/no-extraneous-dependencies @@ -45,7 +45,9 @@ async function setupTest() { const moolaBundle = makeIssuerKit('moola'); const simoleanBundle = makeIssuerKit('simolean'); const rpgBundle = makeIssuerKit('rpg', AssetKind.SET); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); // Create AutomaticRefund instance @@ -56,9 +58,9 @@ async function setupTest() { const automaticRefundContractRoot = new URL(automaticRefundContractUrl) .pathname; const automaticRefundBundle = await bundleSource(automaticRefundContractRoot); - const installation = await zoe.install(automaticRefundBundle); + const installation = await E(zoe).install(automaticRefundBundle); const issuerKeywordRecord = harden({ Contribution: moolaBundle.issuer }); - const { creatorInvitation: invite, instance } = await zoe.startInstance( + const { creatorInvitation: invite, instance } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -71,7 +73,7 @@ async function setupTest() { ); const autoswapContractRoot = new URL(autoswapContractUrl).pathname; const autoswapBundle = await bundleSource(autoswapContractRoot); - const autoswapInstallationHandle = await zoe.install(autoswapBundle); + const autoswapInstallationHandle = await E(zoe).install(autoswapBundle); const autoswapIssuerKeywordRecord = harden({ Central: moolaBundle.issuer, Secondary: simoleanBundle.issuer, @@ -79,7 +81,7 @@ async function setupTest() { const { publicFacet: autoswapPublicFacet, instance: autoswapInstanceHandle, - } = await zoe.startInstance( + } = await E(zoe).startInstance( autoswapInstallationHandle, autoswapIssuerKeywordRecord, ); @@ -1193,7 +1195,9 @@ test('addOffer offer.invitation', async t => { }); test('addOffer makeContinuingInvitation', async t => { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); // Create ContinuingInvitationExample instance @@ -1203,8 +1207,10 @@ test('addOffer makeContinuingInvitation', async t => { ); const path = new URL(url).pathname; const bundle = await bundleSource(path); - const installation = await zoe.install(bundle); - const { creatorInvitation, instance } = await zoe.startInstance(installation); + const installation = await E(zoe).install(bundle); + const { creatorInvitation, instance } = await E(zoe).startInstance( + installation, + ); assert(creatorInvitation); const pursesStateChangeLog = []; @@ -1275,7 +1281,9 @@ test('addOffer makeContinuingInvitation', async t => { }); test('getZoe, getBoard', async t => { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); const pursesStateChangeHandler = _data => {}; @@ -1290,6 +1298,6 @@ test('getZoe, getBoard', async t => { }); await initialized; - t.is(await E(wallet).getZoe(), zoe); + t.is(await E(wallet).getZoe(), await zoe); t.is(await E(wallet).getBoard(), board); }); diff --git a/packages/deploy-script-support/test/unitTests/test-install.js b/packages/deploy-script-support/test/unitTests/test-install.js index 9e3893c9ada..86c84a7954c 100644 --- a/packages/deploy-script-support/test/unitTests/test-install.js +++ b/packages/deploy-script-support/test/unitTests/test-install.js @@ -6,13 +6,16 @@ import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import { makeBoard } from '@agoric/vats/src/lib-board.js'; import bundleSource from '@agoric/bundle-source'; import { resolve as importMetaResolve } from 'import-meta-resolve'; +import { E } from '@agoric/eventual-send'; import '../../exported.js'; import { makeInstall } from '../../src/install.js'; test('install', async t => { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); let addedInstallation; diff --git a/packages/deploy-script-support/test/unitTests/test-offer.js b/packages/deploy-script-support/test/unitTests/test-offer.js index da44647a98e..60bf2ca7163 100644 --- a/packages/deploy-script-support/test/unitTests/test-offer.js +++ b/packages/deploy-script-support/test/unitTests/test-offer.js @@ -6,10 +6,10 @@ import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import bundleSource from '@agoric/bundle-source'; import { makeIssuerKit, AmountMath } from '@agoric/ertp'; import { resolve as importMetaResolve } from 'import-meta-resolve'; +import { E } from '@agoric/eventual-send'; import '../../exported.js'; -import { E } from '@agoric/eventual-send'; import { makeOfferAndFindInvitationAmount } from '../../src/offer.js'; test('offer', async t => { @@ -37,7 +37,9 @@ test('offer', async t => { }, saveOfferResult: () => {}, }; - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const bundleUrl = await importMetaResolve( '@agoric/zoe/src/contracts/automaticRefund.js', diff --git a/packages/deploy-script-support/test/unitTests/test-startInstance.js b/packages/deploy-script-support/test/unitTests/test-startInstance.js index 5315f75a885..c713282466c 100644 --- a/packages/deploy-script-support/test/unitTests/test-startInstance.js +++ b/packages/deploy-script-support/test/unitTests/test-startInstance.js @@ -6,10 +6,10 @@ import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import bundleSource from '@agoric/bundle-source'; import { makeIssuerKit } from '@agoric/ertp'; import { resolve as importMetaResolve } from 'import-meta-resolve'; +import { E } from '@agoric/eventual-send'; import '../../exported.js'; -import { E } from '@agoric/eventual-send'; import { makeStartInstance } from '../../src/startInstance.js'; test('startInstance', async t => { @@ -19,7 +19,9 @@ test('startInstance', async t => { const moolaKit = makeIssuerKit('moola'); const usdKit = makeIssuerKit('usd'); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const bundleUrl = new URL( await importMetaResolve( diff --git a/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js b/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js index 8b909fd3d07..7544a16749c 100644 --- a/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js +++ b/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js @@ -3,12 +3,15 @@ import { Far } from '@agoric/marshal'; import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; export function buildRootObject(vatPowers) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/governance/test/unitTests/test-committee.js b/packages/governance/test/unitTests/test-committee.js index b0f95304b9e..e39d97898a3 100644 --- a/packages/governance/test/unitTests/test-committee.js +++ b/packages/governance/test/unitTests/test-committee.js @@ -20,7 +20,9 @@ const registrarRoot = `${dirname}/../../src/committeeRegistrar.js`; const counterRoot = `${dirname}/../../src/binaryBallotCounter.js`; async function setupContract() { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const [registrarBundle, counterBundle] = await Promise.all([ @@ -29,8 +31,8 @@ async function setupContract() { ]); // install the contract const [registrarInstallation, counterInstallation] = await Promise.all([ - zoe.install(registrarBundle), - zoe.install(counterBundle), + E(zoe).install(registrarBundle), + E(zoe).install(counterBundle), ]); const terms = { committeeName: 'illuminati', committeeSize: 13 }; const registrarStartResult = await E(zoe).startInstance( diff --git a/packages/pegasus/test/test-peg.js b/packages/pegasus/test/test-peg.js index dbe4da6e7ea..fab5886e99b 100644 --- a/packages/pegasus/test/test-peg.js +++ b/packages/pegasus/test/test-peg.js @@ -47,7 +47,9 @@ async function testRemotePeg(t) { }, }); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const contractBundle = await bundleSource(contractPath); diff --git a/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js b/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js index 2834fde8fdb..e61b43d8197 100644 --- a/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js +++ b/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js @@ -3,16 +3,19 @@ import { Far } from '@agoric/marshal'; import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; export function buildRootObject(vatPowers, vatParameters) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit( + const { zoeService } = makeZoeKit( vatAdminSvc, shutdownZoeVat, vatParameters.zcfBundleName, ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js b/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js index 2834fde8fdb..e61b43d8197 100644 --- a/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js +++ b/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js @@ -3,16 +3,19 @@ import { Far } from '@agoric/marshal'; import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; export function buildRootObject(vatPowers, vatParameters) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit( + const { zoeService } = makeZoeKit( vatAdminSvc, shutdownZoeVat, vatParameters.zcfBundleName, ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/swingset-runner/demo/zoeTests/vat-zoe.js b/packages/swingset-runner/demo/zoeTests/vat-zoe.js index 2834fde8fdb..e61b43d8197 100644 --- a/packages/swingset-runner/demo/zoeTests/vat-zoe.js +++ b/packages/swingset-runner/demo/zoeTests/vat-zoe.js @@ -3,16 +3,19 @@ import { Far } from '@agoric/marshal'; import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; export function buildRootObject(vatPowers, vatParameters) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit( + const { zoeService } = makeZoeKit( vatAdminSvc, shutdownZoeVat, vatParameters.zcfBundleName, ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/treasury/test/swingsetTests/bootstrap.js b/packages/treasury/test/swingsetTests/bootstrap.js index 53cf7723c35..1dcf68c00d7 100644 --- a/packages/treasury/test/swingsetTests/bootstrap.js +++ b/packages/treasury/test/swingsetTests/bootstrap.js @@ -67,9 +67,11 @@ function makeBootstrap(argv, cb, vatPowers) { const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService( devices.vatAdmin, ); - const { zoeService: zoe, feeMintAccess } = await E(vats.zoe).buildZoe( + const { zoeService, feeMintAccess } = await E(vats.zoe).buildZoe( vatAdminSvc, ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const [liquidateMinimum, autoswap, treasury] = await Promise.all([ E(zoe).install(cb.liquidateMinimum), E(zoe).install(cb.autoswap), diff --git a/packages/treasury/test/swingsetTests/vat-zoe.js b/packages/treasury/test/swingsetTests/vat-zoe.js index c97b3132b8e..934583f2c0f 100644 --- a/packages/treasury/test/swingsetTests/vat-zoe.js +++ b/packages/treasury/test/swingsetTests/vat-zoe.js @@ -1,7 +1,6 @@ // @ts-check import { Far } from '@agoric/marshal'; - import { makeZoeKit } from '@agoric/zoe'; export function buildRootObject(vatPowers) { diff --git a/packages/treasury/test/test-bootstrapPayment.js b/packages/treasury/test/test-bootstrapPayment.js index 49f89c24d8d..93c9d0d0402 100644 --- a/packages/treasury/test/test-bootstrapPayment.js +++ b/packages/treasury/test/test-bootstrapPayment.js @@ -33,7 +33,9 @@ const makeInstall = async (root, zoe) => { }; test('bootstrap payment', async t => { - const { zoeService: zoe, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const autoswapRoot = await autoswapRootP; const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -81,7 +83,9 @@ test('bootstrap payment', async t => { }); test('bootstrap payment - only minted once', async t => { - const { zoeService: zoe, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const autoswapRoot = await autoswapRootP; const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -138,7 +142,9 @@ test('bootstrap payment - only minted once', async t => { }); test('bootstrap payment - default value is 0n', async t => { - const { zoeService: zoe, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const autoswapRoot = await autoswapRootP; const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); diff --git a/packages/treasury/test/test-stablecoin.js b/packages/treasury/test/test-stablecoin.js index 152e8b65171..6c2aee59605 100644 --- a/packages/treasury/test/test-stablecoin.js +++ b/packages/treasury/test/test-stablecoin.js @@ -55,9 +55,12 @@ const setUpZoeForTest = async setJig => { * @property {ERef} autoswap */ - const { zoeService, feeMintAccess: nonFarFeeMintAccess } = makeZoeKit( - makeFakeVatAdmin(setJig, makeRemote).admin, - ); + const { + zoeService: nonFarZoeService, + feeMintAccess: nonFarFeeMintAccess, + } = makeZoeKit(makeFakeVatAdmin(setJig, makeRemote).admin); + const feePurse = E(nonFarZoeService).makeFeePurse(); + const zoeService = await E(nonFarZoeService).bindDefaultFeePurse(feePurse); /** @type {ERef} */ const zoe = makeFar(zoeService); trace('makeZoe'); diff --git a/packages/treasury/test/test-vault-interest.js b/packages/treasury/test/test-vault-interest.js index 0d08f0e9a7b..196b1ba2e4c 100644 --- a/packages/treasury/test/test-vault-interest.js +++ b/packages/treasury/test/test-vault-interest.js @@ -39,9 +39,12 @@ const setJig = jig => { const { makeFar, makeNear: makeRemote } = makeLoopback('zoeTest'); -const { zoeService, feeMintAccess: nonFarFeeMintAccess } = makeZoeKit( - makeFakeVatAdmin(setJig, makeRemote).admin, -); +const { + zoeService: nonFarZoeService, + feeMintAccess: nonFarFeeMintAccess, +} = makeZoeKit(makeFakeVatAdmin(setJig, makeRemote).admin); +const feePurse = E(nonFarZoeService).makeFeePurse(); +const zoeService = await E(nonFarZoeService).bindDefaultFeePurse(feePurse); /** @type {ERef} */ const zoe = makeFar(zoeService); trace('makeZoe'); diff --git a/packages/treasury/test/test-vault.js b/packages/treasury/test/test-vault.js index e9a298f8576..b6d8faed469 100644 --- a/packages/treasury/test/test-vault.js +++ b/packages/treasury/test/test-vault.js @@ -37,9 +37,12 @@ const setJig = jig => { const { makeFar, makeNear: makeRemote } = makeLoopback('zoeTest'); -const { zoeService, feeMintAccess: nonFarFeeMintAccess } = makeZoeKit( - makeFakeVatAdmin(setJig, makeRemote).admin, -); +const { + zoeService: nonFarZoeService, + feeMintAccess: nonFarFeeMintAccess, +} = makeZoeKit(makeFakeVatAdmin(setJig, makeRemote).admin); +const feePurse = E(nonFarZoeService).makeFeePurse(); +const zoeService = await E(nonFarZoeService).bindDefaultFeePurse(feePurse); /** @type {ERef} */ const zoe = makeFar(zoeService); trace('makeZoe'); diff --git a/packages/zoe/src/contractFacet/internal-types.js b/packages/zoe/src/contractFacet/internal-types.js index 88367d9659e..70e1875b0ba 100644 --- a/packages/zoe/src/contractFacet/internal-types.js +++ b/packages/zoe/src/contractFacet/internal-types.js @@ -20,6 +20,7 @@ * @param {ERef} zoeService * @param {Issuer} invitationIssuer * @param {Function | undefined} testJigSetter + * @param {ERef} feePurse * @returns {ZCFZygote} */ diff --git a/packages/zoe/src/contractFacet/vatRoot.js b/packages/zoe/src/contractFacet/vatRoot.js index 2ff6bf8c546..7a045e01950 100644 --- a/packages/zoe/src/contractFacet/vatRoot.js +++ b/packages/zoe/src/contractFacet/vatRoot.js @@ -36,6 +36,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { instanceRecordFromZoe, issuerStorageFromZoe, privateArgs = undefined, + feePurse, ) => { /** @type {ZCFZygote} */ const zcfZygote = makeZCFZygote( @@ -43,6 +44,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { zoeService, invitationIssuer, testJigSetter, + feePurse, ); zcfZygote.evaluateContract(bundle); return zcfZygote.startContract( diff --git a/packages/zoe/src/contractFacet/zcfZygote.js b/packages/zoe/src/contractFacet/zcfZygote.js index 103ee2ad5f6..ccd2efb4dbc 100644 --- a/packages/zoe/src/contractFacet/zcfZygote.js +++ b/packages/zoe/src/contractFacet/zcfZygote.js @@ -29,6 +29,7 @@ export const makeZCFZygote = ( zoeService, invitationIssuer, testJigSetter, + feePurse, ) => { /** @type {PromiseRecord} */ const zoeInstanceAdminPromiseKit = makePromiseKit(); @@ -259,7 +260,7 @@ export const makeZCFZygote = ( makeEmptySeatKit, // The methods below are pure and have no side-effects // - getZoeService: () => zoeService, + getZoeService: () => E(zoeService).bindDefaultFeePurse(feePurse), getInvitationIssuer: () => invitationIssuer, getTerms, getBrandForIssuer, diff --git a/packages/zoe/src/internal-types.js b/packages/zoe/src/internal-types.js index d557b5ee412..caa8bfb9330 100644 --- a/packages/zoe/src/internal-types.js +++ b/packages/zoe/src/internal-types.js @@ -199,6 +199,7 @@ * @param {InstanceRecord} instanceRecord * @param {IssuerRecords} issuerStorageFromZoe * @param {Object=} privateArgs + * @param {ERef} feePurse * @returns {Promise} * */ diff --git a/packages/zoe/src/issuerStorage.js b/packages/zoe/src/issuerStorage.js index d5f05a7d514..31ed742c2b5 100644 --- a/packages/zoe/src/issuerStorage.js +++ b/packages/zoe/src/issuerStorage.js @@ -127,7 +127,7 @@ export const makeIssuerStorage = () => { /** * - * @param {IssuerPKeywordRecord} uncleanIssuerKeywordRecord + * @param {IssuerKeywordRecord} uncleanIssuerKeywordRecord * @returns {Promise<{ issuers: IssuerKeywordRecord, * brands: BrandKeywordRecord }>} */ diff --git a/packages/zoe/src/zoeService/feePurse.js b/packages/zoe/src/zoeService/feePurse.js index 5a3348657ac..d3d03176882 100644 --- a/packages/zoe/src/zoeService/feePurse.js +++ b/packages/zoe/src/zoeService/feePurse.js @@ -1,20 +1,23 @@ // @ts-check import { Far } from '@agoric/marshal'; +import { E } from '@agoric/eventual-send'; + +const { details: X } = assert; /** * * @param {Issuer} feeIssuer * @returns {{ - * makeFeePurse: MakeFeePurse - * isFeePurse: (feePurse: Purse) => boolean + * makeFeePurse: MakeFeePurse, + * assertFeePurse: AssertFeePurse, * }} */ const setupMakeFeePurse = feeIssuer => { const feePurses = new WeakSet(); /** @type {MakeFeePurse} */ - const makeFeePurse = () => { + const makeFeePurse = async () => { const purse = feeIssuer.makeEmptyPurse(); /** @type {FeePurse} */ const feePurse = Far('feePurse', { @@ -26,16 +29,61 @@ const setupMakeFeePurse = feeIssuer => { return feePurse; }; - /** - * @param {Purse} feePurse - */ - const isFeePurse = feePurse => feePurses.has(feePurse); + /** @type {IsFeePurse} */ + const isFeePurse = feePurse => E.when(feePurse, fp => feePurses.has(fp)); + + /** @type {AssertFeePurse} */ + const assertFeePurse = async feePurse => { + const feePurseProvided = await isFeePurse(feePurse); + assert(feePurseProvided, X`A feePurse must be provided, not ${feePurse}`); + }; return { makeFeePurse, - isFeePurse, + assertFeePurse, }; }; +const bindDefaultFeePurse = (zoeService, defaultFeePurse) => + Far('bound zoeService', { + // The functions from zoe not overridden below have no impact on + // state within Zoe + ...zoeService, + + install: (bundle, feePurse = defaultFeePurse) => + zoeService.install(bundle, feePurse), + startInstance: ( + installation, + issuerKeywordRecord, + terms, + privateArgs, + feePurse = defaultFeePurse, + ) => + zoeService.startInstance( + installation, + issuerKeywordRecord, + terms, + privateArgs, + feePurse, + ), + offer: ( + invitation, + proposal, + paymentKeywordRecord, + offerArgs, + feePurse = defaultFeePurse, + ) => + zoeService.offer( + invitation, + proposal, + paymentKeywordRecord, + offerArgs, + feePurse, + ), + getPublicFacet: (instance, feePurse = defaultFeePurse) => + zoeService.getPublicFacet(instance, feePurse), + }); + harden(setupMakeFeePurse); -export { setupMakeFeePurse }; +harden(bindDefaultFeePurse); +export { setupMakeFeePurse, bindDefaultFeePurse }; diff --git a/packages/zoe/src/zoeService/installationStorage.js b/packages/zoe/src/zoeService/installationStorage.js index 55fc6c27b63..24e1ae511f3 100644 --- a/packages/zoe/src/zoeService/installationStorage.js +++ b/packages/zoe/src/zoeService/installationStorage.js @@ -4,7 +4,11 @@ import { assert, details as X } from '@agoric/assert'; import { Far } from '@agoric/marshal'; import { E } from '@agoric/eventual-send'; -export const makeInstallationStorage = () => { +/** + * @param {AssertFeePurse} assertFeePurse + */ + +export const makeInstallationStorage = assertFeePurse => { /** @type {WeakSet} */ const installations = new WeakSet(); @@ -12,9 +16,10 @@ export const makeInstallationStorage = () => { * Create an installation by permanently storing the bundle. It will be * evaluated each time it is used to make a new instance of a contract. */ - /** @type {Install} */ - const install = bundle => { + /** @type {InstallFeePurseRequired} */ + const install = async (bundle, feePurse) => { assert.typeof(bundle, 'object', X`a bundle must be provided`); + await assertFeePurse(feePurse); /** @type {Installation} */ const installation = Far('Installation', { getBundle: () => bundle, diff --git a/packages/zoe/src/zoeService/instanceAdminStorage.js b/packages/zoe/src/zoeService/instanceAdminStorage.js index 0cf647aa3d9..3962c867983 100644 --- a/packages/zoe/src/zoeService/instanceAdminStorage.js +++ b/packages/zoe/src/zoeService/instanceAdminStorage.js @@ -2,27 +2,33 @@ import { makeWeakStore } from '@agoric/store'; -export const makeInstanceAdminStorage = () => { +/** + * @param {AssertFeePurse} assertFeePurse + */ + +export const makeInstanceAdminStorage = assertFeePurse => { /** @type {WeakStore} */ const instanceToInstanceAdmin = makeWeakStore('instance'); - /** @type {GetPublicFacet} */ - const getPublicFacet = instance => - instanceToInstanceAdmin.get(instance).getPublicFacet(); + /** @type {GetPublicFacetFeePurseRequired} */ + const getPublicFacet = async (instance, feePurse) => { + await assertFeePurse(feePurse); + return instanceToInstanceAdmin.get(instance).getPublicFacet(); + }; /** @type {GetBrands} */ - const getBrands = instance => + const getBrands = async instance => instanceToInstanceAdmin.get(instance).getBrands(); /** @type {GetIssuers} */ - const getIssuers = instance => + const getIssuers = async instance => instanceToInstanceAdmin.get(instance).getIssuers(); /** @type {GetTerms} */ const getTerms = instance => instanceToInstanceAdmin.get(instance).getTerms(); /** @type {GetInstallationForInstance} */ - const getInstallationForInstance = instance => + const getInstallationForInstance = async instance => instanceToInstanceAdmin.get(instance).getInstallationForInstance(); return harden({ diff --git a/packages/zoe/src/zoeService/internal-types.js b/packages/zoe/src/zoeService/internal-types.js index b377c41bac5..3679ff35d6d 100644 --- a/packages/zoe/src/zoeService/internal-types.js +++ b/packages/zoe/src/zoeService/internal-types.js @@ -134,3 +134,15 @@ * @param {FeeMintAccess} feeMintAccess * @returns {IssuerKit} */ + +/** + * @callback IsFeePurse + * @param {ERef} feePurse + * @returns {Promise} + */ + +/** + * @callback AssertFeePurse + * @param {ERef} feePurse + * @returns {Promise} + */ diff --git a/packages/zoe/src/zoeService/offer/offer.js b/packages/zoe/src/zoeService/offer/offer.js index 998cb728628..1d1f59cdef6 100644 --- a/packages/zoe/src/zoeService/offer/offer.js +++ b/packages/zoe/src/zoeService/offer/offer.js @@ -16,6 +16,7 @@ const { details: X, quote: q } = assert; * @param {GetInstanceAdmin} getInstanceAdmin * @param {DepositPayments} depositPayments * @param {GetAssetKindByBrand} getAssetKindByBrand + * @param {AssertFeePurse} assertFeePurse * @returns {Offer} */ export const makeOffer = ( @@ -23,13 +24,15 @@ export const makeOffer = ( getInstanceAdmin, depositPayments, getAssetKindByBrand, + assertFeePurse, ) => { - /** @type {Offer} */ + /** @type {OfferFeePurseRequired} */ const offer = async ( invitation, uncleanProposal = harden({}), paymentKeywordRecord = harden({}), offerArgs = undefined, + feePurse, ) => { const { instanceHandle, invitationHandle } = await burnInvitation( invitationIssuer, @@ -37,6 +40,8 @@ export const makeOffer = ( ); // AWAIT /// + await assertFeePurse(feePurse); + const instanceAdmin = getInstanceAdmin(instanceHandle); instanceAdmin.assertAcceptingOffers(); diff --git a/packages/zoe/src/zoeService/startInstance.js b/packages/zoe/src/zoeService/startInstance.js index d8ebb2d0549..0857bce11f9 100644 --- a/packages/zoe/src/zoeService/startInstance.js +++ b/packages/zoe/src/zoeService/startInstance.js @@ -14,20 +14,25 @@ import { handlePKitWarning } from '../handleWarning.js'; * @param {Promise} zoeServicePromise * @param {MakeZoeInstanceStorageManager} makeZoeInstanceStorageManager * @param {UnwrapInstallation} unwrapInstallation + * @param {AssertFeePurse} assertFeePurse * @returns {StartInstance} */ export const makeStartInstance = ( zoeServicePromise, makeZoeInstanceStorageManager, unwrapInstallation, + assertFeePurse, ) => { - /** @type {StartInstance} */ + /** @type {StartInstanceFeePurseRequired} */ const startInstance = async ( installationP, uncleanIssuerKeywordRecord = harden({}), customTerms = harden({}), privateArgs = undefined, + feePurse, ) => { + await assertFeePurse(feePurse); + /** @type {WeakStore} */ const seatHandleToZoeSeatAdmin = makeWeakStore('seatHandle'); @@ -211,6 +216,7 @@ export const makeStartInstance = ( zoeInstanceStorageManager.getInstanceRecord(), zoeInstanceStorageManager.getIssuerRecords(), privateArgs, + feePurse, ); handleOfferObjPromiseKit.resolve(handleOfferObj); diff --git a/packages/zoe/src/zoeService/types.js b/packages/zoe/src/zoeService/types.js index 54c729a8849..4b42bcd91b6 100644 --- a/packages/zoe/src/zoeService/types.js +++ b/packages/zoe/src/zoeService/types.js @@ -16,7 +16,7 @@ * within its vat. The contract and ZCF never have direct access to * the users' payments or the Zoe purses. * - * @property {() => Issuer} getInvitationIssuer + * @property {GetInvitationIssuer} getInvitationIssuer * * Zoe has a single `invitationIssuer` for the entirety of its * lifetime. By having a reference to Zoe, a user can get the @@ -40,11 +40,17 @@ * handle, and any custom properties specific to the contract. * @property {GetFeeIssuer} getFeeIssuer * @property {MakeFeePurse} makeFeePurse + * @property {BindDefaultFeePurse} bindDefaultFeePurse + */ + +/** + * @callback GetInvitationIssuer + * @returns {Promise} */ /** * @callback GetFeeIssuer - * @returns {Issuer} + * @returns {Promise} */ /** @@ -53,37 +59,51 @@ /** * @callback MakeFeePurse - * @returns {FeePurse} + * @returns {Promise} + */ + +/** + * @callback BindDefaultFeePurse + * @param {ERef} defaultFeePurse + * @returns {ZoeService} */ /** * @callback GetPublicFacet * @param {Instance} instance - * @returns {Object} + * @param {ERef=} feePurse + * @returns {Promise} + */ + +/** + * @callback GetPublicFacetFeePurseRequired + * @param {Instance} instance + * @param {ERef} feePurse + * @returns {Promise} */ /** * @callback GetIssuers * @param {Instance} instance - * @returns {IssuerKeywordRecord} + * @returns {Promise} */ /** * @callback GetBrands * @param {Instance} instance - * @returns {BrandKeywordRecord} + * @returns {Promise} */ /** * @callback GetTerms * @param {Instance} instance - * @returns {Terms} + * @returns {Promise} */ /** * @callback GetInstallationForInstance * @param {Instance} instance - * @returns {Installation} + * @returns {Promise} */ /** @@ -111,11 +131,23 @@ * registering it with Zoe. Returns an installation. * * @param {SourceBundle} bundle - * @returns {Installation} + * @param {ERef=} feePurse + * @returns {Promise} + */ + +/** + * @callback InstallFeePurseRequired + * + * See Install for comments. + * + * @param {SourceBundle} bundle + * @param {ERef} feePurse + * @returns {Promise} */ /** * @callback StartInstance + * * Zoe is long-lived. We can use Zoe to create smart contract * instances by specifying a particular contract installation to use, * as well as the `terms` of the contract. The `terms.issuers` is a @@ -137,6 +169,20 @@ * @param {Object=} privateArgs - an optional configuration object * that can be used to pass in arguments that should not be in the * public terms + * @param {ERef=} feePurse + * @returns {Promise} + */ + +/** + * @callback StartInstanceFeePurseRequired + * + * See StartInstance for comments. + * + * @param {ERef} installation + * @param {IssuerKeywordRecord=} issuerKeywordRecord + * @param {Object=} terms + * @param {Object=} privateArgs + * @param {ERef} feePurse * @returns {Promise} */ @@ -160,6 +206,21 @@ * @param {ERef} invitation * @param {Proposal=} proposal * @param {PaymentPKeywordRecord=} paymentKeywordRecord + * @param {Object=} offerArgs + * @param {ERef=} feePurse + * @returns {Promise} seat + */ + +/** + * @callback OfferFeePurseRequired + * + * See Offer for comments. + * + * @param {ERef} invitation + * @param {Proposal=} proposal + * @param {PaymentPKeywordRecord=} paymentKeywordRecord + * @param {Object=} offerArgs + * @param {ERef} feePurse * @returns {Promise} seat */ @@ -292,3 +353,25 @@ * @property {AssetKind} assetKind * @property {DisplayInfo} displayInfo */ + +/** + * @typedef {Object} ZoeServiceFeePurseRequired + * + * See ZoeService for further comments and explanation (not copied here). + * + * @property {GetInvitationIssuer} getInvitationIssuer + * @property {InstallFeePurseRequired} install + * @property {StartInstanceFeePurseRequired} startInstance + * @property {OfferFeePurseRequired} offer + * @property {GetPublicFacetFeePurseRequired} getPublicFacet + * @property {GetIssuers} getIssuers + * @property {GetBrands} getBrands + * @property {GetTerms} getTerms + * @property {GetInstallationForInstance} getInstallationForInstance + * @property {GetInstance} getInstance + * @property {GetInstallation} getInstallation + * @property {GetInvitationDetails} getInvitationDetails + * @property {GetFeeIssuer} getFeeIssuer + * @property {MakeFeePurse} makeFeePurse + * @property {BindDefaultFeePurse} bindDefaultFeePurse + */ diff --git a/packages/zoe/src/zoeService/zoe.js b/packages/zoe/src/zoeService/zoe.js index c4fbfb00f77..78567dea7cd 100644 --- a/packages/zoe/src/zoeService/zoe.js +++ b/packages/zoe/src/zoeService/zoe.js @@ -25,7 +25,7 @@ import { makeOffer } from './offer/offer.js'; import { makeInvitationQueryFns } from './invitationQueries.js'; import { setupCreateZCFVat } from './createZCFVat.js'; import { createFeeMint } from './feeMint.js'; -import { setupMakeFeePurse } from './feePurse.js'; +import { bindDefaultFeePurse, setupMakeFeePurse } from './feePurse.js'; /** * Create an instance of Zoe. @@ -59,7 +59,7 @@ const makeZoeKit = ( shutdownZoeVat, ); - const { makeFeePurse } = setupMakeFeePurse(feeIssuer); + const { makeFeePurse, assertFeePurse } = setupMakeFeePurse(feeIssuer); // This method contains the power to create a new ZCF Vat, and must // be closely held. vatAdminSvc is even more powerful - any vat can @@ -81,21 +81,28 @@ const makeZoeKit = ( getInstallationForInstance, getInstanceAdmin, invitationIssuer, - } = makeZoeStorageManager(createZCFVat, getFeeIssuerKit, shutdownZoeVat); + } = makeZoeStorageManager( + createZCFVat, + getFeeIssuerKit, + shutdownZoeVat, + assertFeePurse, + ); - // Pass the capabilities necessary to create zoe.startInstance + // Pass the capabilities necessary to create E(zoe).startInstance const startInstance = makeStartInstance( zoeServicePromiseKit.promise, makeZoeInstanceStorageManager, unwrapInstallation, + assertFeePurse, ); - // Pass the capabilities necessary to create zoe.offer + // Pass the capabilities necessary to create E(zoe).offer const offer = makeOffer( invitationIssuer, getInstanceAdmin, depositPayments, getAssetKindByBrand, + assertFeePurse, ); // Make the methods that allow users to easily and credibly get @@ -106,18 +113,20 @@ const makeZoeKit = ( getInvitationDetails, } = makeInvitationQueryFns(invitationIssuer); - /** @type {ZoeService} */ - const zoeService = Far('zoeService', { + /** @type {ZoeServiceFeePurseRequired} */ + const zoeService = Far('zoeServiceFeePurseRequired', { install, startInstance, offer, makeFeePurse, + bindDefaultFeePurse: defaultFeePurse => + bindDefaultFeePurse(zoeService, defaultFeePurse), + getPublicFacet, // The functions below are getters only and have no impact on // state within Zoe - getInvitationIssuer: () => invitationIssuer, - getFeeIssuer: () => feeIssuer, - getPublicFacet, + getInvitationIssuer: async () => invitationIssuer, + getFeeIssuer: async () => feeIssuer, getBrands, getIssuers, getTerms, diff --git a/packages/zoe/src/zoeService/zoeStorageManager.js b/packages/zoe/src/zoeService/zoeStorageManager.js index a68db318526..1d24d6062c7 100644 --- a/packages/zoe/src/zoeService/zoeStorageManager.js +++ b/packages/zoe/src/zoeService/zoeStorageManager.js @@ -28,12 +28,14 @@ import { makeInstallationStorage } from './installationStorage.js'; * ZCF Vat * @param {GetFeeIssuerKit} getFeeIssuerKit * @param {ShutdownWithFailure} shutdownZoeVat + * @param {AssertFeePurse} assertFeePurse * @returns {ZoeStorageManager} */ export const makeZoeStorageManager = ( createZCFVat, getFeeIssuerKit, shutdownZoeVat, + assertFeePurse, ) => { // issuerStorage contains the issuers that the ZoeService knows // about, as well as information about them such as their brand, @@ -66,12 +68,14 @@ export const makeZoeStorageManager = ( getInstanceAdmin, initInstanceAdmin, deleteInstanceAdmin, - } = makeInstanceAdminStorage(); + } = makeInstanceAdminStorage(assertFeePurse); // Zoe stores "installations" - identifiable bundles of contract // code that can be reused again and again to create new contract // instances - const { install, unwrapInstallation } = makeInstallationStorage(); + const { install, unwrapInstallation } = makeInstallationStorage( + assertFeePurse, + ); /** @type {MakeZoeInstanceStorageManager} */ const makeZoeInstanceStorageManager = async ( diff --git a/packages/zoe/test/autoswapJig.js b/packages/zoe/test/autoswapJig.js index 80e13b21fad..79324117a7e 100644 --- a/packages/zoe/test/autoswapJig.js +++ b/packages/zoe/test/autoswapJig.js @@ -134,7 +134,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { const invitation = swapIn ? E(publicFacet).makeSwapInInvitation() : E(publicFacet).makeSwapOutInvitation(); - const seat = await zoe.offer(invitation, proposal, payment); + const seat = await E(zoe).offer(invitation, proposal, payment); return seat; }, @@ -248,7 +248,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { Secondary: withdrawPayment(sAmount), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeAddLiquidityInvitation(), proposal, payment, @@ -330,7 +330,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { Liquidity: withdrawPayment(lAmount), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeRemoveLiquidityInvitation(), proposal, payment, @@ -396,7 +396,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { Secondary: withdrawPayment(sAmount), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( await E(publicFacet).makeAddLiquidityInvitation(), proposal, payment, diff --git a/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js b/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js index 7be7dd02e4b..a78d5f8fb20 100644 --- a/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js @@ -1,6 +1,7 @@ // @ts-check import { Far } from '@agoric/marshal'; +import { E } from '@agoric/eventual-send'; // noinspection ES6PreferShortImport import { makeZoeKit } from '../../../src/zoeService/zoe.js'; @@ -9,7 +10,9 @@ export function buildRootObject(vatPowers) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js b/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js index 7be7dd02e4b..a78d5f8fb20 100644 --- a/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js @@ -1,6 +1,7 @@ // @ts-check import { Far } from '@agoric/marshal'; +import { E } from '@agoric/eventual-send'; // noinspection ES6PreferShortImport import { makeZoeKit } from '../../../src/zoeService/zoe.js'; @@ -9,7 +10,9 @@ export function buildRootObject(vatPowers) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js b/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js index 7be7dd02e4b..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js @@ -3,13 +3,16 @@ import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport +import { E } from '@agoric/eventual-send'; import { makeZoeKit } from '../../../src/zoeService/zoe.js'; export function buildRootObject(vatPowers) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js b/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js index 7be7dd02e4b..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js @@ -3,13 +3,16 @@ import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport +import { E } from '@agoric/eventual-send'; import { makeZoeKit } from '../../../src/zoeService/zoe.js'; export function buildRootObject(vatPowers) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js b/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js index 7be7dd02e4b..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js @@ -3,13 +3,16 @@ import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport +import { E } from '@agoric/eventual-send'; import { makeZoeKit } from '../../../src/zoeService/zoe.js'; export function buildRootObject(vatPowers) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/zoe/test/swingsetTests/zoe/vat-zoe.js b/packages/zoe/test/swingsetTests/zoe/vat-zoe.js index 7be7dd02e4b..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/zoe/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/zoe/vat-zoe.js @@ -3,13 +3,16 @@ import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport +import { E } from '@agoric/eventual-send'; import { makeZoeKit } from '../../../src/zoeService/zoe.js'; export function buildRootObject(vatPowers) { return Far('root', { buildZoe: vatAdminSvc => { const shutdownZoeVat = vatPowers.exitVatWithFailure; - const { zoeService: zoe } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return zoe; }, }); diff --git a/packages/zoe/test/unitTests/contractSupport/test-depositTo.js b/packages/zoe/test/unitTests/contractSupport/test-depositTo.js index d56214e9685..952197a2bdb 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-depositTo.js +++ b/packages/zoe/test/unitTests/contractSupport/test-depositTo.js @@ -23,12 +23,14 @@ async function setupContract(moolaIssuer, bucksIssuer) { const setJig = jig => { testJig = jig; }; - const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/contractSupport/test-offerTo.js b/packages/zoe/test/unitTests/contractSupport/test-offerTo.js index 330ce62a17d..fbdef48a265 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-offerTo.js +++ b/packages/zoe/test/unitTests/contractSupport/test-offerTo.js @@ -27,12 +27,14 @@ const setupContract = async (moolaIssuer, bucksIssuer) => { const setJig = jig => { instanceToZCF.set(jig.instance, jig.zcf); }; - const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Create TWO instances of the zcfTesterContract which have // different keywords diff --git a/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js b/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js index 9c904b2fc3c..15ee170ed73 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js +++ b/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js @@ -27,12 +27,14 @@ async function setupContract(moolaIssuer, bucksIssuer) { const setJig = jig => { testJig = jig; }; - const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js b/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js index 10157d75136..080e06cdf2f 100644 --- a/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js +++ b/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js @@ -22,7 +22,9 @@ const attestationRoot = `${dirname}/../../../../src/contracts/attestation/attest test('attestation contract basic tests', async t => { const bundle = await bundleSource(attestationRoot); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const installation = await E(zoe).install(bundle); const bldIssuerKit = makeIssuerKit('BLD', AssetKind.NAT, { diff --git a/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js b/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js index e866afafa0f..f17c75b3549 100644 --- a/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js +++ b/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js @@ -23,7 +23,9 @@ const exampleVotingUsageRoot = `${dirname}/exampleVotingUsage.js`; test('exampleVotingUsage', async t => { const bundle = await bundleSource(exampleVotingUsageRoot); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const installation = await E(zoe).install(bundle); const bldIssuerKit = makeIssuerKit('BLD', AssetKind.NAT, { diff --git a/packages/zoe/test/unitTests/contracts/loan/helpers.js b/packages/zoe/test/unitTests/contracts/loan/helpers.js index 72c77d8c3af..8374c3a45aa 100644 --- a/packages/zoe/test/unitTests/contracts/loan/helpers.js +++ b/packages/zoe/test/unitTests/contracts/loan/helpers.js @@ -225,7 +225,7 @@ export const makeAutoswapInstance = async ( ), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeAddLiquidityInvitation(), proposal, payment, diff --git a/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js b/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js index 144f45e0771..98c5e78192e 100644 --- a/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js +++ b/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js @@ -33,8 +33,10 @@ const multipoolAutoswapRoot = `${dirname}/../../../../src/contracts/multipoolAut test('multipoolAutoSwap with valid offers', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -56,10 +58,10 @@ test('multipoolAutoSwap with valid offers', async t => { // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30); - const { instance, publicFacet } = await zoe.startInstance( + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer }, @@ -68,7 +70,7 @@ test('multipoolAutoSwap with valid offers', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -108,7 +110,7 @@ test('multipoolAutoSwap with valid offers', async t => { publicFacet, ).getPriceAuthorities(moolaR.brand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -143,7 +145,7 @@ test('multipoolAutoSwap with valid offers', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -193,8 +195,10 @@ test('multipoolAutoSwap with valid offers', async t => { const { value: [bobInvitationValue], - } = await invitationIssuer.getAmountOf(bobSwapInvitation1); - const bobPublicFacet = await zoe.getPublicFacet(bobInvitationValue.instance); + } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); + const bobPublicFacet = await E(zoe).getPublicFacet( + bobInvitationValue.instance, + ); t.is( bobInvitationValue.installation, @@ -220,7 +224,7 @@ test('multipoolAutoSwap with valid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -285,7 +289,7 @@ test('multipoolAutoSwap with valid offers', async t => { In: await E(bobCentralPurse).withdraw(centralTokens(7)), }); - const bobSeat2 = await zoe.offer( + const bobSeat2 = await E(zoe).offer( bobSwapInvitation2, bobCentralForMoolaProposal, centralForMoolaPayments, @@ -350,7 +354,7 @@ test('multipoolAutoSwap with valid offers', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -437,7 +441,7 @@ test('multipoolAutoSwap with valid offers', async t => { In: bobSimoleanPayment, }); - const bobSeat3 = await zoe.offer( + const bobSeat3 = await E(zoe).offer( bobThirdInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, @@ -501,7 +505,7 @@ test('multipoolAutoSwap with valid offers', async t => { want: { Secondary: moola(91), Central: centralTokens(56) }, }); - const aliceSeat3 = await zoe.offer( + const aliceSeat3 = await E(zoe).offer( aliceRemoveLiquidityInvitation, aliceRemoveLiquidityProposal, harden({ Liquidity: liquidityPayout }), @@ -546,8 +550,10 @@ test('multipoolAutoSwap with valid offers', async t => { test('multipoolAutoSwap get detailed prices', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -565,8 +571,8 @@ test('multipoolAutoSwap get detailed prices', async t => { // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); - const { instance, publicFacet } = await zoe.startInstance( + const installation = await E(zoe).install(bundle); + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -574,7 +580,7 @@ test('multipoolAutoSwap get detailed prices', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -621,7 +627,7 @@ test('multipoolAutoSwap get detailed prices', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -667,7 +673,7 @@ test('multipoolAutoSwap get detailed prices', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -728,8 +734,10 @@ test('multipoolAutoSwap get detailed prices', async t => { test('multipoolAutoSwap with some invalid offers', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Set up central token const centralR = makeIssuerKit('central'); @@ -743,8 +751,8 @@ test('multipoolAutoSwap with some invalid offers', async t => { // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); - const { publicFacet } = await zoe.startInstance( + const installation = await E(zoe).install(bundle); + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -755,8 +763,8 @@ test('multipoolAutoSwap with some invalid offers', async t => { const { value: [bobInvitationValue], - } = await invitationIssuer.getAmountOf(bobSwapInvitation1); - const bobPublicFacet = zoe.getPublicFacet(bobInvitationValue.instance); + } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); + const bobPublicFacet = E(zoe).getPublicFacet(bobInvitationValue.instance); // Bob tries to look up prices, but the pool isn't initiailzed await t.throwsAsync( @@ -773,7 +781,7 @@ test('multipoolAutoSwap with some invalid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const failedSeat = await zoe.offer( + const failedSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -789,11 +797,13 @@ test('multipoolAutoSwap with some invalid offers', async t => { test('multipoolAutoSwap jig - addLiquidity', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -806,7 +816,7 @@ test('multipoolAutoSwap jig - addLiquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -911,7 +921,7 @@ test('multipoolAutoSwap jig - addLiquidity', async t => { }); const invite = E(publicFacet).makeAddLiquidityInvitation(); - const seat = zoe.offer(invite, proposal, payment); + const seat = E(zoe).offer(invite, proposal, payment); await t.throwsAsync( () => E(seat).getOfferResult(), { message: 'insufficient Secondary deposited' }, @@ -923,11 +933,13 @@ test('multipoolAutoSwap jig - addLiquidity', async t => { test('multipoolAutoSwap jig - check liquidity', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -940,7 +952,7 @@ test('multipoolAutoSwap jig - check liquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1058,11 +1070,13 @@ test('multipoolAutoSwap jig - check liquidity', async t => { test('multipoolAutoSwap jig - swapOut', async t => { const { moolaR, moola, simoleanR, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1077,7 +1091,7 @@ test('multipoolAutoSwap jig - swapOut', async t => { const simoleanPurse = simoleanR.issuer.makeEmptyPurse(); simoleanPurse.deposit(simoleanR.mint.mintPayment(simoleans(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1270,11 +1284,13 @@ test('multipoolAutoSwap jig - swapOut', async t => { test('multipoolAutoSwap jig - swapOut uneven', async t => { const { moolaR, moola, simoleanR, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1289,7 +1305,7 @@ test('multipoolAutoSwap jig - swapOut uneven', async t => { const simoleanPurse = simoleanR.issuer.makeEmptyPurse(); simoleanPurse.deposit(simoleanR.mint.mintPayment(simoleans(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1452,11 +1468,13 @@ test('multipoolAutoSwap jig - swapOut uneven', async t => { test('multipoolAutoSwap jig - removeLiquidity', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1469,7 +1487,7 @@ test('multipoolAutoSwap jig - removeLiquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1564,11 +1582,13 @@ test('multipoolAutoSwap jig - removeLiquidity', async t => { test('multipoolAutoSwap jig - removeLiquidity ask for too much', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1581,7 +1601,7 @@ test('multipoolAutoSwap jig - removeLiquidity ask for too much', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1660,11 +1680,13 @@ test('multipoolAutoSwap jig - removeLiquidity ask for too much', async t => { test('multipoolAutoSwap jig - remove all liquidity', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1677,7 +1699,7 @@ test('multipoolAutoSwap jig - remove all liquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1755,11 +1777,13 @@ test('multipoolAutoSwap jig - remove all liquidity', async t => { test('multipoolAutoSwap jig - insufficient', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1772,7 +1796,7 @@ test('multipoolAutoSwap jig - insufficient', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1849,15 +1873,17 @@ test('multipoolAutoSwap jig - insufficient', async t => { }); test('multipoolAutoSwap collect empty fees', async t => { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const centralR = makeIssuerKit('central'); const centralTokens = value => AmountMath.make(value, centralR.brand); const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30); - const { publicFacet, creatorFacet } = await zoe.startInstance( + const { publicFacet, creatorFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer }, @@ -1866,7 +1892,7 @@ test('multipoolAutoSwap collect empty fees', async t => { creatorFacet, ).makeCollectFeesInvitation(); - const feeSeat = await zoe.offer(aliceCollectFeesInvitation); + const feeSeat = await E(zoe).offer(aliceCollectFeesInvitation); t.deepEqual(await E(feeSeat).getCurrentAllocation(), {}); await assertAmountsEqual( @@ -1881,8 +1907,10 @@ test('multipoolAutoSwap collect empty fees', async t => { test('multipoolAutoSwap swapout secondary to secondary', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -1900,10 +1928,10 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { // Alice creates an autoswap instance const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30); - const { instance, publicFacet } = await zoe.startInstance( + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer }, @@ -1912,7 +1940,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -1951,7 +1979,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { publicFacet, ).getPriceAuthorities(moolaR.brand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -1976,7 +2004,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -2017,7 +2045,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { Central: aliceCentralPayment2, }; - const aliceAddLiquiditySeat2 = await zoe.offer( + const aliceAddLiquiditySeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -2057,7 +2085,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { In: bobSimoleanPayment, }); - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, diff --git a/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js b/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js index 764248ea867..71226196560 100644 --- a/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js +++ b/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js @@ -37,8 +37,10 @@ const newSwapRoot = `${dirname}/../../../../src/contracts/newSwap/multipoolAutos test('newSwap with valid offers', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -59,10 +61,10 @@ test('newSwap with valid offers', async t => { // Pack the contract. const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30n); - const { instance, publicFacet } = await zoe.startInstance( + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -71,7 +73,7 @@ test('newSwap with valid offers', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -110,7 +112,7 @@ test('newSwap with valid offers', async t => { publicFacet, ).getPriceAuthorities(moolaR.brand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -145,7 +147,7 @@ test('newSwap with valid offers', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -176,10 +178,12 @@ test('newSwap with valid offers', async t => { // Bob creates a swap invitation for himself const bobSwapInvitation1 = await E(publicFacet).makeSwapInInvitation(); - const { value } = await invitationIssuer.getAmountOf(bobSwapInvitation1); + const { value } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); assert(Array.isArray(value)); const [bobInvitationValue] = value; - const bobPublicFacet = await zoe.getPublicFacet(bobInvitationValue.instance); + const bobPublicFacet = await E(zoe).getPublicFacet( + bobInvitationValue.instance, + ); t.is( bobInvitationValue.installation, @@ -201,7 +205,7 @@ test('newSwap with valid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -276,7 +280,7 @@ test('newSwap with valid offers', async t => { In: await E(bobCentralPurse).withdraw(centralTokens(700)), }); - const bobSeat2 = await zoe.offer( + const bobSeat2 = await E(zoe).offer( bobSwapInvitation2, bobCentralForMoolaProposal, centralForMoolaPayments, @@ -348,7 +352,7 @@ test('newSwap with valid offers', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -390,7 +394,9 @@ test('newSwap with valid offers', async t => { test('newSwap doubleSwap', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Set up central token const centralR = makeIssuerKit('central'); @@ -409,17 +415,17 @@ test('newSwap doubleSwap', async t => { // Alice creates an autoswap instance const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30n); - const { - instance, - publicFacet, - creatorFacet, - } = await zoe.startInstance( + const { instance, publicFacet, creatorFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), - { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, + { + timer: fakeTimer, + poolFee: 24n, + protocolFee: 6n, + }, ); const aliceAddLiquidityInvitation = E( publicFacet, @@ -441,7 +447,7 @@ test('newSwap doubleSwap', async t => { const simoleanLiquidity = value => AmountMath.make(value, simoleanLiquidityBrand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -476,7 +482,7 @@ test('newSwap doubleSwap', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -508,7 +514,7 @@ test('newSwap doubleSwap', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -538,7 +544,7 @@ test('newSwap doubleSwap', async t => { t.deepEqual(await E(publicFacet).getProtocolPoolBalance(), {}); - const bobSeat1 = await zoe.offer( + const bobSeat1 = await E(zoe).offer( bobInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, @@ -572,7 +578,7 @@ test('newSwap doubleSwap', async t => { In: bobMoolaPayment, }); - const bobSeat2 = await zoe.offer( + const bobSeat2 = await E(zoe).offer( bobInvitation2, bobMoolaForSimsProposal, moolaForSimsPayments, @@ -594,7 +600,7 @@ test('newSwap doubleSwap', async t => { }); const collectFeesInvitation = E(creatorFacet).makeCollectFeesInvitation(); - const collectFeesSeat = await zoe.offer( + const collectFeesSeat = await E(zoe).offer( collectFeesInvitation, undefined, undefined, @@ -611,8 +617,10 @@ test('newSwap doubleSwap', async t => { test('newSwap with some invalid offers', async t => { const { moolaR, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Set up central token const centralR = makeIssuerKit('central'); @@ -627,8 +635,8 @@ test('newSwap with some invalid offers', async t => { const bundle = await bundleSource(newSwapRoot); const fakeTimer = buildManualTimer(console.log); - const installation = await zoe.install(bundle); - const { publicFacet } = await zoe.startInstance( + const installation = await E(zoe).install(bundle); + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -638,10 +646,10 @@ test('newSwap with some invalid offers', async t => { // Bob creates a swap invitation for himself const bobSwapInvitation1 = await E(publicFacet).makeSwapInInvitation(); - const { value } = await invitationIssuer.getAmountOf(bobSwapInvitation1); + const { value } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); assert(Array.isArray(value)); const [bobInvitationValue] = value; - const bobPublicFacet = zoe.getPublicFacet(bobInvitationValue.instance); + const bobPublicFacet = E(zoe).getPublicFacet(bobInvitationValue.instance); // Bob tries to look up prices, but the pool isn't initiailzed await t.throwsAsync( @@ -658,7 +666,7 @@ test('newSwap with some invalid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const failedSeat = await zoe.offer( + const failedSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -674,11 +682,13 @@ test('newSwap with some invalid offers', async t => { test('newSwap jig - swapOut uneven', async t => { const { moolaR, moola, simoleanR, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -694,7 +704,7 @@ test('newSwap jig - swapOut uneven', async t => { simoleanPurse.deposit(simoleanR.mint.mintPayment(simoleans(20000000))); const fakeTimer = buildManualTimer(console.log); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -889,7 +899,7 @@ test('newSwap jig - swapOut uneven', async t => { mPoolState = updatePoolState(mPoolState, expectedC); const collectFeesInvitation = E(creatorFacet).makeCollectFeesInvitation(); - const collectFeesSeat = await zoe.offer( + const collectFeesSeat = await E(zoe).offer( collectFeesInvitation, undefined, undefined, @@ -911,11 +921,13 @@ test('newSwap jig - swapOut uneven', async t => { test('newSwap jig - breaking scenario', async t => { const { moolaR, moola, simoleanR } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -931,7 +943,7 @@ test('newSwap jig - breaking scenario', async t => { moolaPurse.deposit(moolaR.mint.mintPayment(moola(2396247730468n + 4145005n))); const fakeTimer = buildManualTimer(console.log); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -1028,7 +1040,9 @@ test('newSwap jig - breaking scenario', async t => { // This demonstrates that Zoe can reallocate empty amounts. i.e. that // https://github.com/Agoric/agoric-sdk/issues/3033 stays fixed test('zoe allow empty reallocations', async t => { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Set up central token const { issuer, brand } = makeIssuerKit('central'); @@ -1036,17 +1050,17 @@ test('zoe allow empty reallocations', async t => { // Alice creates an autoswap instance const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30n); - const { creatorFacet } = await zoe.startInstance( + const { creatorFacet } = await E(zoe).startInstance( installation, harden({ Central: issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, ); const collectFeesInvitation2 = E(creatorFacet).makeCollectFeesInvitation(); - const collectFeesSeat2 = await zoe.offer( + const collectFeesSeat2 = await E(zoe).offer( collectFeesInvitation2, undefined, undefined, diff --git a/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js b/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js index 2953912b929..71f98e147d0 100644 --- a/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js +++ b/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js @@ -36,14 +36,16 @@ test('test bug scenario', async t => { AssetKind.NAT, harden({ decimalPlaces: 6 }), ); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const fakeTimer = buildManualTimer(console.log, 30n); - const { publicFacet } = await zoe.startInstance( + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: runKit.issuer }), { @@ -75,7 +77,7 @@ test('test bug scenario', async t => { Central: runKit.mint.mintPayment(runPoolAllocation), }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -123,14 +125,16 @@ const conductTrade = async (t, reduceWantOutBP = 30n) => { AssetKind.NAT, harden({ decimalPlaces: 6 }), ); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const fakeTimer = buildManualTimer(console.log, 30n); - const { publicFacet } = await zoe.startInstance( + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: runKit.issuer }), { @@ -162,7 +166,7 @@ const conductTrade = async (t, reduceWantOutBP = 30n) => { Central: runKit.mint.mintPayment(runPoolAllocation), }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, diff --git a/packages/zoe/test/unitTests/contracts/test-atomicSwap.js b/packages/zoe/test/unitTests/contracts/test-atomicSwap.js index 76ab96be9d1..712c6e69217 100644 --- a/packages/zoe/test/unitTests/contracts/test-atomicSwap.js +++ b/packages/zoe/test/unitTests/contracts/test-atomicSwap.js @@ -37,7 +37,7 @@ test('zoe - atomicSwap', async t => { Asset: moolaKit.issuer, Price: simoleanKit.issuer, }); - const adminP = zoe.startInstance(installation, issuerKeywordRecord); + const adminP = E(zoe).startInstance(installation, issuerKeywordRecord); return adminP; }, offer: async firstInvitation => { @@ -91,7 +91,7 @@ test('zoe - atomicSwap', async t => { // Bob is able to use the trusted invitationIssuer from Zoe to // transform an untrusted invitation that Alice also has access to, to // an - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -116,7 +116,7 @@ test('zoe - atomicSwap', async t => { }); const payments = { Price: simoleanPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -199,7 +199,7 @@ test('zoe - non-fungible atomicSwap', async t => { Asset: ccIssuer, Price: rpgIssuer, }); - const adminP = zoe.startInstance(installation, issuerKeywordRecord); + const adminP = E(zoe).startInstance(installation, issuerKeywordRecord); return adminP; }, offer: async (firstInvitation, calico37Amount, vorpalAmount) => { @@ -210,7 +210,7 @@ test('zoe - non-fungible atomicSwap', async t => { }); const payments = { Asset: aliceCcPayment }; - const seat = await zoe.offer(firstInvitation, proposal, payments); + const seat = await E(zoe).offer(firstInvitation, proposal, payments); seat .getPayout('Asset') @@ -253,7 +253,7 @@ test('zoe - non-fungible atomicSwap', async t => { // Bob is able to use the trusted invitationIssuer from Zoe to // transform an untrusted invitation that Alice also has access to, to // an - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( @@ -279,7 +279,7 @@ test('zoe - non-fungible atomicSwap', async t => { }); const payments = { Price: rpgPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -340,12 +340,12 @@ test('zoe - non-fungible atomicSwap', async t => { test('zoe - atomicSwap like-for-like', async t => { t.plan(13); const { moolaIssuer, moolaMint, moola, zoe } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // pack the contract const bundle = await bundleSource(atomicSwapRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceMoolaPayment = moolaMint.mintPayment(moola(3)); @@ -360,7 +360,7 @@ test('zoe - atomicSwap like-for-like', async t => { Asset: moolaIssuer, Price: moolaIssuer, }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -374,7 +374,7 @@ test('zoe - atomicSwap like-for-like', async t => { const alicePayments = { Asset: aliceMoolaPayment }; // 3: Alice makes the first offer in the swap. - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -385,12 +385,14 @@ test('zoe - atomicSwap like-for-like', async t => { // counter-party. const bobInvitationP = E(aliceSeat).getOfferResult(); - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitationP); + const bobExclusiveInvitation = await E(invitationIssuer).claim( + bobInvitationP, + ); const bobInvitationValue = await E(zoe).getInvitationDetails( bobExclusiveInvitation, ); - const bobIssuers = zoe.getIssuers(bobInvitationValue.instance); + const bobIssuers = await E(zoe).getIssuers(bobInvitationValue.instance); t.is(bobInvitationValue.installation, installation, 'bobInstallationId'); t.deepEqual(bobIssuers, { Asset: moolaIssuer, Price: moolaIssuer }); @@ -405,7 +407,7 @@ test('zoe - atomicSwap like-for-like', async t => { const bobPayments = { Price: bobMoolaPayment }; // 5: Bob makes an offer - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobProposal, bobPayments, diff --git a/packages/zoe/test/unitTests/contracts/test-automaticRefund.js b/packages/zoe/test/unitTests/contracts/test-automaticRefund.js index 0ebee954e27..5b0ff10e19a 100644 --- a/packages/zoe/test/unitTests/contracts/test-automaticRefund.js +++ b/packages/zoe/test/unitTests/contracts/test-automaticRefund.js @@ -20,14 +20,14 @@ test('zoe - simplest automaticRefund', async t => { const { moolaR, moola, zoe } = setup(); // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceMoolaPayment = moolaR.mint.mintPayment(moola(3)); // 1: Alice creates an automatic refund instance const issuerKeywordRecord = harden({ Contribution: moolaR.issuer }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -38,7 +38,11 @@ test('zoe - simplest automaticRefund', async t => { }); const alicePayments = { Contribution: aliceMoolaPayment }; - const seat = await zoe.offer(creatorInvitation, aliceProposal, alicePayments); + const seat = await E(zoe).offer( + creatorInvitation, + aliceProposal, + alicePayments, + ); const aliceMoolaPayout = await seat.getPayout('Contribution'); @@ -95,7 +99,7 @@ test('zoe with automaticRefund', async t => { t.plan(11); // Setup zoe and mints const { moolaR, simoleanR, moola, simoleans, zoe } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Setup Alice const aliceMoolaPayment = moolaR.mint.mintPayment(moola(3)); @@ -111,15 +115,14 @@ test('zoe with automaticRefund', async t => { const bundle = await bundleSource(automaticRefundRoot); // 1: Alice creates an automatic refund instance - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Contribution1: moolaR.issuer, Contribution2: simoleanR.issuer, }); - const { - creatorInvitation: aliceInvitation, - publicFacet, - } = await zoe.startInstance(installation, issuerKeywordRecord); + const { creatorInvitation: aliceInvitation, publicFacet } = await E( + zoe, + ).startInstance(installation, issuerKeywordRecord); // 2: Alice escrows with zoe const aliceProposal = harden({ @@ -134,7 +137,7 @@ test('zoe with automaticRefund', async t => { // In the 'automaticRefund' trivial contract, you just get your // payments back when you make an offer. The offerResult is simply // the string 'The offer was accepted' - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -148,7 +151,7 @@ test('zoe with automaticRefund', async t => { // will do a claim on the invitation with the Zoe invitation issuer and // will check that the installation and terms match what he // expects - const exclusBobInvitation = await invitationIssuer.claim(bobInvitation); + const exclusBobInvitation = await E(invitationIssuer).claim(bobInvitation); const { value: [bobInvitationValue], @@ -173,7 +176,7 @@ test('zoe with automaticRefund', async t => { const bobPayments = { Contribution2: bobSimoleanPayment }; // Bob also gets a seat back - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( exclusBobInvitation, bobProposal, bobPayments, @@ -241,7 +244,7 @@ test('multiple instances of automaticRefund for the same Zoe', async t => { // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ ContributionA: moolaR.issuer, ContributionB: simoleanR.issuer, @@ -249,36 +252,36 @@ test('multiple instances of automaticRefund for the same Zoe', async t => { const { creatorInvitation: aliceInvitation1, publicFacet: publicFacet1, - } = await zoe.startInstance(installation, issuerKeywordRecord); + } = await E(zoe).startInstance(installation, issuerKeywordRecord); const { creatorInvitation: aliceInvitation2, publicFacet: publicFacet2, - } = await zoe.startInstance(installation, issuerKeywordRecord); + } = await E(zoe).startInstance(installation, issuerKeywordRecord); const { creatorInvitation: aliceInvitation3, publicFacet: publicFacet3, - } = await zoe.startInstance(installation, issuerKeywordRecord); + } = await E(zoe).startInstance(installation, issuerKeywordRecord); const aliceProposal = harden({ give: { ContributionA: moola(10) }, want: { ContributionB: simoleans(7) }, }); - const seat1 = await zoe.offer( + const seat1 = await E(zoe).offer( aliceInvitation1, aliceProposal, harden({ ContributionA: aliceMoolaPayments[0] }), ); - const seat2 = await zoe.offer( + const seat2 = await E(zoe).offer( aliceInvitation2, aliceProposal, harden({ ContributionA: aliceMoolaPayments[1] }), ); - const seat3 = await zoe.offer( + const seat3 = await E(zoe).offer( aliceInvitation3, aliceProposal, harden({ ContributionA: aliceMoolaPayments[2] }), @@ -320,12 +323,12 @@ test('zoe - alice tries to complete after completion has already occurred', asyn // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ ContributionA: moolaR.issuer, ContributionB: simoleanR.issuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -336,7 +339,7 @@ test('zoe - alice tries to complete after completion has already occurred', asyn }); const alicePayments = { ContributionA: aliceMoolaPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -377,14 +380,14 @@ test('zoe - automaticRefund non-fungible', async t => { // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceCcPayment = ccMint.mintPayment(cryptoCats(harden(['tigger']))); // 1: Alice creates an automatic refund instance const issuerKeywordRecord = harden({ Contribution: ccIssuer }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -395,7 +398,11 @@ test('zoe - automaticRefund non-fungible', async t => { }); const alicePayments = { Contribution: aliceCcPayment }; - const seat = await zoe.offer(creatorInvitation, aliceProposal, alicePayments); + const seat = await E(zoe).offer( + creatorInvitation, + aliceProposal, + alicePayments, + ); const aliceCcPayout = await seat.getPayout('Contribution'); diff --git a/packages/zoe/test/unitTests/contracts/test-autoswap.js b/packages/zoe/test/unitTests/contracts/test-autoswap.js index c7f74aa3852..39345c04688 100644 --- a/packages/zoe/test/unitTests/contracts/test-autoswap.js +++ b/packages/zoe/test/unitTests/contracts/test-autoswap.js @@ -35,7 +35,7 @@ test('autoSwap API interactions, no jig', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, autoswap); // Setup Alice @@ -52,7 +52,7 @@ test('autoSwap API interactions, no jig', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -74,7 +74,7 @@ test('autoSwap API interactions, no jig', async t => { Secondary: aliceSimoleanPayment, }; const aliceInvitation = await publicFacet.makeAddLiquidityInvitation(); - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -97,7 +97,7 @@ test('autoSwap API interactions, no jig', async t => { const bobInvitation = await E(publicFacet).makeSwapInvitation(); // Bob claims it - const bobExclInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclInvitation = await E(invitationIssuer).claim(bobInvitation); const bobInstance = await E(zoe).getInstance(bobExclInvitation); const bobInstallation = await E(zoe).getInstallation(bobExclInvitation); t.is(bobInstallation, installation, `installation`); @@ -117,7 +117,7 @@ test('autoSwap API interactions, no jig', async t => { }); const bobMoolaForSimPayments = harden({ In: bobMoolaPayment }); - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclInvitation, bobMoolaForSimProposal, bobMoolaForSimPayments, @@ -160,7 +160,7 @@ test('autoSwap API interactions, no jig', async t => { }); const simsForMoolaPayments = harden({ In: bobSimoleanPayment }); - const bobSecondSeat = await zoe.offer( + const bobSecondSeat = await E(zoe).offer( bobSecondInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, @@ -195,7 +195,7 @@ test('autoSwap API interactions, no jig', async t => { want: { Central: moola(0n), Secondary: simoleans(0) }, }); - const aliceRmLiqSeat = await zoe.offer( + const aliceRmLiqSeat = await E(zoe).offer( aliceSecondInvitation, aliceRemoveLiquidityProposal, harden({ Liquidity: liquidityPayout }), @@ -235,7 +235,7 @@ test('autoSwap - thorough jig test init, add, swap', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -353,7 +353,7 @@ test('autoSwap jig - add liquidity in exact ratio', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -446,7 +446,7 @@ test('autoSwap - trade attempt before init, no jig', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -463,7 +463,7 @@ test('autoSwap - trade attempt before init, no jig', async t => { }); const payment = harden({ In: moolaPurse.withdraw(inAmount) }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeSwapInInvitation(), proposal, payment, @@ -501,7 +501,7 @@ test('autoSwap jig - swap varying amounts', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -649,7 +649,7 @@ test('autoSwap price quote for zero', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -671,7 +671,7 @@ test('autoSwap price quote for zero', async t => { Secondary: aliceSimoleanPayment, }; const aliceInvitation = await publicFacet.makeAddLiquidityInvitation(); - await zoe.offer(aliceInvitation, aliceProposal, alicePayments); + await E(zoe).offer(aliceInvitation, aliceProposal, alicePayments); const simoleanAmounts = await E(publicFacet).getInputPrice( moola(0), diff --git a/packages/zoe/test/unitTests/contracts/test-barter.js b/packages/zoe/test/unitTests/contracts/test-barter.js index 99b97384133..0a71aba480c 100644 --- a/packages/zoe/test/unitTests/contracts/test-barter.js +++ b/packages/zoe/test/unitTests/contracts/test-barter.js @@ -27,7 +27,7 @@ test('barter with valid offers', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, barter); // Setup Alice @@ -38,7 +38,7 @@ test('barter with valid offers', async t => { // 1: Simon creates a barter instance and spreads the instance far and // wide with instructions on how to use it. - const { instance } = await zoe.startInstance(installation, { + const { instance } = await E(zoe).startInstance(installation, { Asset: moolaIssuer, Price: simoleanIssuer, }); @@ -57,7 +57,7 @@ test('barter with valid offers', async t => { }); const alicePayments = { In: aliceMoolaPayment }; // 3: Alice adds her sell order to the exchange - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceSellOrderProposal, alicePayments, @@ -72,7 +72,7 @@ test('barter with valid offers', async t => { const bobInstallation = await E(zoe).getInstallation(bobInvitation); // 4: Bob decides to join. - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); t.is(bobInstallation, installation); t.is(bobInstance, instance); @@ -87,7 +87,7 @@ test('barter with valid offers', async t => { const bobPayments = { In: bobSimoleanPayment }; // 5: Bob escrows with zoe - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobBuyOrderProposal, bobPayments, diff --git a/packages/zoe/test/unitTests/contracts/test-brokenContract.js b/packages/zoe/test/unitTests/contracts/test-brokenContract.js index 54d50892fab..21859726b6a 100644 --- a/packages/zoe/test/unitTests/contracts/test-brokenContract.js +++ b/packages/zoe/test/unitTests/contracts/test-brokenContract.js @@ -6,6 +6,7 @@ import path from 'path'; // eslint-disable-next-line import/no-extraneous-dependencies import bundleSource from '@agoric/bundle-source'; +import { E } from '@agoric/eventual-send'; // noinspection ES6PreferShortImport import { makeZoeKit } from '../../../src/zoeService/zoe.js'; @@ -21,17 +22,19 @@ test('zoe - brokenAutomaticRefund', async t => { t.plan(1); // Setup zoe and mints const { moolaR } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Contribution: moolaR.issuer }); // Alice tries to create an instance, but the contract is badly // written. await t.throwsAsync( - () => zoe.startInstance(installation, issuerKeywordRecord), + () => E(zoe).startInstance(installation, issuerKeywordRecord), { message: 'The contract did not correctly return a creatorInvitation' }, 'startInstance should have thrown', ); diff --git a/packages/zoe/test/unitTests/contracts/test-callSpread.js b/packages/zoe/test/unitTests/contracts/test-callSpread.js index f3958985d56..93f43b913fd 100644 --- a/packages/zoe/test/unitTests/contracts/test-callSpread.js +++ b/packages/zoe/test/unitTests/contracts/test-callSpread.js @@ -86,7 +86,7 @@ test('fundedCallSpread below Strike1', async t => { brands.get('moola'), ), }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -101,7 +101,7 @@ test('fundedCallSpread below Strike1', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -111,11 +111,11 @@ test('fundedCallSpread below Strike1', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit(t, bobPayout, bobBucksPurse, bucks(0)); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -177,7 +177,7 @@ test('fundedCallSpread above Strike2', async t => { Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -192,7 +192,7 @@ test('fundedCallSpread above Strike2', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -202,7 +202,7 @@ test('fundedCallSpread above Strike2', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -211,7 +211,7 @@ test('fundedCallSpread above Strike2', async t => { bucks(300), ); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -272,7 +272,7 @@ test('fundedCallSpread, mid-strike', async t => { Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -287,7 +287,7 @@ test('fundedCallSpread, mid-strike', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -297,7 +297,7 @@ test('fundedCallSpread, mid-strike', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -306,7 +306,7 @@ test('fundedCallSpread, mid-strike', async t => { bucks(225), ); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -367,7 +367,7 @@ test('fundedCallSpread, late exercise', async t => { Collateral: bucksIssuer, Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -384,7 +384,7 @@ test('fundedCallSpread, late exercise', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -394,7 +394,7 @@ test('fundedCallSpread, late exercise', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -407,7 +407,7 @@ test('fundedCallSpread, late exercise', async t => { await E(manualTimer).tick(); await E(manualTimer).tick(); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = await carolOptionSeat.getPayout('Collateral'); const carolDepositAmount = await E(carolBucksPurse).deposit(carolPayout); await t.deepEqual( @@ -466,7 +466,7 @@ test('fundedCallSpread, sell options', async t => { Collateral: bucksIssuer, Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -481,7 +481,7 @@ test('fundedCallSpread, sell options', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -495,7 +495,7 @@ test('fundedCallSpread, sell options', async t => { zoe, simpleExchange, ); - const { publicFacet: exchangePublic } = await zoe.startInstance( + const { publicFacet: exchangePublic } = await E(zoe).startInstance( exchangeInstallation, { Asset: invitationIssuer, @@ -509,9 +509,13 @@ test('fundedCallSpread, sell options', async t => { give: { Asset: longOptionAmount }, want: { Price: bucks(200) }, }); - const aliceSellLongSeat = await zoe.offer(aliceLongInvitation, proposalLong, { - Asset: longOption, - }); + const aliceSellLongSeat = await E(zoe).offer( + aliceLongInvitation, + proposalLong, + { + Asset: longOption, + }, + ); const aliceLong = assertPayoutDeposit( t, aliceSellLongSeat.getPayout('Price'), @@ -525,7 +529,7 @@ test('fundedCallSpread, sell options', async t => { give: { Asset: shortOptionAmount }, want: { Price: bucks(100) }, }); - const aliceSellShortSeat = await zoe.offer( + const aliceSellShortSeat = await E(zoe).offer( aliceShortInvitation, proposalShort, { Asset: shortOption }, @@ -543,7 +547,7 @@ test('fundedCallSpread, sell options', async t => { give: { Price: bucks(200) }, want: { Asset: longOptionAmount }, }); - const bobBuySeat = await zoe.offer(bobLongInvitation, bobProposal, { + const bobBuySeat = await E(zoe).offer(bobLongInvitation, bobProposal, { Price: bobBucksPayment, }); const longInvitationPayout = await bobBuySeat.getPayout('Asset'); @@ -553,7 +557,7 @@ test('fundedCallSpread, sell options', async t => { longInvitationPayout, longOptionAmount, ); - const bobOptionSeat = await zoe.offer(longInvitationPayout); + const bobOptionSeat = await E(zoe).offer(longInvitationPayout); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -568,7 +572,7 @@ test('fundedCallSpread, sell options', async t => { give: { Price: bucks(100) }, want: { Asset: shortOptionAmount }, }); - const carolBuySeat = await zoe.offer(carolShortInvitation, carolProposal, { + const carolBuySeat = await E(zoe).offer(carolShortInvitation, carolProposal, { Price: carolBucksPayment, }); const ShortInvitationPayout = await carolBuySeat.getPayout('Asset'); @@ -578,7 +582,7 @@ test('fundedCallSpread, sell options', async t => { ShortInvitationPayout, shortOptionAmount, ); - const carolOptionSeat = await zoe.offer(ShortInvitationPayout); + const carolOptionSeat = await E(zoe).offer(ShortInvitationPayout); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -641,7 +645,7 @@ test('pricedCallSpread, mid-strike', async t => { Collateral: bucksIssuer, Strike: moolaIssuer, }); - const { creatorFacet } = await zoe.startInstance( + const { creatorFacet } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -662,12 +666,12 @@ test('pricedCallSpread, mid-strike', async t => { want: { Option: longOption }, give: { Collateral: bucks(longOptionValue.collateral) }, }); - const bobFundingSeat = await zoe.offer(await longInvitation, bobProposal, { + const bobFundingSeat = await E(zoe).offer(await longInvitation, bobProposal, { Collateral: bobBucksPayment, }); // bob gets an option, and exercises it for the payout const bobOption = await bobFundingSeat.getPayout('Option'); - const bobOptionSeat = await zoe.offer(bobOption); + const bobOptionSeat = await E(zoe).offer(bobOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( @@ -686,7 +690,7 @@ test('pricedCallSpread, mid-strike', async t => { want: { Option: shortOption }, give: { Collateral: bucks(shortOptionValue.collateral) }, }); - const carolFundingSeat = await zoe.offer( + const carolFundingSeat = await E(zoe).offer( await shortInvitation, carolProposal, { @@ -695,7 +699,7 @@ test('pricedCallSpread, mid-strike', async t => { ); // carol gets an option, and exercises it for the payout const carolOption = await carolFundingSeat.getPayout('Option'); - const carolOptionSeat = await zoe.offer(carolOption); + const carolOptionSeat = await E(zoe).offer(carolOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( diff --git a/packages/zoe/test/unitTests/contracts/test-coveredCall.js b/packages/zoe/test/unitTests/contracts/test-coveredCall.js index 9d902f63bb2..e8596b302ac 100644 --- a/packages/zoe/test/unitTests/contracts/test-coveredCall.js +++ b/packages/zoe/test/unitTests/contracts/test-coveredCall.js @@ -51,7 +51,7 @@ test('zoe - coveredCall', async t => { Simoleans: simoleanKit.issuer, Bucks: bucksKit.issuer, }); - const adminP = zoe.startInstance(installation, issuerKeywordRecord); + const adminP = E(zoe).startInstance(installation, issuerKeywordRecord); return adminP; }, offer: async createCallOptionInvitation => { @@ -228,7 +228,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a const { moolaR, simoleanR, moola, simoleans, zoe } = setup(); // Pack the contract. const bundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(bundle); + const coveredCallInstallation = await E(zoe).install(bundle); const timer = buildManualTimer(console.log); // Setup Alice @@ -246,7 +246,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a UnderlyingAsset: moolaR.issuer, StrikePrice: simoleanR.issuer, }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( coveredCallInstallation, issuerKeywordRecord, ); @@ -264,7 +264,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a }); const alicePayments = { UnderlyingAsset: aliceMoolaPayment }; // Alice makes an option - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -280,8 +280,8 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a // contract instance that he expects as well as that Alice has // already escrowed. - const invitationIssuer = zoe.getInvitationIssuer(); - const bobExclOption = await invitationIssuer.claim(optionP); + const invitationIssuer = await E(zoe).getInvitationIssuer(); + const bobExclOption = await E(invitationIssuer).claim(optionP); const optionValue = await E(zoe).getInvitationDetails(bobExclOption); t.is(optionValue.installation, coveredCallInstallation); t.is(optionValue.description, 'exerciseOption'); @@ -298,7 +298,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a }); // Bob escrows - const bobSeat = await zoe.offer(bobExclOption, bobProposal, bobPayments); + const bobSeat = await E(zoe).offer(bobExclOption, bobProposal, bobPayments); // TODO is this await safe? await t.throwsAsync( @@ -350,10 +350,10 @@ test('zoe - coveredCall with swap for invitation', async t => { // Pack the contract. const coveredCallBundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(coveredCallBundle); + const coveredCallInstallation = await E(zoe).install(coveredCallBundle); const atomicSwapBundle = await bundleSource(atomicSwapRoot); - const swapInstallationId = await zoe.install(atomicSwapBundle); + const swapInstallationId = await E(zoe).install(atomicSwapBundle); // Setup Alice // Alice starts with 3 moola @@ -380,7 +380,7 @@ test('zoe - coveredCall with swap for invitation', async t => { UnderlyingAsset: moolaR.issuer, StrikePrice: simoleanR.issuer, }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( coveredCallInstallation, issuerKeywordRecord, ); @@ -404,7 +404,7 @@ test('zoe - coveredCall with swap for invitation', async t => { }); const alicePayments = { UnderlyingAsset: aliceMoolaPayment }; // Alice makes an option. - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -420,10 +420,10 @@ test('zoe - coveredCall with swap for invitation', async t => { // party in the covered call: Did the covered call use the // expected covered call installation (code)? Does it use the issuers // that he expects (moola and simoleans)? - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); - const bobExclOption = await invitationIssuer.claim(optionP); - const optionAmount = await invitationIssuer.getAmountOf(bobExclOption); + const bobExclOption = await E(invitationIssuer).claim(optionP); + const optionAmount = await E(invitationIssuer).getAmountOf(bobExclOption); const optionDesc = optionAmount.value[0]; t.is(optionDesc.installation, coveredCallInstallation); t.is(optionDesc.description, 'exerciseOption'); @@ -438,7 +438,7 @@ test('zoe - coveredCall with swap for invitation', async t => { Asset: invitationIssuer, Price: bucksR.issuer, }); - const { creatorInvitation: bobSwapInvitation } = await zoe.startInstance( + const { creatorInvitation: bobSwapInvitation } = await E(zoe).startInstance( swapInstallationId, swapIssuerKeywordRecord, ); @@ -446,7 +446,7 @@ test('zoe - coveredCall with swap for invitation', async t => { // Bob wants to swap an invitation with the same amount as his // current invitation from Alice. He wants 1 buck in return. const bobProposalSwap = harden({ - give: { Asset: await invitationIssuer.getAmountOf(bobExclOption) }, + give: { Asset: await E(invitationIssuer).getAmountOf(bobExclOption) }, want: { Price: bucks(1) }, }); @@ -454,7 +454,7 @@ test('zoe - coveredCall with swap for invitation', async t => { // Bob escrows his option in the swap // Bob makes an offer to the swap with his "higher order" invitation - const bobSwapSeat = await zoe.offer( + const bobSwapSeat = await E(zoe).offer( bobSwapInvitation, bobProposalSwap, bobPayments, @@ -467,9 +467,9 @@ test('zoe - coveredCall with swap for invitation', async t => { const { value: [{ instance: swapInstance, installation: daveSwapInstallId }], - } = await invitationIssuer.getAmountOf(daveSwapInvitationP); + } = await E(invitationIssuer).getAmountOf(daveSwapInvitationP); - const daveSwapIssuers = zoe.getIssuers(swapInstance); + const daveSwapIssuers = await E(zoe).getIssuers(swapInstance); // Dave is looking to buy the option to trade his 7 simoleans for // 3 moola, and is willing to pay 1 buck for the option. He @@ -502,7 +502,7 @@ test('zoe - coveredCall with swap for invitation', async t => { }); const daveSwapPayments = harden({ Price: daveBucksPayment }); - const daveSwapSeat = await zoe.offer( + const daveSwapSeat = await E(zoe).offer( daveSwapInvitationP, daveSwapProposal, daveSwapPayments, @@ -526,7 +526,7 @@ test('zoe - coveredCall with swap for invitation', async t => { const daveCoveredCallPayments = harden({ StrikePrice: daveSimoleanPayment, }); - const daveCoveredCallSeat = await zoe.offer( + const daveCoveredCallSeat = await E(zoe).offer( daveOption, daveCoveredCallProposal, daveCoveredCallPayments, @@ -561,7 +561,7 @@ test('zoe - coveredCall with swap for invitation', async t => { ); t.deepEqual( - await invitationIssuer.getAmountOf(bobInvitationPayout), + await E(invitationIssuer).getAmountOf(bobInvitationPayout), AmountMath.makeEmpty(invitationBrand, AssetKind.SET), ); t.deepEqual(await bucksR.issuer.getAmountOf(bobBucksPayout), bucks(1)); @@ -603,7 +603,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Pack the contract. const bundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(bundle); + const coveredCallInstallation = await E(zoe).install(bundle); // Setup Alice // Alice starts with 3 moola @@ -630,9 +630,9 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { UnderlyingAsset: moolaR.issuer, StrikePrice: simoleanR.issuer, }); - const { - creatorInvitation: aliceCoveredCallInvitation, - } = await zoe.startInstance(coveredCallInstallation, issuerKeywordRecord); + const { creatorInvitation: aliceCoveredCallInvitation } = await E( + zoe, + ).startInstance(coveredCallInstallation, issuerKeywordRecord); // Alice escrows with Zoe. She specifies her proposal, // which include what she wants and gives as well as the exit @@ -654,7 +654,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { const alicePayments = { UnderlyingAsset: aliceMoolaPayment }; // Alice makes a call option, which is an invitation to join the // covered call contract - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceCoveredCallInvitation, aliceProposal, alicePayments, @@ -670,8 +670,8 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // party in the covered call: Did the covered call use the // expected covered call installation (code)? Does it use the issuers // that he expects (moola and simoleans)? - const invitationIssuer = zoe.getInvitationIssuer(); - const bobExclOption = await invitationIssuer.claim(optionP); + const invitationIssuer = await E(zoe).getInvitationIssuer(); + const bobExclOption = await E(invitationIssuer).claim(optionP); const optionValue = await E(zoe).getInvitationDetails(bobExclOption); t.is(optionValue.installation, coveredCallInstallation); t.is(optionValue.description, 'exerciseOption'); @@ -686,15 +686,15 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { UnderlyingAsset: invitationIssuer, StrikePrice: bucksR.issuer, }); - const { - creatorInvitation: bobInvitationForSecondCoveredCall, - } = await zoe.startInstance(coveredCallInstallation, issuerKeywordRecord2); + const { creatorInvitation: bobInvitationForSecondCoveredCall } = await E( + zoe, + ).startInstance(coveredCallInstallation, issuerKeywordRecord2); // Bob wants to swap an invitation with the same amount as his // current invitation from Alice. He wants 1 buck in return. const bobProposalSecondCoveredCall = harden({ give: { - UnderlyingAsset: await invitationIssuer.getAmountOf(bobExclOption), + UnderlyingAsset: await E(invitationIssuer).getAmountOf(bobExclOption), }, want: { StrikePrice: bucks(1) }, exit: { @@ -709,7 +709,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Bob escrows his invitation // Bob makes an offer to the swap with his "higher order" option - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobInvitationForSecondCoveredCall, bobProposalSecondCoveredCall, bobPayments, @@ -722,7 +722,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Dave is looking to buy the option to trade his 7 simoleans for // 3 moola, and is willing to pay 1 buck for the option. He // checks that this invitation matches what he wants - const daveExclOption = await invitationIssuer.claim(invitationForDaveP); + const daveExclOption = await E(invitationIssuer).claim(invitationForDaveP); const daveOptionValue = await E(zoe).getInvitationDetails(daveExclOption); t.is(daveOptionValue.installation, coveredCallInstallation); t.is(daveOptionValue.description, 'exerciseOption'); @@ -759,7 +759,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Dave escrows his 1 buck with Zoe and forms his proposal const daveSecondCoveredCallPayments = { StrikePrice: daveBucksPayment }; - const daveSecondCoveredCallSeat = await zoe.offer( + const daveSecondCoveredCallSeat = await E(zoe).offer( daveExclOption, daveProposalCoveredCall, daveSecondCoveredCallPayments, @@ -787,7 +787,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { const daveFirstCoveredCallPayments = harden({ StrikePrice: daveSimoleanPayment, }); - const daveFirstCoveredCallSeat = await zoe.offer( + const daveFirstCoveredCallSeat = await E(zoe).offer( firstCoveredCallInvitation, daveFirstCoveredCallProposal, daveFirstCoveredCallPayments, @@ -829,7 +829,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { const invitationBrand = await E(invitationIssuer).getBrand(); t.deepEqual( - await invitationIssuer.getAmountOf(bobInvitationPayout), + await E(invitationIssuer).getAmountOf(bobInvitationPayout), AmountMath.makeEmpty(invitationBrand, AssetKind.SET), ); t.deepEqual(await bucksR.issuer.getAmountOf(bobBucksPayout), bucks(1)); @@ -875,7 +875,7 @@ test('zoe - coveredCall non-fungible', async t => { // install the contract. const bundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(bundle); + const coveredCallInstallation = await E(zoe).install(bundle); const timer = buildManualTimer(console.log); // Setup Alice @@ -902,7 +902,7 @@ test('zoe - coveredCall non-fungible', async t => { StrikePrice: rpgIssuer, }); // separate issuerKeywordRecord from contract-specific terms - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( coveredCallInstallation, issuerKeywordRecord, ); @@ -915,7 +915,7 @@ test('zoe - coveredCall non-fungible', async t => { }); const alicePayments = { UnderlyingAsset: aliceCcPayment }; // Alice creates a call option - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -929,8 +929,8 @@ test('zoe - coveredCall non-fungible', async t => { // contract instance that he expects as well as that Alice has // already escrowed. - const invitationIssuer = zoe.getInvitationIssuer(); - const bobExclOption = await invitationIssuer.claim(optionP); + const invitationIssuer = await E(zoe).getInvitationIssuer(); + const bobExclOption = await E(invitationIssuer).claim(optionP); const optionValue = await E(zoe).getInvitationDetails(bobExclOption); t.is(optionValue.installation, coveredCallInstallation); t.is(optionValue.description, 'exerciseOption'); @@ -957,7 +957,7 @@ test('zoe - coveredCall non-fungible', async t => { // Bob redeems his invitation and escrows with Zoe // Bob exercises the option - const bobSeat = await zoe.offer(bobExclOption, bobProposal, bobPayments); + const bobSeat = await E(zoe).offer(bobExclOption, bobProposal, bobPayments); t.is( await E(bobSeat).getOfferResult(), diff --git a/packages/zoe/test/unitTests/contracts/test-escrowToVote.js b/packages/zoe/test/unitTests/contracts/test-escrowToVote.js index 14f4cfd80b0..f3cd4f5bd64 100644 --- a/packages/zoe/test/unitTests/contracts/test-escrowToVote.js +++ b/packages/zoe/test/unitTests/contracts/test-escrowToVote.js @@ -20,12 +20,14 @@ const contractRoot = `${dirname}/escrowToVote.js`; test('zoe - escrowToVote', async t => { t.plan(14); const { moolaIssuer, moolaMint, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance and acts as the Secretary const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/contracts/test-mintPayments.js b/packages/zoe/test/unitTests/contracts/test-mintPayments.js index 907f0d3df37..c6ec8d7dcde 100644 --- a/packages/zoe/test/unitTests/contracts/test-mintPayments.js +++ b/packages/zoe/test/unitTests/contracts/test-mintPayments.js @@ -19,7 +19,9 @@ const mintPaymentsRoot = `${dirname}/../../../src/contracts/mintPayments.js`; test('zoe - mint payments', async t => { t.plan(2); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const makeAlice = () => { return { @@ -31,7 +33,7 @@ test('zoe - mint payments', async t => { return installationP; }, startInstance: async installation => { - const adminP = zoe.startInstance(installation); + const adminP = E(zoe).startInstance(installation); return adminP; }, }; @@ -87,7 +89,9 @@ test('zoe - mint payments', async t => { test('zoe - mint payments with unrelated give and want', async t => { t.plan(3); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const moolaKit = makeIssuerKit('moola'); const simoleanKit = makeIssuerKit('simolean'); diff --git a/packages/zoe/test/unitTests/contracts/test-oracle.js b/packages/zoe/test/unitTests/contracts/test-oracle.js index 807cce3c16d..6ed753da7d7 100644 --- a/packages/zoe/test/unitTests/contracts/test-oracle.js +++ b/packages/zoe/test/unitTests/contracts/test-oracle.js @@ -37,7 +37,9 @@ test.before( /** @param {ExecutionContext} ot */ async ot => { // Outside of tests, we should use the long-lived Zoe on the // testnet. In this test, we must create a new Zoe. - const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin().admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin().admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const contractBundle = await bundleSource(contractPath); diff --git a/packages/zoe/test/unitTests/contracts/test-otcDesk.js b/packages/zoe/test/unitTests/contracts/test-otcDesk.js index 74737c3cc0a..67fa5e4c1d8 100644 --- a/packages/zoe/test/unitTests/contracts/test-otcDesk.js +++ b/packages/zoe/test/unitTests/contracts/test-otcDesk.js @@ -133,7 +133,7 @@ const makeBob = ( return Far('Bob', { offerOk: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -160,7 +160,7 @@ const makeBob = ( const simoleanPayment1 = simoleanPurse.withdraw(simoleans(4)); const payments = { Whatever1: simoleanPayment1 }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -184,7 +184,7 @@ const makeBob = ( }, offerExpired: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -211,7 +211,11 @@ const makeBob = ( const simoleanPayment1 = simoleanPurse.withdraw(simoleans(4)); const payments = { Whatever1: simoleanPayment1 }; - const offerExpiredSeat = await zoe.offer(invitation, proposal, payments); + const offerExpiredSeat = await E(zoe).offer( + invitation, + proposal, + payments, + ); await t.throwsAsync(() => E(offerExpiredSeat).getOfferResult(), { message: 'The covered call option is expired.', @@ -234,7 +238,7 @@ const makeBob = ( }, offerWantTooMuch: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -265,7 +269,7 @@ const makeBob = ( Whatever2: moola35Payment, }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); await t.throwsAsync(() => E(seat).getOfferResult(), { message: @@ -296,7 +300,7 @@ const makeBob = ( }, offerNotCovered: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -331,7 +335,7 @@ const makeBob = ( Whatever2: moola35Payment, }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); await t.throwsAsync(() => E(seat).getOfferResult(), { message: diff --git a/packages/zoe/test/unitTests/contracts/test-priceAggregator.js b/packages/zoe/test/unitTests/contracts/test-priceAggregator.js index 8d848665c86..7eeef2e2ae6 100644 --- a/packages/zoe/test/unitTests/contracts/test-priceAggregator.js +++ b/packages/zoe/test/unitTests/contracts/test-priceAggregator.js @@ -48,7 +48,9 @@ test.before( /** @param {ExecutionContext} ot */ async ot => { // Outside of tests, we should use the long-lived Zoe on the // testnet. In this test, we must create a new Zoe. - const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin().admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin().admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contracts. const oracleBundle = await bundleSource(oraclePath); diff --git a/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js b/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js index ac3c8fcb920..5fa63986f0b 100644 --- a/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js +++ b/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js @@ -41,7 +41,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { Ask: simoleanKit.issuer, }); const terms = { timeAuthority: timer, closesAfter: 1n }; - const adminP = zoe.startInstance( + const adminP = E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -98,7 +98,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { // Bob is able to use the trusted invitationIssuer from Zoe to // transform an untrusted invitation that Alice also has access to, to // an - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); @@ -130,7 +130,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { }); const payments = { Bid: simoleanPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -166,7 +166,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { return Far('losing bidder', { offer: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const proposal = harden({ give: { Bid: bidAmount }, @@ -174,7 +174,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { }); const payments = { Bid: simoleanPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -245,7 +245,9 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { test('zoe - secondPriceAuction - alice tries to exit', async t => { t.plan(12); const { moolaR, simoleanR, moola, simoleans } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Setup Alice const aliceMoolaPayment = moolaR.mint.mintPayment(moola(1)); @@ -265,14 +267,14 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { // Pack the contract. const bundle = await bundleSource(secondPriceAuctionRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Asset: moolaR.issuer, Ask: simoleanR.issuer, }); const timer = buildManualTimer(console.log); const terms = harden({ timeAuthority: timer, closesAfter: 1n }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -286,7 +288,7 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { }); const alicePayments = harden({ Asset: aliceMoolaPayment }); // Alice initializes the auction - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -312,7 +314,7 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { // Bob escrows with zoe // Bob bids - const bobSeat = await zoe.offer(bobInvitation, bobProposal, bobPayments); + const bobSeat = await E(zoe).offer(bobInvitation, bobProposal, bobPayments); t.is( await E(bobSeat).getOfferResult(), @@ -333,7 +335,7 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { const carolPayments = harden({ Bid: carolSimoleanPayment }); // Carol bids - const carolSeat = await zoe.offer( + const carolSeat = await E(zoe).offer( carolInvitation, carolProposal, carolPayments, @@ -403,7 +405,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { moola, zoe, } = setupMixed(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Setup Alice const aliceCcPayment = ccMint.mintPayment(cryptoCats(harden(['Felix']))); @@ -430,14 +432,14 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Pack the contract. const bundle = await bundleSource(secondPriceAuctionRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Asset: ccIssuer, Ask: moolaIssuer, }); const timer = buildManualTimer(console.log); const terms = harden({ timeAuthority: timer, closesAfter: 1n }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -451,7 +453,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { }); const alicePayments = { Asset: aliceCcPayment }; // Alice initializes the auction - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -463,12 +465,12 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Alice spreads the invitations far and wide and Bob decides he // wants to participate in the auction. - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); const bobInvitationValue = await E(zoe).getInvitationDetails( bobExclusiveInvitation, ); - const bobIssuers = zoe.getIssuers(bobInvitationValue.instance); + const bobIssuers = await E(zoe).getIssuers(bobInvitationValue.instance); t.is(bobInvitationValue.installation, installation, 'bobInstallationId'); t.deepEqual(bobIssuers, { Asset: ccIssuer, Ask: moolaIssuer }, 'bobIssuers'); @@ -487,7 +489,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Bob escrows with zoe // Bob bids - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobProposal, bobPayments, @@ -501,14 +503,14 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Carol decides to bid for the one cc - const carolExclusiveInvitation = await invitationIssuer.claim( + const carolExclusiveInvitation = await E(invitationIssuer).claim( carolInvitation, ); const carolInvitationValue = await E(zoe).getInvitationDetails( carolExclusiveInvitation, ); - const carolIssuers = zoe.getIssuers(carolInvitationValue.instance); + const carolIssuers = await E(zoe).getIssuers(carolInvitationValue.instance); t.is(carolInvitationValue.installation, installation, 'carolInstallationId'); t.deepEqual( @@ -531,7 +533,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Carol escrows with zoe // Carol bids - const carolSeat = await zoe.offer( + const carolSeat = await E(zoe).offer( carolExclusiveInvitation, carolProposal, carolPayments, @@ -544,12 +546,14 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { ); // Dave decides to bid for the one moola - const daveExclusiveInvitation = await invitationIssuer.claim(daveInvitation); + const daveExclusiveInvitation = await E(invitationIssuer).claim( + daveInvitation, + ); const daveInvitationValue = await E(zoe).getInvitationDetails( daveExclusiveInvitation, ); - const daveIssuers = zoe.getIssuers(daveInvitationValue.instance); + const daveIssuers = await E(zoe).getIssuers(daveInvitationValue.instance); t.is(daveInvitationValue.installation, installation, 'daveInstallation'); t.deepEqual( @@ -572,7 +576,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Dave escrows with zoe // Dave bids - const daveSeat = await zoe.offer( + const daveSeat = await E(zoe).offer( daveExclusiveInvitation, daveProposal, davePayments, diff --git a/packages/zoe/test/unitTests/contracts/test-sellTickets.js b/packages/zoe/test/unitTests/contracts/test-sellTickets.js index f0bd6f90a5a..42342869084 100644 --- a/packages/zoe/test/unitTests/contracts/test-sellTickets.js +++ b/packages/zoe/test/unitTests/contracts/test-sellTickets.js @@ -23,7 +23,9 @@ const sellItemsRoot = `${dirname}/../../../src/contracts/sellItems.js`; test(`mint and sell tickets for multiple shows`, async t => { // Setup initial conditions - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const mintAndSellNFTBundle = await bundleSource(mintAndSellNFTRoot); const mintAndSellNFTInstallation = await E(zoe).install(mintAndSellNFTBundle); @@ -147,7 +149,9 @@ test(`mint and sell opera tickets`, async t => { const moola = value => AmountMath.make(value, moolaBrand); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const mintAndSellNFTBundle = await bundleSource(mintAndSellNFTRoot); const mintAndSellNFTInstallation = await E(zoe).install(mintAndSellNFTBundle); @@ -314,7 +318,7 @@ test(`mint and sell opera tickets`, async t => { const jokerPaymentForTicket = jokerPurse.withdraw(pricePerItem); - const seat = await zoe.offer( + const seat = await E(zoe).offer( invitation, jokerProposal, harden({ @@ -386,7 +390,7 @@ test(`mint and sell opera tickets`, async t => { insufficientAmount, ); - const seat = await zoe.offer( + const seat = await E(zoe).offer( invitation, jokerProposal, harden({ @@ -541,7 +545,9 @@ test(`mint and sell opera tickets`, async t => { // test('Testing publicFacet.getAvailableItemsNotifier()', async t => { // Setup initial conditions - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const mintAndSellNFTBundle = await bundleSource(mintAndSellNFTRoot); const mintAndSellNFTInstallation = await E(zoe).install(mintAndSellNFTBundle); diff --git a/packages/zoe/test/unitTests/contracts/test-simpleExchange.js b/packages/zoe/test/unitTests/contracts/test-simpleExchange.js index 3d045012c85..532a5798cf5 100644 --- a/packages/zoe/test/unitTests/contracts/test-simpleExchange.js +++ b/packages/zoe/test/unitTests/contracts/test-simpleExchange.js @@ -31,7 +31,7 @@ test('simpleExchange with valid offers', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, simpleExchange); // Setup Alice @@ -42,7 +42,7 @@ test('simpleExchange with valid offers', async t => { // 1: Alice creates a simpleExchange instance and spreads the publicFacet far // and wide with instructions on how to call makeInvitation(). - const { publicFacet, instance } = await zoe.startInstance(installation, { + const { publicFacet, instance } = await E(zoe).startInstance(installation, { Asset: moolaIssuer, Price: simoleanIssuer, }); @@ -117,9 +117,9 @@ test('simpleExchange with valid offers', async t => { const bobInstallation = await E(zoe).getInstallation(bobInvitation); // 5: Bob decides to join. - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); - const bobIssuers = zoe.getIssuers(instance); + const bobIssuers = await E(zoe).getIssuers(instance); t.is(bobInstallation, installation); @@ -143,7 +143,7 @@ test('simpleExchange with valid offers', async t => { // 6: Bob escrows with zoe // 8: Bob submits the buy order to the exchange - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobBuyOrderProposal, bobPayments, @@ -207,7 +207,7 @@ test('simpleExchange with multiple sell offers', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, simpleExchange); // Setup Alice @@ -220,7 +220,7 @@ test('simpleExchange with multiple sell offers', async t => { // 1: Simon creates a simpleExchange instance and spreads the publicFacet // far and wide with instructions on how to use it. - const { publicFacet } = await zoe.startInstance(installation, { + const { publicFacet } = await E(zoe).startInstance(installation, { Asset: moolaIssuer, Price: simoleanIssuer, }); @@ -238,14 +238,14 @@ test('simpleExchange with multiple sell offers', async t => { const aliceInvitation1 = E(publicFacet).makeInvitation(); // 4: Alice adds her sell order to the exchange - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation1, aliceSale1OrderProposal, alicePayments, ); // 5: Alice adds another sell order to the exchange - const aliceInvitation2 = await invitationIssuer.claim( + const aliceInvitation2 = await E(invitationIssuer).claim( await E(publicFacet).makeInvitation(), ); const aliceSale2OrderProposal = harden({ @@ -256,14 +256,14 @@ test('simpleExchange with multiple sell offers', async t => { const proposal2 = { Asset: aliceMoolaPurse.withdraw(moola(5)), }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceInvitation2, aliceSale2OrderProposal, proposal2, ); // 5: Alice adds a buy order to the exchange - const aliceInvitation3 = await invitationIssuer.claim( + const aliceInvitation3 = await E(invitationIssuer).claim( await E(publicFacet).makeInvitation(), ); const aliceBuyOrderProposal = harden({ @@ -272,7 +272,7 @@ test('simpleExchange with multiple sell offers', async t => { exit: { onDemand: null }, }); const proposal3 = { Price: aliceSimoleanPurse.withdraw(simoleans(18)) }; - const aliceSeat3 = await zoe.offer( + const aliceSeat3 = await E(zoe).offer( aliceInvitation3, aliceBuyOrderProposal, proposal3, @@ -310,7 +310,7 @@ test('simpleExchange with non-fungible assets', async t => { zoe, brands, } = setupNonFungible(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, simpleExchange); // Setup Alice @@ -322,7 +322,7 @@ test('simpleExchange with non-fungible assets', async t => { // 1: Simon creates a simpleExchange instance and spreads the invitation far and // wide with instructions on how to use it. - const { publicFacet } = await zoe.startInstance(installation, { + const { publicFacet } = await E(zoe).startInstance(installation, { Asset: rpgIssuer, Price: ccIssuer, }); @@ -337,7 +337,7 @@ test('simpleExchange with non-fungible assets', async t => { }); const alicePayments = { Asset: aliceRpgPayment }; // 4: Alice adds her sell order to the exchange - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceSellOrderProposal, alicePayments, @@ -348,11 +348,11 @@ test('simpleExchange with non-fungible assets', async t => { // 5: Bob decides to join. const bobInstance = await E(zoe).getInstance(bobInvitation); const bobInstallation = await E(zoe).getInstallation(bobInvitation); - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); t.is(bobInstallation, installation); - const bobIssuers = zoe.getIssuers(bobInstance); + const bobIssuers = await E(zoe).getIssuers(bobInstance); assert( bobIssuers.Asset === rpgIssuer, X`The Asset issuer should be the RPG issuer`, @@ -373,7 +373,7 @@ test('simpleExchange with non-fungible assets', async t => { // 6: Bob escrows with zoe // 8: Bob submits the buy order to the exchange - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobBuyOrderProposal, bobPayments, diff --git a/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js b/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js index 66f5f4390e2..710e9e8f114 100644 --- a/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js +++ b/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js @@ -16,7 +16,9 @@ const dirname = path.dirname(filename); const contractRoot = `${dirname}/throwInOfferHandler.js`; test('throw in offerHandler', async t => { - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); diff --git a/packages/zoe/test/unitTests/contracts/test-useObj.js b/packages/zoe/test/unitTests/contracts/test-useObj.js index ce59b857685..39907dc5fef 100644 --- a/packages/zoe/test/unitTests/contracts/test-useObj.js +++ b/packages/zoe/test/unitTests/contracts/test-useObj.js @@ -20,12 +20,14 @@ const contractRoot = `${dirname}/useObjExample.js`; test('zoe - useObj', async t => { t.plan(3); const { moolaIssuer, moolaMint, moola } = setup(); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceMoolaPayment = moolaMint.mintPayment(moola(3)); @@ -34,7 +36,7 @@ test('zoe - useObj', async t => { const issuerKeywordRecord = harden({ Pixels: moolaIssuer, }); - const { publicFacet } = await zoe.startInstance( + const { publicFacet } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -48,7 +50,11 @@ test('zoe - useObj', async t => { const alicePayments = { Pixels: aliceMoolaPayment }; // Alice makes an offer - const aliceSeat = await zoe.offer(invitation, aliceProposal, alicePayments); + const aliceSeat = await E(zoe).offer( + invitation, + aliceProposal, + alicePayments, + ); const useObj = await E(aliceSeat).getOfferResult(); diff --git a/packages/zoe/test/unitTests/installFromSource.js b/packages/zoe/test/unitTests/installFromSource.js index ab133e27bf6..79f2419a421 100644 --- a/packages/zoe/test/unitTests/installFromSource.js +++ b/packages/zoe/test/unitTests/installFromSource.js @@ -1,6 +1,7 @@ // @ts-check import bundleSource from '@agoric/bundle-source'; +import { E } from '@agoric/eventual-send'; /** * @param {ZoeService} zoe @@ -8,4 +9,4 @@ import bundleSource from '@agoric/bundle-source'; * @returns {Promise} */ export const installationPFromSource = (zoe, path) => - bundleSource(path).then(b => zoe.install(b)); + bundleSource(path).then(b => E(zoe).install(b)); diff --git a/packages/zoe/test/unitTests/setupBasicMints.js b/packages/zoe/test/unitTests/setupBasicMints.js index 9eda983c705..e1cf960199a 100644 --- a/packages/zoe/test/unitTests/setupBasicMints.js +++ b/packages/zoe/test/unitTests/setupBasicMints.js @@ -2,6 +2,7 @@ import { makeIssuerKit, AmountMath } from '@agoric/ertp'; import { makeStore } from '@agoric/store'; +import { E } from '@agoric/eventual-send'; import { makeZoeKit } from '../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../tools/fakeVatAdmin.js'; @@ -21,7 +22,9 @@ const setup = () => { brands.init(k, allBundles[k].brand); } - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const makeSimpleMake = brand => value => AmountMath.make(value, brand); @@ -43,7 +46,7 @@ const setup = () => { * @property {(value: any) => Amount} moola * @property {(value: any) => Amount} simoleans * @property {(value: any) => Amount} bucks - * @property {ZoeService} zoe + * @property {ERef} zoe */ /** @type {BasicMints} */ diff --git a/packages/zoe/test/unitTests/setupMixedMints.js b/packages/zoe/test/unitTests/setupMixedMints.js index 9940a997239..ea8d63e02fe 100644 --- a/packages/zoe/test/unitTests/setupMixedMints.js +++ b/packages/zoe/test/unitTests/setupMixedMints.js @@ -1,6 +1,7 @@ // @ts-check import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp'; +import { E } from '@agoric/eventual-send'; import { makeZoeKit } from '../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../tools/fakeVatAdmin.js'; @@ -25,7 +26,9 @@ const setupMixed = () => { const cryptoCats = value => AmountMath.make(value, allBundles.cc.brand); const moola = value => AmountMath.make(value, allBundles.moola.brand); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return { zoe, ccIssuer, diff --git a/packages/zoe/test/unitTests/setupNonFungibleMints.js b/packages/zoe/test/unitTests/setupNonFungibleMints.js index 6df54c5df9a..1fcc751d518 100644 --- a/packages/zoe/test/unitTests/setupNonFungibleMints.js +++ b/packages/zoe/test/unitTests/setupNonFungibleMints.js @@ -1,6 +1,7 @@ // @ts-check import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp'; +import { E } from '@agoric/eventual-send'; import { makeZoeKit } from '../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../tools/fakeVatAdmin.js'; @@ -21,7 +22,9 @@ const setupNonFungible = () => { function createRpgItem(name, power, desc = undefined) { return harden([{ name, description: desc || name, power }]); } - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const ccIssuer = issuers.get('cc'); const rpgIssuer = issuers.get('rpg'); diff --git a/packages/zoe/test/unitTests/test-bindDefaultFeePurse.js b/packages/zoe/test/unitTests/test-bindDefaultFeePurse.js new file mode 100644 index 00000000000..ae16b6129ad --- /dev/null +++ b/packages/zoe/test/unitTests/test-bindDefaultFeePurse.js @@ -0,0 +1,85 @@ +// @ts-check + +// eslint-disable-next-line import/no-extraneous-dependencies +import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; +import { E } from '@agoric/eventual-send'; +import { Far } from '@agoric/marshal'; + +import { bindDefaultFeePurse } from '../../src/zoeService/feePurse.js'; + +const zoe = Far('mockZoe', { + makeFeePurse: () => Far('feePurse', {}), + bindDefaultFeePurse: feePurse => bindDefaultFeePurse(zoe, feePurse), + // @ts-ignore Mocked for tests + install: (bundle, feePurse) => feePurse, + startInstance: ( + // @ts-ignore Mocked for tests + installation, + // @ts-ignore Mocked for tests + issuerKeywordRecord, + // @ts-ignore Mocked for tests + terms, + // @ts-ignore Mocked for tests + privateArgs, + feePurse, + ) => feePurse, + // @ts-ignore Mocked for tests + offer: (invitation, proposal, paymentKeywordRecord, offerArgs, feePurse) => + feePurse, + // @ts-ignore Mocked for tests + getPublicFacet: (instance, feePurse) => feePurse, +}); + +test('bindDefaultFeePurse', async t => { + const defaultFeePurse = await E(zoe).makeFeePurse(); + const customFeePurse = await E(zoe).makeFeePurse(); + // @ts-ignore Mocked for tests + const boundZoe = E(zoe).bindDefaultFeePurse(defaultFeePurse); + + // @ts-ignore Mocked for tests + t.is(await E(boundZoe).install(undefined), defaultFeePurse); + // @ts-ignore Mocked for tests + t.is(await E(boundZoe).install(undefined, customFeePurse), customFeePurse); + + t.is( + // @ts-ignore Mocked for tests + await E(boundZoe).startInstance(undefined, undefined, undefined, undefined), + defaultFeePurse, + ); + t.is( + await E(boundZoe).startInstance( + // @ts-ignore Mocked for tests + undefined, + undefined, + undefined, + undefined, + customFeePurse, + ), + customFeePurse, + ); + + t.is( + // @ts-ignore Mocked for tests + await E(boundZoe).offer(undefined, undefined, undefined, undefined), + defaultFeePurse, + ); + t.is( + await E(boundZoe).offer( + // @ts-ignore Mocked for tests + undefined, + undefined, + undefined, + undefined, + customFeePurse, + ), + customFeePurse, + ); + + // @ts-ignore Mocked for tests + t.is(await E(boundZoe).getPublicFacet(undefined), defaultFeePurse); + t.is( + // @ts-ignore Mocked for tests + await E(boundZoe).getPublicFacet(undefined, customFeePurse), + customFeePurse, + ); +}); diff --git a/packages/zoe/test/unitTests/test-makeKind.js b/packages/zoe/test/unitTests/test-makeKind.js index 4f2407968ce..22f8b091959 100644 --- a/packages/zoe/test/unitTests/test-makeKind.js +++ b/packages/zoe/test/unitTests/test-makeKind.js @@ -18,9 +18,11 @@ const root = `${dirname}/../minimalMakeKindContract.js`; test('makeKind non-swingset', async t => { const bundle = await bundleSource(root); - const { zoeService: zoe } = makeZoeKit(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const installation = await E(zoe).install(bundle); t.notThrows(() => makeKind()); t.notThrows(() => makeVirtualScalarWeakMap()); - await t.notThrowsAsync(() => zoe.startInstance(installation)); + await t.notThrowsAsync(() => E(zoe).startInstance(installation)); }); diff --git a/packages/zoe/test/unitTests/test-scriptedOracle.js b/packages/zoe/test/unitTests/test-scriptedOracle.js index 66741d0eb89..8a870b3767c 100644 --- a/packages/zoe/test/unitTests/test-scriptedOracle.js +++ b/packages/zoe/test/unitTests/test-scriptedOracle.js @@ -44,7 +44,9 @@ test.before( /** @param {ExecutionContext} ot */ async ot => { // Outside of tests, we should use the long-lived Zoe on the // testnet. In this test, we must create a new Zoe. - const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin().admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin().admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const oracleContractBundle = await bundleSource(oracleContractPath); const bountyContractBundle = await bundleSource(bountyContractPath); diff --git a/packages/zoe/test/unitTests/test-zoe.js b/packages/zoe/test/unitTests/test-zoe.js index d52e1180c23..d1a46e43618 100644 --- a/packages/zoe/test/unitTests/test-zoe.js +++ b/packages/zoe/test/unitTests/test-zoe.js @@ -33,7 +33,7 @@ test(`zoe.getInvitationIssuer`, async t => { t.falsy(await E(invitationIssuer).isLive(invitation)); }); -test(`zoe.install bad bundle`, async t => { +test(`E(zoe).install bad bundle`, async t => { const { zoe } = setup(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).install(), { @@ -41,7 +41,7 @@ test(`zoe.install bad bundle`, async t => { }); }); -test(`zoe.install`, async t => { +test(`E(zoe).install`, async t => { const { zoe } = setup(); const contractPath = `${dirname}/../../src/contracts/atomicSwap`; const bundle = await bundleSource(contractPath); @@ -50,7 +50,7 @@ test(`zoe.install`, async t => { t.is(await E(installation).getBundle(), bundle); }); -test(`zoe.startInstance bad installation`, async t => { +test(`E(zoe).startInstance bad installation`, async t => { const { zoe } = setup(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).startInstance(), { @@ -69,7 +69,7 @@ function isEmptyFacet(t, facet) { t.deepEqual(Object.getOwnPropertyNames(facet), []); } -test(`zoe.startInstance no issuerKeywordRecord, no terms`, async t => { +test(`E(zoe).startInstance no issuerKeywordRecord, no terms`, async t => { const { zoe, installation } = await setupZCFTest(); const result = await E(zoe).startInstance(installation); // Note that deepEqual treats all empty objects (handles) as interchangeable. @@ -88,7 +88,7 @@ test(`zoe.startInstance no issuerKeywordRecord, no terms`, async t => { ]); }); -test(`zoe.startInstance promise for installation`, async t => { +test(`E(zoe).startInstance promise for installation`, async t => { const { zoe, installation } = await setupZCFTest(); const { promise: installationP, @@ -115,7 +115,7 @@ test(`zoe.startInstance promise for installation`, async t => { ]); }); -test(`zoe.startInstance - terms, issuerKeywordRecord switched`, async t => { +test(`E(zoe).startInstance - terms, issuerKeywordRecord switched`, async t => { const { zoe, installation } = await setupZCFTest(); const { moolaKit } = setup(); await t.throwsAsync( @@ -138,14 +138,14 @@ test(`zoe.startInstance - terms, issuerKeywordRecord switched`, async t => { ); }); -test(`zoe.offer`, async t => { +test(`E(zoe).offer`, async t => { const { zoe, zcf } = await setupZCFTest(); const invitation = zcf.makeInvitation(() => 'result', 'invitation'); const userSeat = E(zoe).offer(invitation); t.is(await E(userSeat).getOfferResult(), 'result'); }); -test(`zoe.offer - no invitation`, async t => { +test(`E(zoe).offer - no invitation`, async t => { const { zoe } = await setupZCFTest(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).offer(), { @@ -153,7 +153,7 @@ test(`zoe.offer - no invitation`, async t => { }); }); -test(`zoe.getPublicFacet`, async t => { +test(`E(zoe).getPublicFacet`, async t => { const { zoe } = setup(); const contractPath = `${dirname}/../../src/contracts/automaticRefund`; const bundle = await bundleSource(contractPath); @@ -164,7 +164,7 @@ test(`zoe.getPublicFacet`, async t => { t.is(await E(zoe).getPublicFacet(instance), publicFacet); }); -test(`zoe.getPublicFacet - no instance`, async t => { +test(`E(zoe).getPublicFacet - no instance`, async t => { const { zoe } = setup(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).getPublicFacet(), { diff --git a/packages/zoe/test/unitTests/zcf/setupZcfTest.js b/packages/zoe/test/unitTests/zcf/setupZcfTest.js index edf759b05d4..8841b24c762 100644 --- a/packages/zoe/test/unitTests/zcf/setupZcfTest.js +++ b/packages/zoe/test/unitTests/zcf/setupZcfTest.js @@ -23,7 +23,9 @@ export const setupZCFTest = async (issuerKeywordRecord, terms) => { }; // The contract provides the `zcf` via `setTestJig` upon `start`. const fakeVatAdmin = makeFakeVatAdmin(setZCF); - const { zoeService: zoe, feeMintAccess } = makeZoeKit(fakeVatAdmin.admin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin.admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const bundle = await bundleSource(contractRoot); const installation = await E(zoe).install(bundle); const { creatorFacet, instance } = await E(zoe).startInstance( diff --git a/packages/zoe/test/unitTests/zcf/test-feeMintAccess.js b/packages/zoe/test/unitTests/zcf/test-feeMintAccess.js index a941625d7cf..3e62426df04 100644 --- a/packages/zoe/test/unitTests/zcf/test-feeMintAccess.js +++ b/packages/zoe/test/unitTests/zcf/test-feeMintAccess.js @@ -20,7 +20,9 @@ const dirname = path.dirname(filename); const contractRoot = `${dirname}/registerFeeMintContract.js`; test(`feeMintAccess`, async t => { - const { zoeService: zoe, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = await E(zoeService).bindDefaultFeePurse(feePurse); const bundle = await bundleSource(contractRoot); const installation = await E(zoe).install(bundle); const { creatorFacet } = await E(zoe).startInstance( diff --git a/packages/zoe/test/unitTests/zcf/test-zcf.js b/packages/zoe/test/unitTests/zcf/test-zcf.js index 5698884dfaa..a9628e1ccab 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcf.js +++ b/packages/zoe/test/unitTests/zcf/test-zcf.js @@ -15,8 +15,8 @@ import { assertAmountsEqual } from '../../zoeTestHelpers.js'; test(`zcf.getZoeService`, async t => { const { zoe, zcf } = await setupZCFTest(); - const zoeService = zcf.getZoeService(); - t.is(await zoeService, zoe); + const zoeService = await zcf.getZoeService(); + t.is(await E(zoeService).getFeeIssuer(), await E(zoe).getFeeIssuer()); }); test(`zcf.getInstance`, async t => { diff --git a/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js b/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js index 7dde2e90647..dfffd7ddcec 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js +++ b/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js @@ -29,12 +29,14 @@ test(`zoe - wrongly throw zcfSeat.exit()`, async t => { testJig = jig; }; const { admin: fakeVatAdminSvc, vatAdminState } = makeFakeVatAdmin(setJig); - const { zoeService: zoe } = makeZoeKit(fakeVatAdminSvc); + const { zoeService } = makeZoeKit(fakeVatAdminSvc); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/zcf/test-zcfSeat.js b/packages/zoe/test/unitTests/zcf/test-zcfSeat.js index 3e475a1d66f..dfe549d8083 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcfSeat.js +++ b/packages/zoe/test/unitTests/zcf/test-zcfSeat.js @@ -26,12 +26,14 @@ test(`zoe - zcfSeat.fail() doesn't throw`, async t => { testJig = jig; }; const { admin: fakeVatAdminSvc, vatAdminState } = makeFakeVatAdmin(setJig); - const { zoeService: zoe } = makeZoeKit(fakeVatAdminSvc); + const { zoeService } = makeZoeKit(fakeVatAdminSvc); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/zoe/test-feePurse.js b/packages/zoe/test/unitTests/zoe/test-feePurse.js index 2f60da9c607..30c54a9a486 100644 --- a/packages/zoe/test/unitTests/zoe/test-feePurse.js +++ b/packages/zoe/test/unitTests/zoe/test-feePurse.js @@ -11,20 +11,22 @@ const setup = () => { const runIssuerKit = makeIssuerKit('RUN', AssetKind.NAT, { decimalPlaces: 6, }); - const { makeFeePurse, isFeePurse } = setupMakeFeePurse(runIssuerKit.issuer); - return { makeFeePurse, isFeePurse, runIssuerKit }; + const { makeFeePurse, assertFeePurse } = setupMakeFeePurse( + runIssuerKit.issuer, + ); + return { makeFeePurse, assertFeePurse, runIssuerKit }; }; test('feePurse starts empty', async t => { const { makeFeePurse } = setup(); - const feePurse = makeFeePurse(); + const feePurse = await makeFeePurse(); t.true(AmountMath.isEmpty(feePurse.getCurrentAmount())); }); test('depositing into and withdrawing from feePurse', async t => { const { makeFeePurse, runIssuerKit } = setup(); - const feePurse = makeFeePurse(); + const feePurse = await makeFeePurse(); const run1000 = AmountMath.make(runIssuerKit.brand, 1000n); const payment = runIssuerKit.mint.mintPayment(run1000); @@ -37,9 +39,9 @@ test('depositing into and withdrawing from feePurse', async t => { t.true(AmountMath.isEmpty(feePurse.getCurrentAmount())); }); -test('isFeePurse', async t => { - const { makeFeePurse, isFeePurse } = setup(); - const feePurse = makeFeePurse(); +test('assertFeePurse', async t => { + const { makeFeePurse, assertFeePurse } = setup(); + const feePurse = await makeFeePurse(); - t.true(isFeePurse(feePurse)); + t.is(await assertFeePurse(feePurse), undefined); }); diff --git a/packages/zoe/test/unitTests/zoe/test-installationStorage.js b/packages/zoe/test/unitTests/zoe/test-installationStorage.js index c314fe5600c..252a680011b 100644 --- a/packages/zoe/test/unitTests/zoe/test-installationStorage.js +++ b/packages/zoe/test/unitTests/zoe/test-installationStorage.js @@ -5,47 +5,61 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { makeInstallationStorage } from '../../../src/zoeService/installationStorage.js'; +const assertFeePurse = () => {}; + test('install, unwrap installations', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const { install, unwrapInstallation } = makeInstallationStorage( + assertFeePurse, + ); const fakeBundle = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation = install(fakeBundle); + const installation = await install(fakeBundle, feePurse); const unwrapped = await unwrapInstallation(installation); t.is(unwrapped.installation, installation); t.is(unwrapped.bundle, fakeBundle); }); test('unwrap promise for installation', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const { install, unwrapInstallation } = makeInstallationStorage( + assertFeePurse, + ); const fakeBundle = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation = install(fakeBundle); + const installation = await install(fakeBundle, feePurse); const unwrapped = await unwrapInstallation(Promise.resolve(installation)); t.is(unwrapped.installation, installation); t.is(unwrapped.bundle, fakeBundle); }); test('install several', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const { install, unwrapInstallation } = makeInstallationStorage( + assertFeePurse, + ); const fakeBundle1 = {}; const fakeBundle2 = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation1 = install(fakeBundle1); + const installation1 = await install(fakeBundle1, feePurse); const unwrapped1 = await unwrapInstallation(installation1); t.is(unwrapped1.installation, installation1); t.is(unwrapped1.bundle, fakeBundle1); - const installation2 = install(fakeBundle2); + const installation2 = await install(fakeBundle2, feePurse); const unwrapped2 = await unwrapInstallation(installation2); t.is(unwrapped2.installation, installation2); t.is(unwrapped2.bundle, fakeBundle2); }); test('install same twice', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const { install, unwrapInstallation } = makeInstallationStorage( + assertFeePurse, + ); const fakeBundle1 = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation1 = install(fakeBundle1); + const installation1 = await install(fakeBundle1, feePurse); const unwrapped1 = await unwrapInstallation(installation1); t.is(unwrapped1.installation, installation1); t.is(unwrapped1.bundle, fakeBundle1); @@ -53,7 +67,7 @@ test('install same twice', async t => { // If the same bundle is installed twice, the bundle is the same, // but the installation is different. Zoe does not currently care about // duplicate bundles. - const installation2 = install(fakeBundle1); + const installation2 = await install(fakeBundle1, feePurse); const unwrapped2 = await unwrapInstallation(installation2); t.is(unwrapped2.installation, installation2); t.not(installation2, installation1); diff --git a/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js b/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js index 259c953d380..691a9db6642 100644 --- a/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js +++ b/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js @@ -7,6 +7,8 @@ import { Far } from '@agoric/marshal'; import { makeInstanceAdminStorage } from '../../../src/zoeService/instanceAdminStorage.js'; +const assertFeePurse = () => {}; + test('makeInstanceAdminStorage', async t => { const { getPublicFacet, @@ -17,7 +19,7 @@ test('makeInstanceAdminStorage', async t => { getInstanceAdmin, initInstanceAdmin, deleteInstanceAdmin, - } = makeInstanceAdminStorage(); + } = makeInstanceAdminStorage(assertFeePurse); const mockInstance1 = Far('mockInstance1', {}); const mockInstance2 = Far('mockInstance2', {}); @@ -46,19 +48,19 @@ test('makeInstanceAdminStorage', async t => { t.is(getInstanceAdmin(mockInstance1), mockInstanceAdmin1); // @ts-ignore instance is mocked - t.is(getPublicFacet(mockInstance1), 'publicFacet1'); + t.is(await getPublicFacet(mockInstance1), 'publicFacet1'); // @ts-ignore instance is mocked - t.is(getBrands(mockInstance2), 'brands2'); + t.is(await getBrands(mockInstance2), 'brands2'); // @ts-ignore instance is mocked - t.is(getIssuers(mockInstance1), 'issuers1'); + t.is(await getIssuers(mockInstance1), 'issuers1'); // @ts-ignore instance is mocked - t.is(getTerms(mockInstance1), 'terms1'); + t.is(await getTerms(mockInstance1), 'terms1'); // @ts-ignore instance is mocked - t.is(getInstallationForInstance(mockInstance1), 'installation1'); + t.is(await getInstallationForInstance(mockInstance1), 'installation1'); // @ts-ignore instance is mocked deleteInstanceAdmin(mockInstance2); @@ -69,13 +71,13 @@ test('makeInstanceAdminStorage', async t => { }); // @ts-ignore instance is mocked - t.throws(() => getPublicFacet(mockInstance2), { + await t.throwsAsync(() => getPublicFacet(mockInstance2), { message: '"instance" not found: "[Alleged: mockInstance2]"', }); }); test('add another instance admin for same instance', async t => { - const { initInstanceAdmin } = makeInstanceAdminStorage(); + const { initInstanceAdmin } = makeInstanceAdminStorage(assertFeePurse); const mockInstance1 = Far('mockInstance1', {}); const mockInstanceAdmin1 = Far('mockInstanceAdmin1', {});