Skip to content

Commit

Permalink
feat(liveslots-tools): return incarnation in test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Sep 21, 2024
1 parent c0152bc commit 11171f9
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions packages/swingset-liveslots/tools/prepare-strict-test-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,55 @@ import { Fail } from '@endo/errors';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { makeUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';

export { flushIncarnation } from './setup-vat-data.js';
export { eventLoopIteration as nextCrank };

/** @type {ReturnType<typeof reincarnate>} */
/**
* @import { ReincarnateOptions } from './setup-vat-data.js'
*/

/** @type {ReincarnateOptions} */
let incarnation;
let incarnationNumber = 0;

export const annihilate = () => {
incarnation = reincarnate({ relaxDurabilityRules: false });
/** @param {Omit<ReincarnateOptions, 'fakeVomKit' | 'fakeStore'>} [options] */
export const annihilate = (options = {}) => {
// @ts-expect-error
const { fakeStore: _fs, fakeVomKit: _fvk, ...opts } = options;
incarnation = reincarnate({ relaxDurabilityRules: false, ...opts });
incarnationNumber = 0;
return incarnation;
};

export const getBaggage = () => {
return incarnation.fakeVomKit.cm.provideBaggage();
};

export const nextLife = () => {
incarnation = reincarnate(incarnation);
/**
* @param {ReincarnateOptions} [fromIncarnation]
*/
export const nextLife = (fromIncarnation = incarnation) => {
incarnation = reincarnate(fromIncarnation);
incarnationNumber += 1;
return incarnation;
};

/**
* @template {(baggage: import('@agoric/swingset-liveslots').Baggage) => Promise<any> | any} B
* @param {B} build
* @param {(tools: Awaited<ReturnType<B>>) => Promise<void> | void} [run]
* @param {object} [options]
* @param {ReincarnateOptions} [options.fromIncarnation]
*/
export const startLife = async (build, run) => {
export const startLife = async (build, run, { fromIncarnation } = {}) => {
await eventLoopIteration();
const oldIncarnationNumber = incarnationNumber;
const oldIncarnation = incarnation;
const disconnectionObject = makeUpgradeDisconnection(
'vat upgraded',
oldIncarnationNumber,
);
nextLife();
const { fakeVomKit } = incarnation;
const { fakeVomKit } = nextLife(fromIncarnation);
/** @type {Map<string, import('@endo/promise-kit').PromiseKit<any>>} */
const previouslyWatchedPromises = new Map();
let buildTools;
Expand Down Expand Up @@ -93,6 +107,8 @@ export const startLife = async (build, run) => {
await run(buildTools);
await eventLoopIteration();
}

return incarnation;
};

// Setup the initial incarnation
Expand Down

0 comments on commit 11171f9

Please sign in to comment.