Skip to content

Commit

Permalink
chore: improved comments and formatting and moving functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jul 27, 2023
1 parent b472773 commit 5813535
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 117 deletions.
102 changes: 2 additions & 100 deletions packages/vats/test/bootstrapTests/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,14 @@ import { loadSwingsetConfigFile } from '@agoric/swingset-vat';
import { E } from '@endo/eventual-send';
import { makeQueue } from '@endo/stream';
import { TimeMath } from '@agoric/time';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';

import * as processAmbient from 'child_process';
import {
boardSlottingMarshaller,
makeAgoricNamesRemotesFromFakeStorage,
slotToBoardRemote,
} from '../../tools/board-utils.js';
import { makeWalletFactoryDriver, makeZoeDriver } from './drivers.js';

// to retain for ESlint, used by typedef
E;

// main/production config doesn't have initialPrice, upon which 'open vaults' depends
const PLATFORM_CONFIG = '@agoric/vats/decentral-itest-vaults-config.json';

const sink = () => {};

const trace = makeTracer('BSTSupport', false);
Expand Down Expand Up @@ -231,7 +223,7 @@ export const getNodeTestVaultsConfig = async (
* @param {Pick<typeof import('node:child_process'), 'execFileSync'>} powers.childProcess
* @param {typeof import('node:fs/promises')} powers.fs
*/
const makeProposalExtractor = ({ childProcess, fs }) => {
export const makeProposalExtractor = ({ childProcess, fs }) => {
const getPkgPath = (pkg, fileName = '') =>
new URL(`../../../${pkg}/${fileName}`, import.meta.url).pathname;

Expand Down Expand Up @@ -318,6 +310,7 @@ const makeProposalExtractor = ({ childProcess, fs }) => {
};
return buildAndExtract;
};
harden(makeProposalExtractor);

/**
* Start a SwingSet kernel to be shared across all tests. By default Ava tests
Expand Down Expand Up @@ -502,94 +495,3 @@ export const makeSwingsetTestKit = async (
timer,
};
};

/** @typedef {Awaited<ReturnType<typeof makeSwingsetTestKit>>} SwingsetTestKit */

export const makeTestContext = async t => {
console.time('DefaultTestContext');
/** @type {SwingsetTestKit} */
const swingsetTestKit = await makeSwingsetTestKit(t, 'bundles/vaults', {
configSpecifier: PLATFORM_CONFIG,
});

const { runUtils, storage } = swingsetTestKit;
console.timeLog('DefaultTestContext', 'swingsetTestKit');
const { EV } = runUtils;

// Wait for ATOM to make it into agoricNames
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');
console.timeLog('DefaultTestContext', 'vaultFactoryKit');

await eventLoopIteration();

// has to be late enough for agoricNames data to have been published
const agoricNamesRemotes = makeAgoricNamesRemotesFromFakeStorage(
swingsetTestKit.storage,
);
agoricNamesRemotes.brand.ATOM || Fail`ATOM brand not yet defined`;
console.timeLog('DefaultTestContext', 'agoricNamesRemotes');

const walletFactoryDriver = await makeWalletFactoryDriver(
runUtils,
storage,
agoricNamesRemotes,
);
console.timeLog('DefaultTestContext', 'walletFactoryDriver');

console.timeEnd('DefaultTestContext');

const buildProposal = makeProposalExtractor({
childProcess: processAmbient,
fs: fsAmbientPromises,
});

return {
...swingsetTestKit,
agoricNamesRemotes,
walletFactoryDriver,
buildProposal,
};
};

export const makeZoeTestContext = async t => {
console.time('DefaultTestContext');
/** @type {SwingsetTestKit} */
const swingsetTestKit = await makeSwingsetTestKit(t, 'bundles/zoe', {
configSpecifier: '@agoric/vats/decentral-demo-config.json',
});

const { controller, runUtils } = swingsetTestKit;
console.timeLog('DefaultTestContext', 'swingsetTestKit');
const { EV } = runUtils;

await eventLoopIteration();

// We don't need vaults, but this gets the brand, which is checked somewhere
// Wait for ATOM to make it into agoricNames
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');
console.timeLog('DefaultTestContext', 'vaultFactoryKit');

// has to be late enough for agoricNames data to have been published
const agoricNamesRemotes = makeAgoricNamesRemotesFromFakeStorage(
swingsetTestKit.storage,
);
console.timeLog('DefaultTestContext', 'agoricNamesRemotes');

const zoeDriver = await makeZoeDriver(swingsetTestKit);
console.timeLog('DefaultTestContext', 'walletFactoryDriver');

console.timeEnd('DefaultTestContext');

const buildProposal = makeProposalExtractor({
childProcess: processAmbient,
fs: fsAmbientPromises,
});

return {
...swingsetTestKit,
controller,
agoricNamesRemotes,
zoeDriver,
buildProposal,
};
};
59 changes: 58 additions & 1 deletion packages/vats/test/bootstrapTests/test-vats-restart.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,69 @@
// @ts-check
/** @file Bootstrap test of restarting (almost) all vats */
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';

import processAmbient from 'child_process';
import { promises as fsAmbientPromises } from 'fs';

import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { makeTestContext } from './supports.js';
import { makeAgoricNamesRemotesFromFakeStorage } from '../../tools/board-utils.js';
import { makeWalletFactoryDriver } from './drivers.js';
import { makeProposalExtractor, makeSwingsetTestKit } from './supports.js';

const { Fail } = assert;

/** @file Bootstrap test of restarting (almost) all vats */

// main/production config doesn't have initialPrice, upon which 'open vaults' depends
const PLATFORM_CONFIG = '@agoric/vats/decentral-itest-vaults-config.json';
/** @typedef {Awaited<ReturnType<typeof makeSwingsetTestKit>>} SwingsetTestKit */

export const makeTestContext = async t => {
console.time('DefaultTestContext');
/** @type {SwingsetTestKit} */
const swingsetTestKit = await makeSwingsetTestKit(t, 'bundles/vaults', {
configSpecifier: PLATFORM_CONFIG,
});

const { runUtils, storage } = swingsetTestKit;
console.timeLog('DefaultTestContext', 'swingsetTestKit');
const { EV } = runUtils;

// Wait for ATOM to make it into agoricNames
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');
console.timeLog('DefaultTestContext', 'vaultFactoryKit');

await eventLoopIteration();

// has to be late enough for agoricNames data to have been published
const agoricNamesRemotes = makeAgoricNamesRemotesFromFakeStorage(
swingsetTestKit.storage,
);
agoricNamesRemotes.brand.ATOM || Fail`ATOM brand not yet defined`;
console.timeLog('DefaultTestContext', 'agoricNamesRemotes');

const walletFactoryDriver = await makeWalletFactoryDriver(
runUtils,
storage,
agoricNamesRemotes,
);
console.timeLog('DefaultTestContext', 'walletFactoryDriver');

console.timeEnd('DefaultTestContext');

const buildProposal = makeProposalExtractor({
childProcess: processAmbient,
fs: fsAmbientPromises,
});

return {
...swingsetTestKit,
agoricNamesRemotes,
walletFactoryDriver,
buildProposal,
};
};
/**
* @type {import('ava').TestFn<
* Awaited<ReturnType<typeof makeTestContext>>
Expand Down
92 changes: 76 additions & 16 deletions packages/vats/test/bootstrapTests/test-zcf-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,91 @@

import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import bundleSource from '@endo/bundle-source';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';

import path from 'path';
import { makeZoeTestContext } from './supports.js';
import processAmbient from 'child_process';
import { promises as fsAmbientPromises } from 'fs';

import { makeAgoricNamesRemotesFromFakeStorage } from '../../tools/board-utils.js';
import { makeZoeDriver } from './drivers.js';
import { makeProposalExtractor, makeSwingsetTestKit } from './supports.js';

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

const ZCF_PROBE_SRC = './zcfProbe.js';

/** @typedef {Awaited<ReturnType<typeof makeSwingsetTestKit>>} SwingsetTestKit */

/**
* @file Bootstrap test of upgrading ZCF to support atomicRearrange internally.
*
* The goal is to tell Zoe about a new version of ZCF that it should use
* when starting new contracts. Zoe wasn't previously configurable for that, so
* a prerequisite was to upgrade Zoe to a version that could have its ZCF
* updated. To test that we install a contract that can detect the variation
* among zcf versions, and run it before, in the middle and after the upgrades.
* The goal is to tell Zoe about a new version of ZCF that it should use when
* starting new contracts. Zoe wasn't previously configurable for that, so a
* prerequisite was to upgrade Zoe to a version that could have its ZCF
* updated. To test that we install a contract that can detect the variation
* among zcf versions, and run it before, in the middle and after the
* upgrades.
*
* 0. add a contract that can report on the state of ZCF's support for
* different versions of reallocation: staging, helper, and internal.
* 1. put new Zoe & ZCF bundles on chain
* 2. upgrade Zoe; return a new facet that supports ZCF update
* 3. tell Zoe to use new ZCF
* 4. restart the new contract; verify that the behavior is unchanged.
* 5. null upgrade the contract; verify that zcf supports internal rearrange.
* 6. [optional] fully upgrade the contract; verify that it works
* 0. add a contract that can report on the state of ZCF's support for different
* versions of reallocation: staging, helper, and internal.
* 1. put new Zoe & ZCF bundles on chain
* 2. upgrade Zoe; return a new facet that supports ZCF update
* 3. tell Zoe to use new ZCF
* 4. restart the new contract; verify that the behavior is unchanged.
* 5. null upgrade the contract; verify that zcf supports internal rearrange.
* 6. [optional] fully upgrade the contract; verify that it works
*/

/** @type {import('ava').TestFn<Awaited<ReturnType<typeof makeZoeTestContext>>>} */
export const makeZoeTestContext = async t => {
console.time('ZoeTestContext');
/** @type {SwingsetTestKit} */
const swingsetTestKit = await makeSwingsetTestKit(t, 'bundles/zoe', {
configSpecifier: '@agoric/vats/decentral-demo-config.json',
});

const { controller, runUtils } = swingsetTestKit;
console.timeLog('DefaultTestContext', 'swingsetTestKit');
const { EV } = runUtils;

await eventLoopIteration();

// We don't need vaults, but this gets the brand, which is checked somewhere
// Wait for ATOM to make it into agoricNames
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');
console.timeLog('DefaultTestContext', 'vaultFactoryKit');

// has to be late enough for agoricNames data to have been published
const agoricNamesRemotes = makeAgoricNamesRemotesFromFakeStorage(
swingsetTestKit.storage,
);
console.timeLog('DefaultTestContext', 'agoricNamesRemotes');

const zoeDriver = await makeZoeDriver(swingsetTestKit);
console.timeLog('DefaultTestContext', 'walletFactoryDriver');

console.timeEnd('DefaultTestContext');

const buildProposal = makeProposalExtractor({
childProcess: processAmbient,
fs: fsAmbientPromises,
});

return {
...swingsetTestKit,
controller,
agoricNamesRemotes,
zoeDriver,
buildProposal,
};
};

/**
* @type {import('ava').TestFn<
* Awaited<ReturnType<typeof makeZoeTestContext>>
* >}
*/
const test = anyTest;

test.before(async t => {
Expand Down Expand Up @@ -67,7 +123,11 @@ test('run restart-vats proposal', async t => {
const source = `${dirname}/${ZCF_PROBE_SRC}`;

const zcfProbeBundle = await bundleSource(source);
// uncomment and add `import fs from "fs";` to generate a bundle of the prober contract
// This test self-sufficiently builds all the artifacts it needs. The test in
// .../packages/deployment/upgradeTest/upgradeTest-scripts/agoric-upgrade-11/zoe-upgrade/
// needs a bundled copy of ./zcfProbe.js as of the final commit that will be
// installed on-chain. Uncomment the following line and add
// `import fs from "fs";` to generate a bundle of the contract.
// fs.writeFileSync('bundles/prober-contract-bundle.json', JSON.stringify(zcfProbeBundle));

const brandRecord = await zoeDriver.instantiateProbeContract(zcfProbeBundle);
Expand Down

0 comments on commit 5813535

Please sign in to comment.