Skip to content

Commit

Permalink
test(zoe): switch to E(zoe).installBundleID()
Browse files Browse the repository at this point in the history
The new preferred way to install a contract is by its bundleID, using
`E(zoe).installBundleID(id)` instead of `E(zoe).install(bundle)`. The bundle
itself must first be installed/registered with the VatAdmin service. In a
real swingset, this happens out-of-band, via
`controller.validateAndInstallBundle`. In a non-swingset unit test, the
`fakeVatAdmin` has a new `vatAdminState.installBundle(id, bundle)`.

This changes most Zoe unit tests to perform `vatAdminState.installBundle` and
then use Zoe's `installBundleID` method. This requires some mechanical
changes to the way many tests get access to their fakeVatAdmin. I took the
opportunity to switch all tests to importing `makeFakeVatAdmin` and building
their own local copy, rather than relying upon the shared singleton created
and exported by `fakeVatAdmin.js` itself.

This leaves one test in `unitTests/` using the old `E(zoe).install(bundle)`,
to ensure it still works until we decide to remove it entirely. All tests in
`swingsetTests/` still use `install(bundle)`, those will be changed later.

refs #4565
  • Loading branch information
warner committed Mar 1, 2022
1 parent ce4474b commit fc89aa7
Show file tree
Hide file tree
Showing 36 changed files with 393 additions and 143 deletions.
7 changes: 5 additions & 2 deletions packages/zoe/test/unitTests/contractSupport/test-depositTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ async function setupContract(moolaIssuer, bucksIssuer) {
const setJig = jig => {
testJig = jig;
};
const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin);
const fakeVatAdmin = makeFakeVatAdmin(setJig);
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin.admin);

// pack the contract
const bundle = await bundleSource(contractRoot);
fakeVatAdmin.vatAdminState.installBundle('b1-contract', bundle);

// install the contract
const installation = await E(zoe).install(bundle);
const installation = await E(zoe).installBundleID('b1-contract');

// Alice creates an instance
const issuerKeywordRecord = harden({
Expand Down
6 changes: 4 additions & 2 deletions packages/zoe/test/unitTests/contractSupport/test-offerTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 fakeVatAdmin = makeFakeVatAdmin(setJig);
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin.admin);

// pack the contract
const bundle = await bundleSource(contractRoot);
fakeVatAdmin.vatAdminState.installBundle('b1-contract', bundle);
// install the contract
const installation = await E(zoe).install(bundle);
const installation = await E(zoe).installBundleID('b1-contract');

// Create TWO instances of the zcfTesterContract which have
// different keywords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ async function setupContract(moolaIssuer, bucksIssuer) {
const setJig = jig => {
testJig = jig;
};
const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin);
const fakeVatAdmin = makeFakeVatAdmin(setJig);
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin.admin);

// pack the contract
const bundle = await bundleSource(contractRoot);
fakeVatAdmin.vatAdminState.installBundle('b1-contract', bundle);
// install the contract
const installation = await E(zoe).install(bundle);
const installation = await E(zoe).installBundleID('b1-contract');

