Skip to content

Commit

Permalink
Merge pull request #9050 from Agoric/ta/runutils-tests
Browse files Browse the repository at this point in the history
misc RunUtils test improvements
  • Loading branch information
mergify[bot] authored Mar 8, 2024
2 parents c5284e4 + 62c1842 commit 32c4d68
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 121 deletions.
23 changes: 2 additions & 21 deletions packages/boot/test/bootstrapTests/test-addAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ test.before(async t => {
'@agoric/builders/scripts/inter-protocol/add-STARS.js',
);

t.log('installing proposal');
// share a single proposal so tests don't stomp on each other's files; It has
// to be edited by each so as not to re-use keywords.
for await (const bundle of proposal.bundles) {
await context.controller.validateAndInstallBundle(bundle);
}
t.log('installed', proposal.bundles.length, 'bundles');

const getCollateralProposal = (name, id) => {
// stringify, modify and parse because modifying a deep copy was fragile.
const proposalJSON = JSON.stringify(proposal);
Expand All @@ -46,7 +38,6 @@ test.before(async t => {
...context,
getCollateralProposal,
};
t.log('installed', proposal.bundles.length, 'bundles');
});

test.after.always(t => {
Expand All @@ -59,13 +50,9 @@ test.after.always(t => {
});

test('addAsset to quiescent auction', async t => {
const { advanceTimeTo, readLatest } = t.context;
const { advanceTimeTo, evalProposal, readLatest } = t.context;

const proposal = t.context.getCollateralProposal('COMETS', 'A');
const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};
await evalProposal(t.context.getCollateralProposal('COMETS', 'A'));

const { EV } = t.context.runUtils;

Expand All @@ -82,12 +69,6 @@ test('addAsset to quiescent auction', async t => {
const nextQuiescentTime = TimeMath.addAbsRel(nextEndTime, fiveMinutes);
await advanceTimeTo(nextQuiescentTime);

const coreEvalBridgeHandler = await EV.vat('bootstrap').consumeItem(
'coreEvalBridgeHandler',
);
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
t.log('proposal executed');

t.like(readLatest(`${auctioneerPath}.book1`), {
currentPriceLevel: null,
});
Expand Down
54 changes: 6 additions & 48 deletions packages/boot/test/bootstrapTests/test-vats-restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,10 @@ export const makeTestContext = async t => {

console.timeEnd('DefaultTestContext');

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

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

Expand Down Expand Up @@ -98,31 +92,13 @@ test.serial('open vault', async t => {
});

test.serial('run network vat proposal', async t => {
const { controller, buildProposal } = t.context;
const { buildProposal, evalProposal } = t.context;

t.log('building network proposal');
const proposal = await buildProposal(
'@agoric/builders/scripts/vats/init-network.js',
await evalProposal(
buildProposal('@agoric/builders/scripts/vats/init-network.js'),
);

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}
t.log('installed', proposal.bundles.length, 'bundles');

t.log('executing proposal');
const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};
t.log({ bridgeMessage });
const { EV } = t.context.runUtils;
const coreEvalBridgeHandler: BridgeHandler = await EV.vat(
'bootstrap',
).consumeItem('coreEvalBridgeHandler');
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);

t.log('network proposal executed');
t.pass(); // reached here without throws
});

Expand All @@ -141,31 +117,13 @@ test.serial('register network protocol before upgrade', async t => {
});

test.serial('run restart-vats proposal', async t => {
const { controller, buildProposal } = t.context;
const { controller, buildProposal, evalProposal } = t.context;

t.log('building proposal');
const proposal = await buildProposal(
'@agoric/builders/scripts/vats/restart-vats.js',
await evalProposal(
buildProposal('@agoric/builders/scripts/vats/restart-vats.js'),
);

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}
t.log('installed', proposal.bundles.length, 'bundles');

t.log('launching proposal');
const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};
t.log({ bridgeMessage });
const { EV } = t.context.runUtils;
const coreEvalBridgeHandler: BridgeHandler = await EV.vat(
'bootstrap',
).consumeItem('coreEvalBridgeHandler');
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);

t.log('restart-vats proposal executed');
t.pass(); // reached here without throws
});

Expand Down
26 changes: 4 additions & 22 deletions packages/boot/test/bootstrapTests/test-walletSurvivesZoeRestart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,19 @@ test.serial('wallet survives zoe null upgrade', async t => {
const collateralBrandKey = 'ATOM';
const managerIndex = 0;

const { walletFactoryDriver, setupVaults, controller, buildProposal } =
const { walletFactoryDriver, setupVaults, buildProposal, evalProposal } =
t.context;

const { EV } = t.context.runUtils;

const buyer = await walletFactoryDriver.provideSmartWallet('agoric1buyer');

const buildAndExecuteProposal = async (packageSpec: string) => {
const proposal = await buildProposal(packageSpec);

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}

const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};

const coreEvalBridgeHandler: ERef<BridgeHandler> = await EV.vat(
'bootstrap',
).consumeItem('coreEvalBridgeHandler');
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
};

await setupVaults(collateralBrandKey, managerIndex, setup);

// restart Zoe

// /////// Upgrading ////////////////////////////////
await buildAndExecuteProposal('@agoric/builders/scripts/vats/upgrade-zoe.js');
await evalProposal(
buildProposal('@agoric/builders/scripts/vats/upgrade-zoe.js'),
);

t.like(await buyer.getLatestUpdateRecord(), {
currentAmount: {
Expand Down
33 changes: 4 additions & 29 deletions packages/boot/test/bootstrapTests/test-zcf-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,11 @@ export const makeZoeTestContext = async t => {

console.timeEnd('DefaultTestContext');

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

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

Expand All @@ -94,30 +88,9 @@ test.before(async t => {
test.after.always(t => t.context.shutdown?.());

test('run restart-vats proposal', async t => {
const { controller, buildProposal, zoeDriver } = t.context;
const { controller, buildProposal, evalProposal, zoeDriver } = t.context;
const { EV } = t.context.runUtils;

const buildAndExecuteProposal = async packageSpec => {
const proposal = await buildProposal(packageSpec);

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}

t.log('installed', proposal.bundles.length, 'bundles');

t.log('launching proposal');
const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};

t.log({ bridgeMessage });
const coreEvalBridgeHandler: ERef<BridgeHandler> = await EV.vat(
'bootstrap',
).consumeItem('coreEvalBridgeHandler');
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
};
const source = `${dirname}/${ZCF_PROBE_SRC}`;
const zcfProbeBundle = await bundleSource(source);
await controller.validateAndInstallBundle(zcfProbeBundle);
Expand Down Expand Up @@ -145,7 +118,9 @@ test('run restart-vats proposal', async t => {

t.log('building proposal');
// /////// Upgrading ////////////////////////////////
await buildAndExecuteProposal('@agoric/builders/scripts/vats/replace-zoe.js');
await evalProposal(
buildProposal('@agoric/builders/scripts/vats/replace-zoe.js'),
);

t.log('upgrade zoe&zcf proposal executed');
await zoeDriver.upgradeProbe(zcfProbeBundle);
Expand Down
42 changes: 41 additions & 1 deletion packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { buildSwingset } from '@agoric/cosmic-swingset/src/launch-chain.js';
import { BridgeId, VBankAccount, makeTracer } from '@agoric/internal';
import { unmarshalFromVstorage } from '@agoric/internal/src/marshal.js';
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { krefOf } from '@agoric/kmarshal';
import { initSwingStore } from '@agoric/swing-store';
import { loadSwingsetConfigFile } from '@agoric/swingset-vat';
import { krefOf } from '@agoric/kmarshal';
import { makeSlogSender } from '@agoric/telemetry';
import { TimeMath, Timestamp } from '@agoric/time';
import '@agoric/vats/exported.js';
Expand All @@ -27,6 +27,7 @@ import type { ExecutionContext as AvaT } from 'ava';

import { makeRunUtils } from '@agoric/swingset-vat/tools/run-utils.js';
import type { CoreEvalSDKType } from '@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset';
import type { BridgeHandler } from '@agoric/vats';

const trace = makeTracer('BSTSupport', false);

Expand Down Expand Up @@ -280,11 +281,19 @@ export const makeSwingsetTestKit = async (

let lastNonce = 0n;

const outboundMessages = new Map();

/**
* Mock the bridge outbound handler. The real one is implemented in Golang so
* changes there will sometimes require changes here.
*/
const bridgeOutbound = (bridgeId: string, obj: any) => {
// store all messages for querying by tests
if (!outboundMessages.has(bridgeId)) {
outboundMessages.set(bridgeId, []);
}
outboundMessages.get(bridgeId).push(obj);

switch (bridgeId) {
case BridgeId.BANK: {
trace(
Expand Down Expand Up @@ -340,6 +349,7 @@ export const makeSwingsetTestKit = async (
case BridgeId.DIBC:
case BridgeId.PROVISION:
case BridgeId.PROVISION_SMART_WALLET:
case BridgeId.VTRANSFER:
case BridgeId.WALLET:
console.warn('Bridge returning undefined for', bridgeId, ':', obj);
return undefined;
Expand Down Expand Up @@ -386,6 +396,31 @@ export const makeSwingsetTestKit = async (
fs: fsAmbientPromises,
});

const evalProposal = async (
proposalP: ERef<Awaited<ReturnType<typeof buildProposal>>>,
) => {
const { EV } = runUtils;

const proposal = harden(await proposalP);

for await (const bundle of proposal.bundles) {
await controller.validateAndInstallBundle(bundle);
}
log('installed', proposal.bundles.length, 'bundles');

log('executing proposal');
const bridgeMessage = {
type: 'CORE_EVAL',
evals: proposal.evals,
};
log({ bridgeMessage });
const coreEvalBridgeHandler: BridgeHandler = await EV.vat(
'bootstrap',
).consumeItem('coreEvalBridgeHandler');
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
log(`proposal executed`);
};

console.timeEnd('makeBaseSwingsetTestKit');

let currentTime = 0n;
Expand Down Expand Up @@ -430,12 +465,17 @@ export const makeSwingsetTestKit = async (

const getCrankNumber = () => Number(kernelStorage.kvStore.get('crankNumber'));

const getOutboundMessages = (bridgeId: string) =>
harden([...outboundMessages.get(bridgeId)]);

return {
advanceTimeBy,
advanceTimeTo,
buildProposal,
controller,
evalProposal,
getCrankNumber,
getOutboundMessages,
jumpTimeTo,
readLatest,
runUtils,
Expand Down

0 comments on commit 32c4d68

Please sign in to comment.