diff --git a/packages/SwingSet/package.json b/packages/SwingSet/package.json index ce15fac215f5..5441a8092534 100644 --- a/packages/SwingSet/package.json +++ b/packages/SwingSet/package.json @@ -52,6 +52,7 @@ "@endo/patterns": "^0.2.5", "@endo/promise-kit": "^0.2.59", "@endo/ses-ava": "^0.2.43", + "@endo/stream": "^0.3.28", "@endo/zip": "^0.2.34", "ansi-styles": "^6.2.1", "anylogger": "^0.21.0", diff --git a/packages/SwingSet/tools/run-utils.ts b/packages/SwingSet/tools/run-utils.ts new file mode 100644 index 000000000000..605940e22223 --- /dev/null +++ b/packages/SwingSet/tools/run-utils.ts @@ -0,0 +1,108 @@ +/* eslint-disable @jessie.js/safe-await-separator */ +import { Fail } from '@agoric/assert'; +import { kunser } from '@agoric/kmarshal'; +import { makeQueue } from '@endo/stream'; +import type { E } from '@endo/eventual-send'; + +import type { SwingsetController } from '../src/controller/controller.js'; + +const sink = () => {}; + +export const makeRunUtils = ( + controller: SwingsetController, + log = (..._) => {}, +) => { + let cranksRun = 0; + + const mutex = makeQueue(); + + mutex.put(controller.run()); + + const runThunk = async any>( + thunk: T, + ): Promise> => { + try { + // this promise for the last lock may fail + await mutex.get(); + } catch { + // noop because the result will resolve for the previous runMethod return + } + + const thunkResult = await thunk(); + + const result = controller.run().then(cranks => { + cranksRun += cranks; + log(`kernel ran ${cranks} cranks`); + return thunkResult; + }); + mutex.put(result.then(sink, sink)); + return result; + }; + + const queueAndRun = async (deliveryThunk, voidResult = false) => { + log('queueAndRun at', cranksRun); + + const kpid = await runThunk(deliveryThunk); + + if (voidResult) { + return undefined; + } + const status = controller.kpStatus(kpid); + switch (status) { + case 'fulfilled': + return kunser(controller.kpResolution(kpid)); + case 'rejected': + throw kunser(controller.kpResolution(kpid)); + case 'unresolved': + throw Error(`unresolved value for ${kpid}`); + default: + throw Fail`unknown status ${status}`; + } + }; + + type EVProxy = typeof E & { + sendOnly: (presence: unknown) => Record void>; + vat: (name: string) => Record Promise>; + }; + // @ts-expect-error cast, approximate + const EV: EVProxy = presence => + new Proxy(harden({}), { + get: (_t, method, _rx) => + harden((...args) => + queueAndRun(() => + controller.queueToVatObject(presence, method, args), + ), + ), + }); + EV.vat = vatName => + new Proxy(harden({}), { + get: (_t, method, _rx) => + harden((...args) => + queueAndRun(() => controller.queueToVatRoot(vatName, method, args)), + ), + }); + // @ts-expect-error xxx + EV.sendOnly = presence => + new Proxy(harden({}), { + get: (_t, method, _rx) => + harden((...args) => + queueAndRun( + () => controller.queueToVatObject(presence, method, args), + true, + ), + ), + }); + // @ts-expect-error xxx + EV.get = presence => + new Proxy(harden({}), { + get: (_t, pathElement, _rx) => + queueAndRun(() => + controller.queueToVatRoot('bootstrap', 'awaitVatObject', [ + presence, + [pathElement], + ]), + ), + }); + return harden({ runThunk, EV }); +}; +export type RunUtils = ReturnType; diff --git a/packages/agoric-cli/src/sdk-package-names.js b/packages/agoric-cli/src/sdk-package-names.js index df8d4f3062cc..1f2908ddf7b1 100644 --- a/packages/agoric-cli/src/sdk-package-names.js +++ b/packages/agoric-cli/src/sdk-package-names.js @@ -38,7 +38,6 @@ export default [ "@agoric/swingset-vat", "@agoric/swingset-xsnap-supervisor", "@agoric/telemetry", - "@agoric/test-support", "@agoric/time", "@agoric/vat-data", "@agoric/vats", diff --git a/packages/benchmark/package.json b/packages/benchmark/package.json index c2bfeff1a96c..d0ac7f9484de 100644 --- a/packages/benchmark/package.json +++ b/packages/benchmark/package.json @@ -23,10 +23,10 @@ "license": "Apache-2.0", "dependencies": { "@agoric/assert": "^0.6.0", + "@agoric/boot": "^0.1.0", "@agoric/cosmic-swingset": "^0.41.3", "@agoric/internal": "^0.3.2", "@agoric/inter-protocol": "^0.16.1", - "@agoric/test-support": "^0.1.0", "@agoric/vats": "^0.15.1", "@agoric/zoe": "^0.26.2", "@endo/init": "^0.5.59" diff --git a/packages/benchmark/src/benchmarkerator.js b/packages/benchmark/src/benchmarkerator.js index 79aa734c3c3b..703f2ad6ac3b 100644 --- a/packages/benchmark/src/benchmarkerator.js +++ b/packages/benchmark/src/benchmarkerator.js @@ -13,10 +13,8 @@ import '@agoric/cosmic-swingset/src/launch-chain.js'; import { Fail } from '@agoric/assert'; import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; -import { - makeSwingsetTestKit, - makeWalletFactoryDriver, -} from '@agoric/test-support'; +import { makeSwingsetTestKit } from '@agoric/boot/tools/supports.ts'; +import { makeWalletFactoryDriver } from '@agoric/boot/tools/drivers.ts'; // When I was a child my family took a lot of roadtrips around California to go // camping and backpacking and so on. It was not uncommon in those days (nor is @@ -46,7 +44,7 @@ import { * @typedef {{ * options: Record, * argv: string[], - * actors: Record, + * actors: Record, * title?: string, * rounds?: number, * config?: Record, diff --git a/packages/boot/package.json b/packages/boot/package.json index 1dc5cee3aeff..30fd8e1e81c8 100644 --- a/packages/boot/package.json +++ b/packages/boot/package.json @@ -19,9 +19,16 @@ "author": "Agoric", "license": "Apache-2.0", "dependencies": { + "@agoric/assert": "^0.6.0", "@agoric/builders": "^0.1.0", + "@agoric/cosmic-swingset": "^0.41.3", "@agoric/ertp": "^0.16.2", "@agoric/internal": "^0.3.2", + "@agoric/inter-protocol": "^0.16.1", + "@agoric/kmarshal": "^0.1.0", + "@agoric/swing-store": "^0.9.1", + "@agoric/swingset-vat": "^0.32.2", + "@agoric/time": "^0.3.2", "@agoric/vat-data": "^0.5.2", "@agoric/vats": "^0.15.1", "@agoric/vm-config": "^0.1.0", @@ -37,19 +44,11 @@ "import-meta-resolve": "^2.2.1" }, "devDependencies": { - "@agoric/assert": "^0.6.0", "@agoric/benchmark": "^0.1.0", - "@agoric/cosmic-swingset": "^0.41.3", "@agoric/deploy-script-support": "^0.10.3", "@agoric/governance": "^0.10.3", - "@agoric/inter-protocol": "^0.16.1", - "@agoric/kmarshal": "^0.1.0", "@agoric/store": "^0.9.2", - "@agoric/swing-store": "^0.9.1", "@agoric/swingset-liveslots": "^0.10.2", - "@agoric/swingset-vat": "^0.32.2", - "@agoric/test-support": "^0.1.0", - "@agoric/time": "^0.3.2", "ava": "^5.3.0", "c8": "^7.13.0", "tsx": "^3.12.8" diff --git a/packages/boot/test/bootstrapTests/bench-vaults-performance.js b/packages/boot/test/bootstrapTests/bench-vaults-performance.js index 53c631115073..5c76d3d71033 100644 --- a/packages/boot/test/bootstrapTests/bench-vaults-performance.js +++ b/packages/boot/test/bootstrapTests/bench-vaults-performance.js @@ -12,10 +12,8 @@ import engineGC from '@agoric/internal/src/lib-nodejs/engine-gc.js'; import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; -import { - makeSwingsetTestKit, - makeWalletFactoryDriver, -} from '@agoric/test-support'; +import { makeSwingsetTestKit } from '../../tools/supports.ts'; +import { makeWalletFactoryDriver } from '../../tools/drivers.ts'; /** * @type {import('ava').TestFn< diff --git a/packages/boot/test/bootstrapTests/liquidation.ts b/packages/boot/test/bootstrapTests/liquidation.ts index d3da84ab415d..6ecadfb44b74 100644 --- a/packages/boot/test/bootstrapTests/liquidation.ts +++ b/packages/boot/test/bootstrapTests/liquidation.ts @@ -7,12 +7,12 @@ import { AgoricNamesRemotes, makeAgoricNamesRemotesFromFakeStorage, } from '@agoric/vats/tools/board-utils.js'; +import { makeSwingsetTestKit } from '../../tools/supports.ts'; import { makeGovernanceDriver, makePriceFeedDriver, makeWalletFactoryDriver, - makeSwingsetTestKit, -} from '@agoric/test-support'; +} from '../../tools/drivers.ts'; export const scale6 = x => BigInt(Math.round(x * 1_000_000)); diff --git a/packages/boot/test/bootstrapTests/test-demo-config.ts b/packages/boot/test/bootstrapTests/test-demo-config.ts index 7cf84e6b18c9..f04317f8b6c1 100644 --- a/packages/boot/test/bootstrapTests/test-demo-config.ts +++ b/packages/boot/test/bootstrapTests/test-demo-config.ts @@ -3,7 +3,7 @@ import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { PowerFlags } from '@agoric/vats/src/walletFlags.js'; import type { TestFn } from 'ava'; -import { makeSwingsetTestKit, keyArrayEqual } from '@agoric/test-support'; +import { makeSwingsetTestKit, keyArrayEqual } from '../../tools/supports.ts'; const { keys } = Object; diff --git a/packages/boot/test/bootstrapTests/test-vats-restart.ts b/packages/boot/test/bootstrapTests/test-vats-restart.ts index 205421a51569..e79072a01d7d 100644 --- a/packages/boot/test/bootstrapTests/test-vats-restart.ts +++ b/packages/boot/test/bootstrapTests/test-vats-restart.ts @@ -13,8 +13,8 @@ import type { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals import { makeProposalExtractor, makeSwingsetTestKit, - makeWalletFactoryDriver, -} from '@agoric/test-support'; +} from '../../tools/supports.ts'; +import { makeWalletFactoryDriver } from '../../tools/drivers.ts'; const { Fail } = assert; diff --git a/packages/boot/test/bootstrapTests/test-vaults-integration.ts b/packages/boot/test/bootstrapTests/test-vaults-integration.ts index 8659f5d7321e..eda3c165a98f 100644 --- a/packages/boot/test/bootstrapTests/test-vaults-integration.ts +++ b/packages/boot/test/bootstrapTests/test-vaults-integration.ts @@ -13,10 +13,8 @@ import { } from '@agoric/vats/tools/board-utils.js'; import type { TestFn } from 'ava'; import { ParamChangesOfferArgs } from '@agoric/inter-protocol/src/econCommitteeCharter.js'; -import { - makeSwingsetTestKit, - makeWalletFactoryDriver, -} from '@agoric/test-support'; +import { makeSwingsetTestKit } from '../../tools/supports.ts'; +import { makeWalletFactoryDriver } from '../../tools/drivers.ts'; // presently all these tests use one collateral manager const collateralBrandKey = 'ATOM'; diff --git a/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts b/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts index 5243f7d87e77..d88523ad44a5 100644 --- a/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts +++ b/packages/boot/test/bootstrapTests/test-vaults-upgrade.ts @@ -15,10 +15,8 @@ import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board- import { ExecutionContext, TestFn } from 'ava'; import { FakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; import { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js'; -import { - makeSwingsetTestKit, - makeWalletFactoryDriver, -} from '@agoric/test-support'; +import { makeSwingsetTestKit } from '../../tools/supports.ts'; +import { makeWalletFactoryDriver } from '../../tools/drivers.ts'; // presently all these tests use one collateral manager const collateralBrandKey = 'ATOM'; diff --git a/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts b/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts index 6ba3d84295ce..0417790f96ca 100644 --- a/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts +++ b/packages/boot/test/bootstrapTests/test-zcf-upgrade.ts @@ -13,10 +13,10 @@ import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board- import { TestFn } from 'ava'; import { matchAmount, - makeZoeDriver, makeProposalExtractor, makeSwingsetTestKit, -} from '@agoric/test-support'; +} from '../../tools/supports.ts'; +import { makeZoeDriver } from '../../tools/drivers.ts'; const filename = new URL(import.meta.url).pathname; const dirname = path.dirname(filename); diff --git a/packages/boot/test/upgrading/test-upgrade-vats.js b/packages/boot/test/upgrading/test-upgrade-vats.js index c074375d2bec..2733bcd6c4bf 100644 --- a/packages/boot/test/upgrading/test-upgrade-vats.js +++ b/packages/boot/test/upgrading/test-upgrade-vats.js @@ -3,13 +3,9 @@ import { test as anyTest } from '@agoric/swingset-vat/tools/prepare-test-env-ava import { BridgeId } from '@agoric/internal'; import { buildVatController } from '@agoric/swingset-vat'; +import { makeRunUtils } from '@agoric/swingset-vat/tools/run-utils.ts'; import { resolve as importMetaResolve } from 'import-meta-resolve'; -import { - makeRunUtils, - matchAmount, - matchIter, - matchRef, -} from '@agoric/test-support'; +import { matchAmount, matchIter, matchRef } from '../../tools/supports.ts'; /** * @type {import('ava').TestFn<{}>} diff --git a/packages/test-support/src/drivers.ts b/packages/boot/tools/drivers.ts similarity index 98% rename from packages/test-support/src/drivers.ts rename to packages/boot/tools/drivers.ts index 66c7b9afb019..7280be5a45ce 100644 --- a/packages/test-support/src/drivers.ts +++ b/packages/boot/tools/drivers.ts @@ -22,7 +22,8 @@ import type { WalletFactoryStartResult } from '@agoric/vats/src/core/startWallet import type { OfferSpec } from '@agoric/smart-wallet/src/offers.js'; import type { TimerService } from '@agoric/time/src/types.js'; import type { OfferMaker } from '@agoric/smart-wallet/src/types.js'; -import type { RunUtils, SwingsetTestKit } from './supports.ts'; +import type { RunUtils } from '@agoric/swingset-vat/tools/run-utils.ts'; +import type { SwingsetTestKit } from './supports.ts'; export const makeWalletFactoryDriver = async ( runUtils: RunUtils, diff --git a/packages/test-support/src/supports.ts b/packages/boot/tools/supports.ts similarity index 79% rename from packages/test-support/src/supports.ts rename to packages/boot/tools/supports.ts index 7f675677397a..1b891eb30b8c 100644 --- a/packages/test-support/src/supports.ts +++ b/packages/boot/tools/supports.ts @@ -14,33 +14,20 @@ import { unmarshalFromVstorage } from '@agoric/internal/src/marshal.js'; import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; import { initSwingStore } from '@agoric/swing-store'; import { loadSwingsetConfigFile } from '@agoric/swingset-vat'; -import { krefOf, kunser } from '@agoric/kmarshal'; +import { krefOf } from '@agoric/kmarshal'; import { TimeMath, Timestamp } from '@agoric/time'; import '@agoric/vats/exported.js'; import { boardSlottingMarshaller, slotToBoardRemote, } from '@agoric/vats/tools/board-utils.js'; -import { makeQueue } from '@endo/stream'; -import type { SwingsetController } from '@agoric/swingset-vat/src/controller/controller.js'; -import type { BootstrapRootObject } from '@agoric/vats/src/core/lib-boot'; -import type { E } from '@endo/eventual-send'; import type { ExecutionContext as AvaT } from 'ava'; -const sink = () => {}; +import { makeRunUtils } from '@agoric/swingset-vat/tools/run-utils.ts'; const trace = makeTracer('BSTSupport', false); -export const bootstrapMethods: { [P in keyof BootstrapRootObject]: P } = { - bootstrap: 'bootstrap', - consumeItem: 'consumeItem', - produceItem: 'produceItem', - resetItem: 'resetItem', - awaitVatObject: 'awaitVatObject', - snapshotStore: 'snapshotStore', -}; - const keysToObject = ( keys: K[], valueMaker: (key: K, i: number) => V, @@ -63,105 +50,6 @@ export const keyArrayEqual = ( return t.deepEqual(aobj, bobj, message); }; -export const makeRunUtils = ( - controller: SwingsetController, - log = (..._) => {}, -) => { - let cranksRun = 0; - - const mutex = makeQueue(); - - mutex.put(controller.run()); - - const runThunk = async any>( - thunk: T, - ): Promise> => { - try { - // this promise for the last lock may fail - await mutex.get(); - } catch { - // noop because the result will resolve for the previous runMethod return - } - - const thunkResult = await thunk(); - - const result = controller.run().then(cranks => { - cranksRun += cranks; - log(`kernel ran ${cranks} cranks`); - return thunkResult; - }); - mutex.put(result.then(sink, sink)); - return result; - }; - - const queueAndRun = async (deliveryThunk, voidResult = false) => { - log('queueAndRun at', cranksRun); - - const kpid = await runThunk(deliveryThunk); - - if (voidResult) { - return undefined; - } - const status = controller.kpStatus(kpid); - switch (status) { - case 'fulfilled': - return kunser(controller.kpResolution(kpid)); - case 'rejected': - throw kunser(controller.kpResolution(kpid)); - case 'unresolved': - throw Error(`unresolved value for ${kpid}`); - default: - throw Fail`unknown status ${status}`; - } - }; - - type EVProxy = typeof E & { - sendOnly: (presence: unknown) => Record void>; - vat: (name: string) => Record Promise>; - }; - // @ts-expect-error cast, approximate - const EV: EVProxy = presence => - new Proxy(harden({}), { - get: (_t, method, _rx) => - harden((...args) => - queueAndRun(() => - controller.queueToVatObject(presence, method, args), - ), - ), - }); - EV.vat = vatName => - new Proxy(harden({}), { - get: (_t, method, _rx) => - harden((...args) => - queueAndRun(() => controller.queueToVatRoot(vatName, method, args)), - ), - }); - // @ts-expect-error xxx - EV.sendOnly = presence => - new Proxy(harden({}), { - get: (_t, method, _rx) => - harden((...args) => - queueAndRun( - () => controller.queueToVatObject(presence, method, args), - true, - ), - ), - }); - // @ts-expect-error xxx - EV.get = presence => - new Proxy(harden({}), { - get: (_t, pathElement, _rx) => - queueAndRun(() => - controller.queueToVatRoot('bootstrap', 'awaitVatObject', [ - presence, - [pathElement], - ]), - ), - }); - return harden({ runThunk, EV }); -}; -export type RunUtils = ReturnType; - /** * @param {string} bundleDir * @param {string} specifier diff --git a/packages/test-support/package.json b/packages/test-support/package.json deleted file mode 100644 index 559d95f44bbe..000000000000 --- a/packages/test-support/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "@agoric/test-support", - "version": "0.1.0", - "description": "Support libraries for testing on chain", - "type": "module", - "main": "./src/index.js", - "exports": { - ".": "./src/index.js" - }, - "repository": "https://github.com/Agoric/agoric-sdk", - "author": "Agoric", - "license": "Apache-2.0", - "scripts": { - "build": "exit 0", - "test": "exit 0", - "test:xs": "exit 0", - "lint-fix": "yarn lint:eslint --fix", - "lint": "run-s --continue-on-error lint:*", - "lint:types": "tsc", - "lint:eslint": "eslint ." - }, - "dependencies": { - "@endo/eventual-send": "^0.17.5", - "@endo/stream": "^0.3.28", - "@agoric/assert": "^0.6.0", - "@agoric/cosmic-swingset": "^0.41.3", - "@agoric/inter-protocol": "^0.16.1", - "@agoric/internal": "^0.3.2", - "@agoric/kmarshal": "^0.1.0", - "@agoric/smart-wallet": "^0.5.3", - "@agoric/swing-store": "^0.9.1", - "@agoric/swingset-vat": "^0.32.2", - "@agoric/time": "^0.3.2", - "@agoric/vats": "^0.15.1", - "ava": "^5.3.0", - "import-meta-resolve": "^2.2.1" - }, - "devDependencies": {}, - "publishConfig": { - "access": "public" - }, - "ava": { - "files": [ - "test/**/test-*.js" - ], - "require": [ - "@endo/init/debug.js" - ], - "timeout": "2m" - } -} diff --git a/packages/test-support/src/index.js b/packages/test-support/src/index.js deleted file mode 100644 index d8febecbbf80..000000000000 --- a/packages/test-support/src/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from './supports.ts'; -export * from './drivers.ts'; diff --git a/packages/test-support/tsconfig.json b/packages/test-support/tsconfig.json deleted file mode 100644 index 0bd02ce55543..000000000000 --- a/packages/test-support/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -// This file can contain .js-specific Typescript compiler config. -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "allowImportingTsExtensions": true, - "allowSyntheticDefaultImports": true, - "checkJs": true, - "maxNodeModuleJsDepth": 2, - }, - "include": [ - "src/**/*.js", - "test/**/*.js" - ] -}