Skip to content

Commit e96c0c1

Browse files
committed
test(zoe): switch to E(zoe).installBundleID()
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
1 parent 0a320ba commit e96c0c1

36 files changed

+393
-143
lines changed

packages/zoe/test/unitTests/contractSupport/test-depositTo.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ async function setupContract(moolaIssuer, bucksIssuer) {
2323
const setJig = jig => {
2424
testJig = jig;
2525
};
26-
const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin);
26+
const fakeVatAdmin = makeFakeVatAdmin(setJig);
27+
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin.admin);
2728

2829
// pack the contract
2930
const bundle = await bundleSource(contractRoot);
31+
fakeVatAdmin.vatAdminState.installBundle('b1-contract', bundle);
32+
3033
// install the contract
31-
const installation = await E(zoe).install(bundle);
34+
const installation = await E(zoe).installBundleID('b1-contract');
3235

3336
// Alice creates an instance
3437
const issuerKeywordRecord = harden({

packages/zoe/test/unitTests/contractSupport/test-offerTo.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ const setupContract = async (moolaIssuer, bucksIssuer) => {
2727
const setJig = jig => {
2828
instanceToZCF.set(jig.instance, jig.zcf);
2929
};
30-
const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin);
30+
const fakeVatAdmin = makeFakeVatAdmin(setJig);
31+
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin.admin);
3132

3233
// pack the contract
3334
const bundle = await bundleSource(contractRoot);
35+
fakeVatAdmin.vatAdminState.installBundle('b1-contract', bundle);
3436
// install the contract
35-
const installation = await E(zoe).install(bundle);
37+
const installation = await E(zoe).installBundleID('b1-contract');
3638

3739
// Create TWO instances of the zcfTesterContract which have
3840
// different keywords

packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ async function setupContract(moolaIssuer, bucksIssuer) {
2727
const setJig = jig => {
2828
testJig = jig;
2929
};
30-
const { zoeService: zoe } = makeZoeKit(makeFakeVatAdmin(setJig).admin);
30+
const fakeVatAdmin = makeFakeVatAdmin(setJig);
31+
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin.admin);
3132

3233
// pack the contract
3334
const bundle = await bundleSource(contractRoot);
35+
fakeVatAdmin.vatAdminState.installBundle('b1-contract', bundle);
3436
// install the contract
35-
const installation = await E(zoe).install(bundle);
37+
const installation = await E(zoe).installBundleID('b1-contract');
3638

3739
// Alice creates an instance
3840
const issuerKeywordRecord = harden({

packages/zoe/test/unitTests/contracts/attestation/test-attestation.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ import bundleSource from '@endo/bundle-source';
1212
import { E } from '@agoric/eventual-send';
1313

1414
import { makeZoeKit } from '../../../../src/zoeService/zoe.js';
15-
import fakeVatAdmin from '../../../../tools/fakeVatAdmin.js';
15+
import { makeFakeVatAdmin } from '../../../../tools/fakeVatAdmin.js';
1616

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

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

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

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

2830
const bldIssuerKit = makeIssuerKit(
2931
'BLD',

packages/zoe/test/unitTests/contracts/loan/helpers.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ export const setupLoanUnitTest = async terms => {
106106
Loan: loanKit.issuer,
107107
});
108108

109-
const { zcf, zoe, installation, instance } = await setupZCFTest(
110-
issuerKeywordRecord,
111-
terms,
112-
);
109+
const { zcf, zoe, installation, instance, vatAdminState } =
110+
await setupZCFTest(issuerKeywordRecord, terms);
113111

114112
return {
115113
zcf,
@@ -118,6 +116,7 @@ export const setupLoanUnitTest = async terms => {
118116
loanKit,
119117
installation,
120118
instance,
119+
vatAdminState,
121120
};
122121
};
123122

@@ -195,12 +194,14 @@ export const makeAutoswapInstance = async (
195194
collateralKit,
196195
loanKit,
197196
initialLiquidityKeywordRecord,
197+
vatAdminState,
198198
) => {
199199
const autoswapRoot = `${dirname}/../../../../src/contracts/autoswap`;
200200

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

205206
const { instance: autoswapInstance, publicFacet } = await E(
206207
zoe,

packages/zoe/test/unitTests/contracts/loan/test-borrow.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const setupBorrow = async (
3636
timer = buildManualTimer(console.log),
3737
) => {
3838
const setup = await setupLoanUnitTest();
39-
const { zcf, loanKit, collateralKit, zoe } = setup;
39+
const { zcf, loanKit, collateralKit, zoe, vatAdminState } = setup;
4040
// Set up the lender seat
4141
const maxLoan = AmountMath.make(loanKit.brand, maxLoanValue);
4242
const { zcfSeat: lenderSeat, userSeat: lenderUserSeat } = await makeSeatKit(
@@ -66,6 +66,7 @@ const setupBorrow = async (
6666
collateralKit,
6767
loanKit,
6868
initialLiquidityKeywordRecord,
69+
vatAdminState,
6970
);
7071

7172
// In the config that the borrow code sees, the periodNotifier has

packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ test.todo('loan - lend - wrong exit rule');
3535
test.todo('loan - lend - must want nothing');
3636

3737
test('loan - lend - exit before borrow', async t => {
38-
const { moolaKit: collateralKit, simoleanKit: loanKit, zoe } = setup();
38+
const {
39+
moolaKit: collateralKit,
40+
simoleanKit: loanKit,
41+
zoe,
42+
vatAdminState,
43+
} = setup();
3944
const bundle = await bundleSource(loanRoot);
40-
const installation = await E(zoe).install(bundle);
45+
vatAdminState.installBundle('b1-loan', bundle);
46+
const installation = await E(zoe).installBundleID('b1-loan');
4147

4248
// Create autoswap installation and instance
4349
const autoswapBundle = await bundleSource(autoswapRoot);
44-
const autoswapInstallation = await E(zoe).install(autoswapBundle);
50+
vatAdminState.installBundle('b1-autoswap', autoswapBundle);
51+
const autoswapInstallation = await E(zoe).installBundleID('b1-autoswap');
4552

4653
const { instance: autoswapInstance } = await E(zoe).startInstance(
4754
autoswapInstallation,

packages/zoe/test/unitTests/contracts/test-atomicSwap.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const atomicSwapRoot = `${dirname}/../../../src/contracts/atomicSwap.js`;
1919

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

2425
const makeAlice = async moolaPayment => {
2526
const moolaPurse = await E(moolaKit.issuer).makeEmptyPurse();
@@ -29,7 +30,8 @@ test('zoe - atomicSwap', async t => {
2930
// pack the contract
3031
const bundle = await bundleSource(atomicSwapRoot);
3132
// install the contract
32-
const installationP = E(zoe).install(bundle);
33+
vatAdminState.installBundle('b1-atomicswap', bundle);
34+
const installationP = E(zoe).installBundleID('b1-atomicswap');
3335
return installationP;
3436
},
3537
startInstance: async installation => {
@@ -181,6 +183,7 @@ test('zoe - non-fungible atomicSwap', async t => {
181183
rpgItems,
182184
createRpgItem,
183185
zoe,
186+
vatAdminState,
184187
} = setupNonFungible();
185188

186189
const makeAlice = async aliceCcPayment => {
@@ -191,7 +194,8 @@ test('zoe - non-fungible atomicSwap', async t => {
191194
// pack the contract
192195
const bundle = await bundleSource(atomicSwapRoot);
193196
// install the contract
194-
const installationP = E(zoe).install(bundle);
197+
vatAdminState.installBundle('b1-atomicswap', bundle);
198+
const installationP = E(zoe).installBundleID('b1-atomicswap');
195199
return installationP;
196200
},
197201
startInstance: async installation => {
@@ -339,13 +343,14 @@ test('zoe - non-fungible atomicSwap', async t => {
339343
// Checking handling of duplicate issuers. I'd have preferred a raffle contract
340344
test('zoe - atomicSwap like-for-like', async t => {
341345
t.plan(13);
342-
const { moolaIssuer, moolaMint, moola, zoe } = setup();
346+
const { moolaIssuer, moolaMint, moola, zoe, vatAdminState } = setup();
343347
const invitationIssuer = await E(zoe).getInvitationIssuer();
344348

345349
// pack the contract
346350
const bundle = await bundleSource(atomicSwapRoot);
347351
// install the contract
348-
const installation = await E(zoe).install(bundle);
352+
vatAdminState.installBundle('b1-atomicswap', bundle);
353+
const installation = await E(zoe).installBundleID('b1-atomicswap');
349354

350355
// Setup Alice
351356
const aliceMoolaPayment = moolaMint.mintPayment(moola(3n));

packages/zoe/test/unitTests/contracts/test-auction.js

+26-17
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import { E } from '@agoric/eventual-send';
99
import { Far } from '@endo/marshal';
1010
import { assert, details as X } from '@agoric/assert';
1111

12-
import { makeZoeKit } from '../../../src/zoeService/zoe.js';
1312
import buildManualTimer from '../../../tools/manualTimer.js';
1413
import { setup } from '../setupBasicMints.js';
1514
import { setupMixed } from '../setupMixedMints.js';
16-
import fakeVatAdmin from '../../../tools/fakeVatAdmin.js';
1715

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

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

2726
const makeAlice = async (timer, moolaPayment) => {
2827
const moolaPurse = await E(moolaKit.issuer).makeEmptyPurse();
@@ -32,7 +31,8 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => {
3231
// pack the contract
3332
const bundle = await bundleSource(auctionRoot);
3433
// install the contract
35-
const installationP = E(zoe).install(bundle);
34+
vatAdminState.installBundle('b1-auction', bundle);
35+
const installationP = E(zoe).installBundleID('b1-auction');
3636
return installationP;
3737
},
3838
startInstance: async installation => {
@@ -247,8 +247,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => {
247247

248248
test('zoe - secondPriceAuction - alice tries to exit', async t => {
249249
t.plan(12);
250-
const { moolaR, simoleanR, moola, simoleans } = setup();
251-
const { zoeService: zoe } = makeZoeKit(fakeVatAdmin);
250+
const { moolaR, simoleanR, moola, simoleans, zoe, vatAdminState } = setup();
252251

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

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

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

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

419418
// Pack the contract.
420419
const bundle = await bundleSource(auctionRoot);
421-
422-
const installation = await E(zoe).install(bundle);
420+
vatAdminState.installBundle('b1-auction', bundle);
421+
const installation = await E(zoe).installBundleID('b1-auction');
423422
const issuerKeywordRecord = harden({
424423
Asset: moolaR.issuer,
425424
Ask: simoleanR.issuer,
@@ -526,8 +525,16 @@ test('zoe - secondPriceAuction - all bidders try to exit', async t => {
526525
// Three bidders with (fungible) moola bid for a CryptoCat
527526
test('zoe - secondPriceAuction non-fungible asset', async t => {
528527
t.plan(30);
529-
const { ccIssuer, moolaIssuer, ccMint, moolaMint, cryptoCats, moola, zoe } =
530-
setupMixed();
528+
const {
529+
ccIssuer,
530+
moolaIssuer,
531+
ccMint,
532+
moolaMint,
533+
cryptoCats,
534+
moola,
535+
zoe,
536+
vatAdminState,
537+
} = setupMixed();
531538
const invitationIssuer = await E(zoe).getInvitationIssuer();
532539

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

555562
// Pack the contract.
556563
const bundle = await bundleSource(auctionRoot);
557-
558-
const installation = await E(zoe).install(bundle);
564+
vatAdminState.installBundle('b1-auction', bundle);
565+
const installation = await E(zoe).installBundleID('b1-auction');
559566
const issuerKeywordRecord = harden({
560567
Asset: ccIssuer,
561568
Ask: moolaIssuer,
@@ -812,7 +819,8 @@ test('zoe - secondPriceAuction non-fungible asset', async t => {
812819

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

817825
const makeAlice = async (timer, moolaPayment) => {
818826
const moolaPurse = await E(moolaKit.issuer).makeEmptyPurse();
@@ -822,7 +830,8 @@ test('zoe - firstPriceAuction w/ 3 bids', async t => {
822830
// pack the contract
823831
const bundle = await bundleSource(auctionRoot);
824832
// install the contract
825-
const installationP = E(zoe).install(bundle);
833+
vatAdminState.installBundle('b1-auction', bundle);
834+
const installationP = E(zoe).installBundleID('b1-auction');
826835
return installationP;
827836
},
828837
startInstance: async installation => {

0 commit comments

Comments
 (0)