From 081f1d269bc7df07be17d62c545e74e575cd0656 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Fri, 8 Sep 2023 09:51:03 -0700 Subject: [PATCH] test: convert supports to .ts --- .../bench-vaults-performance.js | 2 +- .../bootstrapTests/bench-vaults-stripped.js | 2 +- packages/boot/test/bootstrapTests/drivers.ts | 2 +- .../boot/test/bootstrapTests/liquidation.js | 2 +- .../{supports.js => supports.ts} | 151 ++++++++---------- .../test/bootstrapTests/test-demo-config.ts | 3 +- .../test/bootstrapTests/test-vats-restart.js | 2 +- .../bootstrapTests/test-vaults-integration.js | 2 +- .../bootstrapTests/test-vaults-upgrade.js | 2 +- .../test/bootstrapTests/test-zcf-upgrade.js | 2 +- 10 files changed, 76 insertions(+), 94 deletions(-) rename packages/boot/test/bootstrapTests/{supports.js => supports.ts} (80%) diff --git a/packages/boot/test/bootstrapTests/bench-vaults-performance.js b/packages/boot/test/bootstrapTests/bench-vaults-performance.js index 4e57e10a5be4..a7553154ae93 100644 --- a/packages/boot/test/bootstrapTests/bench-vaults-performance.js +++ b/packages/boot/test/bootstrapTests/bench-vaults-performance.js @@ -12,7 +12,7 @@ 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 } from './supports.js'; +import { makeSwingsetTestKit } from './supports.ts'; import { makeWalletFactoryDriver } from './drivers.ts'; /** diff --git a/packages/boot/test/bootstrapTests/bench-vaults-stripped.js b/packages/boot/test/bootstrapTests/bench-vaults-stripped.js index 09432e636ee5..0fa7cac3e7c2 100644 --- a/packages/boot/test/bootstrapTests/bench-vaults-stripped.js +++ b/packages/boot/test/bootstrapTests/bench-vaults-stripped.js @@ -8,7 +8,7 @@ import { Offers } from '@agoric/inter-protocol/src/clientSupport.js'; import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; -import { makeSwingsetTestKit } from './supports.js'; +import { makeSwingsetTestKit } from './supports.ts'; import { makeWalletFactoryDriver } from './drivers.ts'; // presently all these tests use one collateral manager diff --git a/packages/boot/test/bootstrapTests/drivers.ts b/packages/boot/test/bootstrapTests/drivers.ts index be8ddc9338e5..7abcd957e7c3 100644 --- a/packages/boot/test/bootstrapTests/drivers.ts +++ b/packages/boot/test/bootstrapTests/drivers.ts @@ -22,7 +22,7 @@ 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.js'; +import type { RunUtils, SwingsetTestKit } from './supports.ts'; export const makeWalletFactoryDriver = async ( runUtils: RunUtils, diff --git a/packages/boot/test/bootstrapTests/liquidation.js b/packages/boot/test/bootstrapTests/liquidation.js index 15670928706e..41060d2fc45c 100644 --- a/packages/boot/test/bootstrapTests/liquidation.js +++ b/packages/boot/test/bootstrapTests/liquidation.js @@ -9,7 +9,7 @@ import { makePriceFeedDriver, makeWalletFactoryDriver, } from './drivers.ts'; -import { makeSwingsetTestKit } from './supports.js'; +import { makeSwingsetTestKit } from './supports.ts'; export const scale6 = x => BigInt(Math.round(x * 1_000_000)); diff --git a/packages/boot/test/bootstrapTests/supports.js b/packages/boot/test/bootstrapTests/supports.ts similarity index 80% rename from packages/boot/test/bootstrapTests/supports.js rename to packages/boot/test/bootstrapTests/supports.ts index 2c11710131d9..050b2c91d79f 100644 --- a/packages/boot/test/bootstrapTests/supports.js +++ b/packages/boot/test/bootstrapTests/supports.ts @@ -1,43 +1,42 @@ -// @ts-check +/* eslint-disable jsdoc/require-param-type, jsdoc/require-param, @jessie.js/safe-await-separator */ /* global process */ import { promises as fsAmbientPromises } from 'fs'; import { resolve as importMetaResolve } from 'import-meta-resolve'; import { basename } from 'path'; import { inspect } from 'util'; -import childProcessAmbient from 'child_process'; +import childProcessAmbient, { ChildProcess } from 'child_process'; -import { Fail } from '@agoric/assert'; +import { Fail, NonNullish } from '@agoric/assert'; import { buildSwingset } from '@agoric/cosmic-swingset/src/launch-chain.js'; import { BridgeId, makeTracer, VBankAccount } from '@agoric/internal'; import { unmarshalFromVstorage } from '@agoric/internal/src/marshal.js'; -import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; +import { + FakeStorageKit, + makeFakeStorageKit, +} from '@agoric/internal/src/storage-test-utils.js'; import { initSwingStore } from '@agoric/swing-store'; import { kunser } from '@agoric/swingset-liveslots/test/kmarshal.js'; import { loadSwingsetConfigFile } from '@agoric/swingset-vat'; import { E } from '@endo/eventual-send'; import { makeQueue } from '@endo/stream'; -import { TimeMath } from '@agoric/time'; +import { TimeMath, Timestamp } from '@agoric/time'; import { boardSlottingMarshaller, slotToBoardRemote, } from '@agoric/vats/tools/board-utils.js'; -// to retain for ESlint, used by typedef -E; +import type { ExecutionContext } from 'ava'; +import type { makeBootstrap } from '@agoric/vats/src/core/lib-boot'; +import type { SwingsetController } from '@agoric/swingset-vat/src/controller/controller.js'; const sink = () => {}; const trace = makeTracer('BSTSupport', false); -/** - * @typedef {Awaited< - * ReturnType - * >} BootstrapRootObject - */ +type BootstrapRootObject = Awaited>; -/** @type {{ [P in keyof BootstrapRootObject]: P }} */ -export const bootstrapMethods = { +export const bootstrapMethods: { [P in keyof BootstrapRootObject]: P } = { bootstrap: 'bootstrap', consumeItem: 'consumeItem', produceItem: 'produceItem', @@ -49,50 +48,41 @@ export const bootstrapMethods = { snapshotStore: 'snapshotStore', }; -/** - * @template {PropertyKey} K - * @template V - * @param {K[]} keys - * @param {(key: K, i: number) => V} valueMaker - */ -const keysToObject = (keys, valueMaker) => { +const keysToObject = ( + keys: K[], + valueMaker: (key: K, i: number) => V, +) => { return Object.fromEntries(keys.map((key, i) => [key, valueMaker(key, i)])); }; /** * AVA's default t.deepEqual() is nearly unreadable for sorted arrays of * strings. - * - * @param {{ - * deepEqual: (a: unknown, b: unknown, message?: string) => void; - * }} t - * @param {PropertyKey[]} a - * @param {PropertyKey[]} b - * @param {string} [message] */ -export const keyArrayEqual = (t, a, b, message) => { +export const keyArrayEqual = ( + t: ExecutionContext, + a: PropertyKey[], + b: PropertyKey[], + message: string, +) => { const aobj = keysToObject(a, () => 1); const bobj = keysToObject(b, () => 1); return t.deepEqual(aobj, bobj, message); }; -/** - * @param {import('@agoric/swingset-vat/src/controller/controller').SwingsetController} controller - * @param {(..._: any[]) => any} log - */ -export const makeRunUtils = (controller, log = (..._) => {}) => { +export const makeRunUtils = ( + controller: SwingsetController, + log = (..._) => {}, +) => { let cranksRun = 0; const mutex = makeQueue(); mutex.put(controller.run()); - /** - * @template {() => any} T - * @param {T} thunk - * @returns {Promise>} - */ - const runThunk = async thunk => { + const runThunk = async any>( + thunk: T, + ): Promise> => { try { // this promise for the last lock may fail await mutex.get(); @@ -111,7 +101,7 @@ export const makeRunUtils = (controller, log = (..._) => {}) => { return result; }; - const runMethod = async (method, args = []) => { + const runMethod = async (method: string, args: object[] = []) => { log('runMethod', method, args, 'at', cranksRun); assert(Array.isArray(args)); @@ -151,6 +141,7 @@ export const makeRunUtils = (controller, log = (..._) => {}) => { new Proxy(harden({}), { get: (_t, methodName, _rx) => harden((...args) => { + assert.string(methodName); if (name === 'meta') { return runMethod(methodName, args); } @@ -159,9 +150,9 @@ export const makeRunUtils = (controller, log = (..._) => {}) => { }); EV.rawBoot = new Proxy(harden({}), { get: (_t, methodName, _rx) => + // @ts-expect-error FIXME runMethod takes string but proxy allows symbol harden((...args) => runMethod(methodName, args)), }); - // @ts-expect-error xxx EV.sendOnly = presence => new Proxy( {}, @@ -174,7 +165,6 @@ export const makeRunUtils = (controller, log = (..._) => {}) => { ]), }, ); - // @ts-expect-error xxx EV.get = presence => new Proxy(harden({}), { get: (_t, pathElement, _rx) => @@ -183,7 +173,7 @@ export const makeRunUtils = (controller, log = (..._) => {}) => { return harden({ runThunk, EV }); }; -/** @typedef {ReturnType} RunUtils */ +export type RunUtils = ReturnType; export const getNodeTestVaultsConfig = async ( bundleDir = 'bundles', @@ -192,10 +182,9 @@ export const getNodeTestVaultsConfig = async ( const fullPath = await importMetaResolve(specifier, import.meta.url).then( u => new URL(u).pathname, ); - const config = /** @type {SwingSetConfig & { coreProposals?: any[] }} */ ( - await loadSwingsetConfigFile(fullPath) + const config: SwingSetConfig & { coreProposals?: any[] } = NonNullish( + await loadSwingsetConfigFile(fullPath), ); - assert(config); // speed up (e.g. 80s vs 133s with xs-worker in production config) config.defaultManagerType = 'local'; @@ -219,12 +208,12 @@ export const getNodeTestVaultsConfig = async ( return testConfigPath; }; -/** - * @param {object} powers - * @param {Pick} powers.childProcess - * @param {typeof import('node:fs/promises')} powers.fs - */ -export const makeProposalExtractor = ({ childProcess, fs }) => { +interface Powers { + childProcess: Pick; + fs: typeof import('node:fs/promises'); +} + +export const makeProposalExtractor = ({ childProcess, fs }: Powers) => { const getPkgPath = (pkg, fileName = '') => new URL(`../../../${pkg}/${fileName}`, import.meta.url).pathname; @@ -241,8 +230,7 @@ export const makeProposalExtractor = ({ childProcess, fs }) => { harden(JSON.parse(await fs.readFile(filePath, 'utf8'))); // XXX parses the output to find the files but could write them to a path that can be traversed - /** @param {string} txt */ - const parseProposalParts = txt => { + const parseProposalParts = (txt: string) => { const evals = [ ...txt.matchAll(/swingset-core-eval (?\S+) (?