diff --git a/packages/vats/test/bootstrapTests/supports.js b/packages/vats/test/bootstrapTests/supports.js index ee9dc71df36..21cd6c1ec8b 100644 --- a/packages/vats/test/bootstrapTests/supports.js +++ b/packages/vats/test/bootstrapTests/supports.js @@ -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); @@ -231,7 +223,7 @@ export const getNodeTestVaultsConfig = async ( * @param {Pick} 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; @@ -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 @@ -502,94 +495,3 @@ export const makeSwingsetTestKit = async ( timer, }; }; - -/** @typedef {Awaited>} 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, - }; -}; diff --git a/packages/vats/test/bootstrapTests/test-vats-restart.js b/packages/vats/test/bootstrapTests/test-vats-restart.js index 93431478f9f..d1358bef893 100644 --- a/packages/vats/test/bootstrapTests/test-vats-restart.js +++ b/packages/vats/test/bootstrapTests/test-vats-restart.js @@ -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>} 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> diff --git a/packages/vats/test/bootstrapTests/test-zcf-upgrade.js b/packages/vats/test/bootstrapTests/test-zcf-upgrade.js index 9ef41fd6930..2c1a73f30b5 100644 --- a/packages/vats/test/bootstrapTests/test-zcf-upgrade.js +++ b/packages/vats/test/bootstrapTests/test-zcf-upgrade.js @@ -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>} 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>>} */ +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> + * >} + */ const test = anyTest; test.before(async t => { @@ -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);