// Alice creates an instance
const issuerKeywordRecord = harden({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ import bundleSource from '@endo/bundle-source';
import { E } from '@agoric/eventual-send';

import { makeZoeKit } from '../../../../src/zoeService/zoe.js';
import fakeVatAdmin from '../../../../tools/fakeVatAdmin.js';
import { makeFakeVatAdmin } from '../../../../tools/fakeVatAdmin.js';

const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);

const attestationRoot = `${dirname}/../../../../src/contracts/attestation/attestation.js`;

test('attestation contract basic tests', async t => {
const { admin: fakeVatAdmin, vatAdminState } = makeFakeVatAdmin();
const bundle = await bundleSource(attestationRoot);
vatAdminState.installBundle('b1-contract', bundle);

const { zoeService: zoe } = makeZoeKit(fakeVatAdmin);
const installation = await E(zoe).install(bundle);
const installation = await E(zoe).installBundleID('b1-contract');

const bldIssuerKit = makeIssuerKit(
'BLD',
Expand Down
11 changes: 6 additions & 5 deletions packages/zoe/test/unitTests/contracts/loan/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ export const setupLoanUnitTest = async terms => {
Loan: loanKit.issuer,
});

const { zcf, zoe, installation, instance } = await setupZCFTest(
issuerKeywordRecord,
terms,
);
const { zcf, zoe, installation, instance, vatAdminState } =
await setupZCFTest(issuerKeywordRecord, terms);

return {
zcf,
Expand All @@ -118,6 +116,7 @@ export const setupLoanUnitTest = async terms => {
loanKit,
installation,
instance,
vatAdminState,
};
};

Expand Down Expand Up @@ -195,12 +194,14 @@ export const makeAutoswapInstance = async (
collateralKit,
loanKit,
initialLiquidityKeywordRecord,
vatAdminState,
) => {
const autoswapRoot = `${dirname}/../../../../src/contracts/autoswap`;

// Create autoswap installation and instance
const autoswapBundle = await bundleSource(autoswapRoot);
const autoswapInstallation = await E(zoe).install(autoswapBundle);
vatAdminState.installBundle('b1-autoswap', autoswapBundle);
const autoswapInstallation = await E(zoe).installBundleID('b1-autoswap');

const { instance: autoswapInstance, publicFacet } = await E(
zoe,
Expand Down
3 changes: 2 additions & 1 deletion packages/zoe/test/unitTests/contracts/loan/test-borrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const setupBorrow = async (
timer = buildManualTimer(console.log),
) => {
const setup = await setupLoanUnitTest();
const { zcf, loanKit, collateralKit, zoe } = setup;
const { zcf, loanKit, collateralKit, zoe, vatAdminState } = setup;
// Set up the lender seat
const maxLoan = AmountMath.make(loanKit.brand, maxLoanValue);
const { zcfSeat: lenderSeat, userSeat: lenderUserSeat } = await makeSeatKit(
Expand Down Expand Up @@ -66,6 +66,7 @@ const setupBorrow = async (
collateralKit,
loanKit,
initialLiquidityKeywordRecord,
vatAdminState,
);

// In the config that the borrow code sees, the periodNotifier has
Expand Down
13 changes: 10 additions & 3 deletions packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@ test.todo('loan - lend - wrong exit rule');
test.todo('loan - lend - must want nothing');

test('loan - lend - exit before borrow', async t => {
const { moolaKit: collateralKit, simoleanKit: loanKit, zoe } = setup();
const {
moolaKit: collateralKit,
simoleanKit: loanKit,
zoe,
vatAdminState,
} = setup();
const bundle = await bundleSource(loanRoot);
const installation = await E(zoe).install(bundle);
vatAdminState.installBundle('b1-loan', bundle);
const installation = await E(zoe).installBundleID('b1-loan');

// Create autoswap installation and instance
const autoswapBundle = await bundleSource(autoswapRoot);
const autoswapInstallation = await E(zoe).install(autoswapBundle);
vatAdminState.installBundle('b1-autoswap', autoswapBundle);
const autoswapInstallation = await E(zoe).installBundleID('b1-autoswap');

const { instance: autoswapInstance } = await E(zoe).startInstance(
autoswapInstallation,
Expand Down
15 changes: 10 additions & 5 deletions packages/zoe/test/unitTests/contracts/test-atomicSwap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const atomicSwapRoot = `${dirname}/../../../src/contracts/atomicSwap.js`;

test('zoe - atomicSwap', async t => {
t.plan(8);
const { moolaKit, simoleanKit, moola, simoleans, zoe } = setup();
const { moolaKit, simoleanKit, moola, simoleans, zoe, vatAdminState } =
setup();

const makeAlice = async moolaPayment => {
const moolaPurse = await E(moolaKit.issuer).makeEmptyPurse();
Expand All @@ -29,7 +30,8 @@ test('zoe - atomicSwap', async t => {
// pack the contract
const bundle = await bundleSource(atomicSwapRoot);
// install the contract
const installationP = E(zoe).install(bundle);
vatAdminState.installBundle('b1-atomicswap', bundle);
const installationP = E(zoe).installBundleID('b1-atomicswap');
return installationP;
},
startInstance: async installation => {
Expand Down Expand Up @@ -181,6 +183,7 @@ test('zoe - non-fungible atomicSwap', async t => {
rpgItems,
createRpgItem,
zoe,
vatAdminState,
} = setupNonFungible();

const makeAlice = async aliceCcPayment => {
Expand All @@ -191,7 +194,8 @@ test('zoe - non-fungible atomicSwap', async t => {
// pack the contract
const bundle = await bundleSource(atomicSwapRoot);
// install the contract
const installationP = E(zoe).install(bundle);
vatAdminState.installBundle('b1-atomicswap', bundle);
const installationP = E(zoe).installBundleID('b1-atomicswap');
return installationP;
},
startInstance: async installation => {
Expand Down Expand Up @@ -339,13 +343,14 @@ test('zoe - non-fungible atomicSwap', async t => {
// Checking handling of duplicate issuers. I'd have preferred a raffle contract
test('zoe - atomicSwap like-for-like', async t => {
t.plan(13);
const { moolaIssuer, moolaMint, moola, zoe } = setup();
const { moolaIssuer, moolaMint, moola, zoe, vatAdminState } = setup();
const invitationIssuer = await E(zoe).getInvitationIssuer();

// pack the contract
const bundle = await bundleSource(atomicSwapRoot);
// install the contract
const installation = await E(zoe).install(bundle);
vatAdminState.installBundle('b1-atomicswap', bundle);
const installation = await E(zoe).installBundleID('b1-atomicswap');

// Setup Alice
const aliceMoolaPayment = moolaMint.mintPayment(moola(3n));
Expand Down
43 changes: 26 additions & 17 deletions packages/zoe/test/unitTests/contracts/test-auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { E } from '@agoric/eventual-send';
import { Far } from '@endo/marshal';
import { assert, details as X } from '@agoric/assert';

import { makeZoeKit } from '../../../src/zoeService/zoe.js';
import buildManualTimer from '../../../tools/manualTimer.js';
import { setup } from '../setupBasicMints.js';
import { setupMixed } from '../setupMixedMints.js';
import fakeVatAdmin from '../../../tools/fakeVatAdmin.js';

const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);
Expand All @@ -22,7 +20,8 @@ const auctionRoot = `${dirname}/../../../src/contracts/auction/index.js`;

test('zoe - secondPriceAuction w/ 3 bids', async t => {
t.plan(15);
const { moolaKit, simoleanKit, moola, simoleans, zoe } = setup();
const { moolaKit, simoleanKit, moola, simoleans, zoe, vatAdminState } =
setup();

const makeAlice = async (timer, moolaPayment) => {
const moolaPurse = await E(moolaKit.issuer).makeEmptyPurse();
Expand All @@ -32,7 +31,8 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => {
// pack the contract
const bundle = await bundleSource(auctionRoot);
// install the contract
const installationP = E(zoe).install(bundle);
vatAdminState.installBundle('b1-auction', bundle);
const installationP = E(zoe).installBundleID('b1-auction');
return installationP;
},
startInstance: async installation => {
Expand Down Expand Up @@ -247,8 +247,7 @@ 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 { moolaR, simoleanR, moola, simoleans, zoe, vatAdminState } = setup();

// Setup Alice
const aliceMoolaPayment = moolaR.mint.mintPayment(moola(1n));
Expand All @@ -268,7 +267,8 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => {
// Pack the contract.
const bundle = await bundleSource(auctionRoot);

const installation = await E(zoe).install(bundle);
vatAdminState.installBundle('b1-auction', bundle);
const installation = await E(zoe).installBundleID('b1-auction');
const issuerKeywordRecord = harden({
Asset: moolaR.issuer,
Ask: simoleanR.issuer,
Expand Down Expand Up @@ -401,8 +401,7 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => {

test('zoe - secondPriceAuction - all bidders try to exit', async t => {
t.plan(10);
const { moolaR, simoleanR, moola, simoleans } = setup();
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin);
const { moolaR, simoleanR, moola, simoleans, zoe, vatAdminState } = setup();

// Setup Alice
const aliceMoolaPayment = moolaR.mint.mintPayment(moola(1n));
Expand All @@ -418,8 +417,8 @@ test('zoe - secondPriceAuction - all bidders try to exit', async t => {

// Pack the contract.
const bundle = await bundleSource(auctionRoot);

const installation = await E(zoe).install(bundle);
vatAdminState.installBundle('b1-auction', bundle);
const installation = await E(zoe).installBundleID('b1-auction');
const issuerKeywordRecord = harden({
Asset: moolaR.issuer,
Ask: simoleanR.issuer,
Expand Down Expand Up @@ -526,8 +525,16 @@ test('zoe - secondPriceAuction - all bidders try to exit', async t => {
// Three bidders with (fungible) moola bid for a CryptoCat
test('zoe - secondPriceAuction non-fungible asset', async t => {
t.plan(30);
const { ccIssuer, moolaIssuer, ccMint, moolaMint, cryptoCats, moola, zoe } =
setupMixed();
const {
ccIssuer,
moolaIssuer,
ccMint,
moolaMint,
cryptoCats,
moola,
zoe,
vatAdminState,
} = setupMixed();
const invitationIssuer = await E(zoe).getInvitationIssuer();

// Setup Alice
Expand All @@ -554,8 +561,8 @@ test('zoe - secondPriceAuction non-fungible asset', async t => {

// Pack the contract.
const bundle = await bundleSource(auctionRoot);

const installation = await E(zoe).install(bundle);
vatAdminState.installBundle('b1-auction', bundle);
const installation = await E(zoe).installBundleID('b1-auction');
const issuerKeywordRecord = harden({
Asset: ccIssuer,
Ask: moolaIssuer,
Expand Down Expand Up @@ -812,7 +819,8 @@ test('zoe - secondPriceAuction non-fungible asset', async t => {

test('zoe - firstPriceAuction w/ 3 bids', async t => {
t.plan(15);
const { moolaKit, simoleanKit, moola, simoleans, zoe } = setup();
const { moolaKit, simoleanKit, moola, simoleans, zoe, vatAdminState } =
setup();

const makeAlice = async (timer, moolaPayment) => {
const moolaPurse = await E(moolaKit.issuer).makeEmptyPurse();
Expand All @@ -822,7 +830,8 @@ test('zoe - firstPriceAuction w/ 3 bids', async t => {
// pack the contract
const bundle = await bundleSource(auctionRoot);
// install the contract
const installationP = E(zoe).install(bundle);
vatAdminState.installBundle('b1-auction', bundle);
const installationP = E(zoe).installBundleID('b1-auction');
return installationP;
},
startInstance: async installation => {
Expand Down
Loading

0 comments on commit fc89aa7

Please sign in to comment.