Skip to content

Commit

Permalink
Merge pull request #4684 from Agoric/4565-update-zoe-tests
Browse files Browse the repository at this point in the history
test(zoe): switch to E(zoe).installBundleID()
  • Loading branch information
mergify[bot] authored Mar 4, 2022
2 parents 55155d3 + 96e5512 commit d989e62
Show file tree
Hide file tree
Showing 48 changed files with 463 additions and 197 deletions.
8 changes: 4 additions & 4 deletions packages/zoe/test/swingsetTests/brokenContracts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import { E } from '@agoric/eventual-send';
import { Far } from '@endo/marshal';
import { makeIssuerKit, AmountMath } from '@agoric/ertp';
/* eslint-disable import/extensions, import/no-unresolved */
import crashingAutoRefund from './bundle-crashingAutoRefund';
/* eslint-enable import/extensions, import/no-unresolved */

const setupBasicMints = () => {
const all = [
Expand Down Expand Up @@ -40,14 +37,17 @@ const makeVats = (log, vats, zoe, installations, startingValues) => {
};

export function buildRootObject(vatPowers, vatParameters) {
const { D } = vatPowers;
return Far('root', {
async bootstrap(vats, devices) {
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService(
devices.vatAdmin,
);
const zoe = await E(vats.zoe).buildZoe(vatAdminSvc);
const bcap = await E(vatAdminSvc).getNamedBundleCap('crashingAutoRefund');
const id = D(bcap).getBundleID();
const installations = {
crashAutoRefund: await E(zoe).install(crashingAutoRefund.bundle),
crashAutoRefund: await E(zoe).installBundleID(id),
};

const [testName, startingValues] = vatParameters.argv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,25 @@ import path from 'path';

import { loadBasedir, buildVatController } from '@agoric/swingset-vat';
import bundleSource from '@endo/bundle-source';
import fs from 'fs';
import zcfBundle from '../../../bundles/bundle-contractFacet.js';

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

const CONTRACT_FILES = ['crashingAutoRefund'];
const contractBundles = {};
const generateBundlesP = Promise.all(
CONTRACT_FILES.map(async contract => {
const bundle = await bundleSource(`${dirname}/${contract}`);
const obj = { bundle, contract };
fs.writeFileSync(
`${dirname}/bundle-${contract}.js`,
`export default ${JSON.stringify(obj)};`,
);
contractBundles[contract] = { bundle };
}),
);

async function main(argv) {
const config = await loadBasedir(dirname);
config.defaultManagerType = 'xs-worker';
config.bundles = { zcf: { bundle: zcfBundle } };
await generateBundlesP;
config.bundles = { zcf: { bundle: zcfBundle }, ...contractBundles };
const controller = await buildVatController(config, argv);
await controller.run();
return controller.dump();
Expand Down
10 changes: 7 additions & 3 deletions packages/zoe/test/swingsetTests/makeKind/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { E } from '@agoric/eventual-send';
import { Far } from '@endo/marshal';

export function buildRootObject(vatPowers, vatParameters) {
const { contractBundles: cb } = vatParameters;
export function buildRootObject(vatPowers) {
const { D } = vatPowers;
return Far('root', {
async bootstrap(vats, devices) {
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService(
devices.vatAdmin,
);
const zoe = await E(vats.zoe).buildZoe(vatAdminSvc);
const bcap = await E(vatAdminSvc).getNamedBundleCap(
'minimalMakeKindContract',
);
const id = D(bcap).getBundleID();
const installations = {
minimalMakeKind: await E(zoe).install(cb.minimalMakeKindContract),
minimalMakeKind: await E(zoe).installBundleID(id),
};

const aliceP = E(vats.alice).build(zoe, installations);
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/test/swingsetTests/makeKind/test-makeKind.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.before(async t => {
}
const source = `${dirname}/../../${contractPath}`;
const bundle = await bundleSource(source);
contractBundles[bundleName] = bundle;
contractBundles[bundleName] = { bundle };
}),
);
const step3 = Date.now();
Expand All @@ -49,10 +49,10 @@ test.before(async t => {
const bootstrapSource = `${dirname}/bootstrap.js`;
vats.bootstrap = {
bundle: await bundleSource(bootstrapSource),
parameters: { contractBundles }, // argv will be added to this
parameters: {}, // argv will be added to this
};
const config = { bootstrap: 'bootstrap', vats };
config.bundles = { zcf: { bundle: zcfBundle } };
config.bundles = { zcf: { bundle: zcfBundle }, ...contractBundles };
config.defaultManagerType = 'xs-worker';

const step4 = Date.now();
Expand Down
10 changes: 7 additions & 3 deletions packages/zoe/test/swingsetTests/offerArgs/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { E } from '@agoric/eventual-send';
import { Far } from '@endo/marshal';

export function buildRootObject(vatPowers, vatParameters) {
const { contractBundles: cb } = vatParameters;
export function buildRootObject(vatPowers) {
const { D } = vatPowers;
return Far('root', {
async bootstrap(vats, devices) {
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService(
devices.vatAdmin,
);
const zoe = await E(vats.zoe).buildZoe(vatAdminSvc);
const bcap = await E(vatAdminSvc).getNamedBundleCap(
'offerArgsUsageContract',
);
const id = D(bcap).getBundleID();
const installations = {
offerArgsUsageContract: await E(zoe).install(cb.offerArgsUsageContract),
offerArgsUsageContract: await E(zoe).installBundleID(id),
};

const aliceP = E(vats.alice).build(zoe, installations);
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/test/swingsetTests/offerArgs/test-offerArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.before(async t => {
}
const source = `${dirname}/../../${contractPath}`;
const bundle = await bundleSource(source);
contractBundles[bundleName] = bundle;
contractBundles[bundleName] = { bundle };
}),
);
const step3 = Date.now();
Expand All @@ -49,10 +49,10 @@ test.before(async t => {
const bootstrapSource = `${dirname}/bootstrap.js`;
vats.bootstrap = {
bundle: await bundleSource(bootstrapSource),
parameters: { contractBundles }, // argv will be added to this
parameters: {}, // argv will be added to this
};
const config = { bootstrap: 'bootstrap', vats };
config.bundles = { zcf: { bundle: zcfBundle } };
config.bundles = { zcf: { bundle: zcfBundle }, ...contractBundles };
config.defaultManagerType = 'xs-worker';

const step4 = Date.now();
Expand Down
12 changes: 7 additions & 5 deletions packages/zoe/test/swingsetTests/privateArgs/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { E } from '@agoric/eventual-send';
import { Far } from '@endo/marshal';

export function buildRootObject(vatPowers, vatParameters) {
const { contractBundles: cb } = vatParameters;
export function buildRootObject(vatPowers) {
const { D } = vatPowers;
return Far('root', {
async bootstrap(vats, devices) {
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService(
devices.vatAdmin,
);
const zoe = await E(vats.zoe).buildZoe(vatAdminSvc);
const bcap = await E(vatAdminSvc).getNamedBundleCap(
'privateArgsUsageContract',
);
const id = D(bcap).getBundleID();
const installations = {
privateArgsUsageContract: await E(zoe).install(
cb.privateArgsUsageContract,
),
privateArgsUsageContract: await E(zoe).installBundleID(id),
};

const aliceP = E(vats.alice).build(zoe, installations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.before(async t => {
}
const source = `${dirname}/../../${contractPath}`;
const bundle = await bundleSource(source);
contractBundles[bundleName] = bundle;
contractBundles[bundleName] = { bundle };
}),
);
const step3 = Date.now();
Expand All @@ -49,10 +49,10 @@ test.before(async t => {
const bootstrapSource = `${dirname}/bootstrap.js`;
vats.bootstrap = {
bundle: await bundleSource(bootstrapSource),
parameters: { contractBundles }, // argv will be added to this
parameters: {}, // argv will be added to this
};
const config = { bootstrap: 'bootstrap', vats };
config.bundles = { zcf: { bundle: zcfBundle } };
config.bundles = { zcf: { bundle: zcfBundle }, ...contractBundles };
config.defaultManagerType = 'xs-worker';

const step4 = Date.now();
Expand Down
16 changes: 11 additions & 5 deletions packages/zoe/test/swingsetTests/runMint/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import { E } from '@agoric/eventual-send';
import { Far } from '@endo/marshal';

export function buildRootObject(vatPowers, vatParameters) {
const { contractBundles: cb } = vatParameters;
const { D } = vatPowers;
return Far('root', {
async bootstrap(vats, devices) {
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService(
devices.vatAdmin,
);
const { zoe, feeMintAccess } = await E(vats.zoe).buildZoe(vatAdminSvc);
const installations = {
runMintContract: await E(zoe).install(cb.runMintContract),
offerArgsUsageContract: await E(zoe).install(cb.offerArgsUsageContract),
};
const installations = {};
const installedPs = vatParameters.contractNames.map(name =>
E(vatAdminSvc)
.getNamedBundleCap(name)
.then(bcap => E(zoe).installBundleID(D(bcap).getBundleID()))
.then(installation => {
installations[name] = installation;
}),
);
await Promise.all(installedPs);

const aliceP = E(vats.alice).build(zoe, installations, feeMintAccess);
await E(aliceP).runMintTest();
Expand Down
8 changes: 5 additions & 3 deletions packages/zoe/test/swingsetTests/runMint/test-runMint.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test.before(async t => {
const kernelBundles = await buildKernelBundles();
const step2 = Date.now();
const contractBundles = {};
const contractNames = [];
await Promise.all(
CONTRACT_FILES.map(async settings => {
let bundleName;
Expand All @@ -36,7 +37,8 @@ test.before(async t => {
}
const source = `${dirname}/../../${contractPath}`;
const bundle = await bundleSource(source);
contractBundles[bundleName] = bundle;
contractBundles[bundleName] = { bundle };
contractNames.push(bundleName);
}),
);
const step3 = Date.now();
Expand All @@ -52,10 +54,10 @@ test.before(async t => {
const bootstrapSource = `${dirname}/bootstrap.js`;
vats.bootstrap = {
bundle: await bundleSource(bootstrapSource),
parameters: { contractBundles }, // argv will be added to this
parameters: { contractNames }, // argv will be added to this
};
const config = { bootstrap: 'bootstrap', vats };
config.bundles = { zcf: { bundle: zcfBundle } };
config.bundles = { zcf: { bundle: zcfBundle }, ...contractBundles };
config.defaultManagerType = 'xs-worker';

const step4 = Date.now();
Expand Down
24 changes: 12 additions & 12 deletions packages/zoe/test/swingsetTests/zoe/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,24 @@ const makeVats = (log, vats, zoe, installations, startingValues) => {
};

export function buildRootObject(vatPowers, vatParameters) {
const { argv, contractBundles: cb } = vatParameters;
const { D } = vatPowers;
const { argv } = vatParameters;
return Far('root', {
async bootstrap(vats, devices) {
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService(
devices.vatAdmin,
);
const zoe = await E(vats.zoe).buildZoe(vatAdminSvc);
const installations = {
automaticRefund: await E(zoe).install(cb.automaticRefund),
coveredCall: await E(zoe).install(cb.coveredCall),
secondPriceAuction: await E(zoe).install(cb.secondPriceAuction),
atomicSwap: await E(zoe).install(cb.atomicSwap),
simpleExchange: await E(zoe).install(cb.simpleExchange),
autoswap: await E(zoe).install(cb.autoswap),
sellItems: await E(zoe).install(cb.sellItems),
mintAndSellNFT: await E(zoe).install(cb.mintAndSellNFT),
otcDesk: await E(zoe).install(cb.otcDesk),
};
const installations = {};
const installedPs = vatParameters.contractNames.map(name =>
E(vatAdminSvc)
.getNamedBundleCap(name)
.then(bcap => E(zoe).installBundleID(D(bcap).getBundleID()))
.then(installation => {
installations[name] = installation;
}),
);
await Promise.all(installedPs);

const [testName, startingValues] = argv;

Expand Down
8 changes: 5 additions & 3 deletions packages/zoe/test/swingsetTests/zoe/test-zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test.before(async t => {
const kernelBundles = await buildKernelBundles();
const step2 = Date.now();
const contractBundles = {};
const contractNames = [];
await Promise.all(
CONTRACT_FILES.map(async settings => {
let bundleName;
Expand All @@ -47,10 +48,11 @@ test.before(async t => {
}
const source = `${dirname}/../../../src/contracts/${contractPath}.js`;
const bundle = await bundleSource(source);
contractBundles[bundleName] = bundle;
contractBundles[bundleName] = { bundle };
contractNames.push(bundleName);
}),
);
const bundles = { zcf: { bundle: zcfBundle } };
const bundles = { zcf: { bundle: zcfBundle }, ...contractBundles };
const step3 = Date.now();

const vats = {};
Expand All @@ -64,7 +66,7 @@ test.before(async t => {
const bootstrapSource = `${dirname}/bootstrap.js`;
vats.bootstrap = {
bundle: await bundleSource(bootstrapSource),
parameters: { contractBundles }, // argv will be added to this
parameters: { contractNames }, // argv will be added to this
};
const config = { bootstrap: 'bootstrap', vats, bundles };
config.defaultManagerType = 'xs-worker';
Expand Down
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
Loading

0 comments on commit d989e62

Please sign in to comment.