diff --git a/packages/agoric-cli/src/install.js b/packages/agoric-cli/src/install.js index 920719653bc..78c785cbf21 100644 --- a/packages/agoric-cli/src/install.js +++ b/packages/agoric-cli/src/install.js @@ -9,8 +9,7 @@ const REQUIRED_AGORIC_START_PACKAGES = [ '@agoric/cosmic-swingset', ]; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); export default async function installMain(progname, rawArgs, powers, opts) { const { anylogger, fs, spawn } = powers; diff --git a/packages/boot/test/bootstrapTests/zcf-upgrade.test.ts b/packages/boot/test/bootstrapTests/zcf-upgrade.test.ts index d93b7fe7c17..c2c3e085728 100644 --- a/packages/boot/test/bootstrapTests/zcf-upgrade.test.ts +++ b/packages/boot/test/bootstrapTests/zcf-upgrade.test.ts @@ -11,8 +11,7 @@ import { TestFn } from 'ava'; import { matchAmount, makeSwingsetTestKit } from '../../tools/supports.ts'; import { makeZoeDriver } from '../../tools/drivers.ts'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const ZCF_PROBE_SRC = './zcfProbe.js'; diff --git a/packages/boot/tools/supports.ts b/packages/boot/tools/supports.ts index 3f4d2015348..59ac205cc6b 100644 --- a/packages/boot/tools/supports.ts +++ b/packages/boot/tools/supports.ts @@ -57,15 +57,10 @@ export const keyArrayEqual = ( return t.deepEqual(aobj, bobj, message); }; -/** - * @param {string} bundleDir - * @param {string} specifier - * @param {ManagerType} [defaultManagerType] - */ export const getNodeTestVaultsConfig = async ( bundleDir = 'bundles', specifier = '@agoric/vm-config/decentral-itest-vaults-config.json', - defaultManagerType = 'local', + defaultManagerType = 'local' as ManagerType, ) => { const fullPath = await importMetaResolve(specifier, import.meta.url).then( u => new URL(u).pathname, @@ -81,7 +76,7 @@ export const getNodeTestVaultsConfig = async ( // - exhibits inconsistent GC behavior from run to run // 'xs-worker' // - timing results more accurately reflect production - config.defaultManagerType = defaultManagerType as ManagerType; + config.defaultManagerType = defaultManagerType; // speed up build (60s down to 10s in testing) config.bundleCachePath = bundleDir; await fsAmbientPromises.mkdir(bundleDir, { recursive: true }); diff --git a/packages/governance/test/swingsetTests/committeeBinary/committee.test.js b/packages/governance/test/swingsetTests/committeeBinary/committee.test.js index 1cc81e85de1..90b0302fbbd 100644 --- a/packages/governance/test/swingsetTests/committeeBinary/committee.test.js +++ b/packages/governance/test/swingsetTests/committeeBinary/committee.test.js @@ -8,8 +8,7 @@ import path from 'path'; const CONTRACT_FILES = ['committee', 'binaryVoteCounter']; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); test.before(async t => { const start = Date.now(); diff --git a/packages/governance/test/swingsetTests/contractGovernor/governor.test.js b/packages/governance/test/swingsetTests/contractGovernor/governor.test.js index d1bb1317bc5..de24bb0268b 100644 --- a/packages/governance/test/swingsetTests/contractGovernor/governor.test.js +++ b/packages/governance/test/swingsetTests/contractGovernor/governor.test.js @@ -15,8 +15,7 @@ const CONTRACT_FILES = [ }, ]; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); test.before(async t => { const start = Date.now(); diff --git a/packages/governance/test/unitTests/committee.test.js b/packages/governance/test/unitTests/committee.test.js index 5672490b267..6228d9267f5 100644 --- a/packages/governance/test/unitTests/committee.test.js +++ b/packages/governance/test/unitTests/committee.test.js @@ -25,8 +25,7 @@ import { remoteNullMarshaller } from '../swingsetTests/utils.js'; * @import {SimpleIssue} from '../../src/types.js'; */ -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const electorateRoot = `${dirname}/../../src/committee.js`; const counterRoot = `${dirname}/../../src/binaryVoteCounter.js`; diff --git a/packages/inter-protocol/test/auction/auctionContract.test.js b/packages/inter-protocol/test/auction/auctionContract.test.js index 912f803a132..cf3720e6bca 100644 --- a/packages/inter-protocol/test/auction/auctionContract.test.js +++ b/packages/inter-protocol/test/auction/auctionContract.test.js @@ -38,10 +38,12 @@ import { setUpInstallations } from './tools.js'; /** @type {import('ava').TestFn>>} */ const test = anyTest; +/** @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; */ + /** * @typedef {Record & { - * bid: IssuerKit & import('../supports.js').AmountUtils; - * collateral: IssuerKit & import('../supports.js').AmountUtils; + * bid: IssuerKit & AmountUtils; + * collateral: IssuerKit & AmountUtils; * zoe: ZoeService; * }} Context */ diff --git a/packages/inter-protocol/test/supports.js b/packages/inter-protocol/test/supports.js index 7c2f4e6197f..e39acbd475a 100644 --- a/packages/inter-protocol/test/supports.js +++ b/packages/inter-protocol/test/supports.js @@ -1,24 +1,22 @@ -import { AmountMath } from '@agoric/ertp'; import binaryVoteCounterBundle from '@agoric/governance/bundles/bundle-binaryVoteCounter.js'; import committeeBundle from '@agoric/governance/bundles/bundle-committee.js'; import contractGovernorBundle from '@agoric/governance/bundles/bundle-contractGovernor.js'; import puppetContractGovernorBundle from '@agoric/governance/bundles/bundle-puppetContractGovernor.js'; -import * as utils from '@agoric/vats/src/core/utils.js'; -import { makePromiseSpace, makeAgoricNamesAccess } from '@agoric/vats'; -import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js'; +import { makeTracer } from '@agoric/internal'; import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js'; -import { setUpZoeForTest as generalSetUpZoeForTest } from '@agoric/zoe/tools/setup-zoe.js'; -import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js'; import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; -import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; -import { E } from '@endo/far'; -import { makeTracer } from '@agoric/internal'; import { makeNotifierFromAsyncIterable, observeIteration, subscribeEach, } from '@agoric/notifier'; +import { makeAgoricNamesAccess, makePromiseSpace } from '@agoric/vats'; import { produceDiagnostics } from '@agoric/vats/src/core/basic-behaviors.js'; +import * as utils from '@agoric/vats/src/core/utils.js'; +import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js'; +import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; +import { setUpZoeForTest as generalSetUpZoeForTest } from '@agoric/zoe/tools/setup-zoe.js'; +import { E } from '@endo/far'; /** @import {EconomyBootstrapPowers as Space} from '../src/proposals/econ-behaviors.js' */ @@ -152,25 +150,7 @@ export const produceInstallations = (space, installations) => { export const scale6 = x => BigInt(Math.round(x * 1_000_000)); -/** @param {Pick, 'brand' | 'issuer' | 'mint'>} kit */ -export const withAmountUtils = kit => { - const decimalPlaces = kit.issuer.getDisplayInfo?.()?.decimalPlaces ?? 6; - return { - ...kit, - /** @param {NatValue} v */ - make: v => AmountMath.make(kit.brand, v), - makeEmpty: () => AmountMath.makeEmpty(kit.brand), - /** - * @param {NatValue} n - * @param {NatValue} [d] - */ - makeRatio: (n, d) => makeRatio(n, kit.brand, d), - /** @param {number} n */ - units: n => - AmountMath.make(kit.brand, BigInt(Math.round(n * 10 ** decimalPlaces))), - }; -}; -/** @typedef {ReturnType} AmountUtils */ +export { withAmountUtils } from '@agoric/zoe/tools/test-utils.js'; /** @param {ERef | StoredSubscriber>} subscription */ export const subscriptionKey = subscription => { diff --git a/packages/inter-protocol/test/vaultFactory/driver.js b/packages/inter-protocol/test/vaultFactory/driver.js index f10a0afa28a..bfb55c502c0 100644 --- a/packages/inter-protocol/test/vaultFactory/driver.js +++ b/packages/inter-protocol/test/vaultFactory/driver.js @@ -33,7 +33,10 @@ import { withAmountUtils, } from '../supports.js'; -/** @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js' */ +/** + * @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js'; + * @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; + */ const trace = makeTracer('VFDriver'); @@ -60,7 +63,7 @@ const contractRoots = { /** * dL: 1M, lM: 105%, lP: 10%, iR: 100, lF: 500, lP: 0% * - * @param {import('../supports.js').AmountUtils} debt + * @param {AmountUtils} debt */ const defaultParamValues = debt => harden({ @@ -78,7 +81,7 @@ const defaultParamValues = debt => /** * @typedef {{ - * aeth: IssuerKit & import('../supports.js').AmountUtils; + * aeth: IssuerKit & AmountUtils; * aethInitialLiquidity: Amount<'nat'>; * consume: import('../../src/proposals/econ-behaviors.js').EconomyBootstrapPowers['consume']; * puppetGovernors: { @@ -95,7 +98,7 @@ const defaultParamValues = debt => * minInitialDebt: bigint; * reserveCreatorFacet: ERef; * rates: any; - * run: IssuerKit & import('../supports.js').AmountUtils; + * run: IssuerKit & AmountUtils; * stableInitialLiquidity: Amount<'nat'>; * timer: ReturnType; * zoe: ZoeService; @@ -370,7 +373,7 @@ export const makeManagerDriver = async ( notification: () => notification, /** * @param {bigint} collValue - * @param {import('../supports.js').AmountUtils} collUtils + * @param {AmountUtils} collUtils * @param {bigint} [mintedValue] */ giveCollateral: async (collValue, collUtils, mintedValue = 0n) => { @@ -391,7 +394,7 @@ export const makeManagerDriver = async ( }, /** * @param {bigint} mintedValue - * @param {import('../supports.js').AmountUtils} collUtils + * @param {AmountUtils} collUtils * @param {bigint} [collValue] */ giveMinted: async (mintedValue, collUtils, collValue = 0n) => { diff --git a/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js b/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js index 53f04b6bbfc..b54697e6d40 100644 --- a/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js +++ b/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js @@ -39,12 +39,15 @@ import { import '../../src/vaultFactory/types-ambient.js'; import { defaultParamValues } from './vaultFactoryUtils.js'; -/** @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js' */ +/** + * @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js'; + * @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; + */ /** * @typedef {Record & { - * aeth: IssuerKit & import('../supports.js').AmountUtils; - * run: IssuerKit & import('../supports.js').AmountUtils; + * aeth: IssuerKit & AmountUtils; + * run: IssuerKit & AmountUtils; * bundleCache: Awaited>; * rates: VaultManagerParamValues; * interestTiming: InterestTiming; diff --git a/packages/inter-protocol/test/vaultFactory/vaultFactory.test.js b/packages/inter-protocol/test/vaultFactory/vaultFactory.test.js index 6852667f737..7c6362cb14a 100644 --- a/packages/inter-protocol/test/vaultFactory/vaultFactory.test.js +++ b/packages/inter-protocol/test/vaultFactory/vaultFactory.test.js @@ -47,12 +47,13 @@ import { /** * @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; * @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js' + * @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; */ /** * @typedef {Record & { - * aeth: IssuerKit & import('../supports.js').AmountUtils; - * run: IssuerKit & import('../supports.js').AmountUtils; + * aeth: IssuerKit & AmountUtils; + * run: IssuerKit & AmountUtils; * bundleCache: Awaited>; * rates: VaultManagerParamValues; * interestTiming: InterestTiming; diff --git a/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js b/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js index 7cc4157721d..e8da6989960 100644 --- a/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js +++ b/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js @@ -24,10 +24,12 @@ import { startEconomicCommittee } from '../../src/proposals/startEconCommittee.j export const BASIS_POINTS = 10000n; +/** @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; */ + /** * @typedef {Record & { - * aeth: IssuerKit & import('../supports.js').AmountUtils; - * run: IssuerKit & import('../supports.js').AmountUtils; + * aeth: IssuerKit & AmountUtils; + * run: IssuerKit & AmountUtils; * bundleCache: Awaited< * ReturnType< * typeof import('@agoric/swingset-vat/tools/bundleTool.js').unsafeMakeBundleCache diff --git a/packages/inter-protocol/test/vaultFactory/vaultLiquidation.test.js b/packages/inter-protocol/test/vaultFactory/vaultLiquidation.test.js index 45cf37a1bf8..a762ad9f86c 100644 --- a/packages/inter-protocol/test/vaultFactory/vaultLiquidation.test.js +++ b/packages/inter-protocol/test/vaultFactory/vaultLiquidation.test.js @@ -44,12 +44,15 @@ import { setupElectorateReserveAndAuction, } from './vaultFactoryUtils.js'; -/** @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js' */ +/** + * @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js'; + * @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; + */ /** * @typedef {Record & { - * aeth: IssuerKit & import('../supports.js').AmountUtils; - * run: IssuerKit & import('../supports.js').AmountUtils; + * aeth: IssuerKit & AmountUtils; + * run: IssuerKit & AmountUtils; * bundleCache: Awaited>; * rates: VaultManagerParamValues; * interestTiming: InterestTiming; diff --git a/packages/orchestration/src/cosmos-api.ts b/packages/orchestration/src/cosmos-api.ts index b158f41db4b..ff0e3e0bdbf 100644 --- a/packages/orchestration/src/cosmos-api.ts +++ b/packages/orchestration/src/cosmos-api.ts @@ -133,7 +133,7 @@ export interface StakingAccountActions { * Undelegate multiple delegations (concurrently). To delegate independently, pass an array with one item. * Resolves when the undelegation is complete and the tokens are no longer bonded. Note it may take weeks. * The unbonding time is padded by 10 minutes to account for clock skew. - * @param {Delegation[]} delegations - the delegation to undelegate + * @param delegations - the delegation to undelegate */ undelegate: (delegations: Delegation[]) => Promise; @@ -168,8 +168,8 @@ export interface IcaAccount { executeTx: (msgs: Proto3JSONMsg[]) => Promise; /** * Submit a transaction on behalf of the remote account for execution on the remote chain. - * @param {AnyJson[]} msgs - records for the transaction - * @param {Partial>} [opts] - optional parameters for the Tx, like `timeoutHeight` and `memo` + * @param msgs - records for the transaction + * @param [opts] - optional parameters for the Tx, like `timeoutHeight` and `memo` * @returns acknowledgement string */ executeEncodedTx: ( diff --git a/packages/orchestration/test/staking-ops.test.js b/packages/orchestration/test/staking-ops.test.ts similarity index 85% rename from packages/orchestration/test/staking-ops.test.js rename to packages/orchestration/test/staking-ops.test.ts index cfaab0d36c6..52cd9564e2e 100644 --- a/packages/orchestration/test/staking-ops.test.js +++ b/packages/orchestration/test/staking-ops.test.ts @@ -8,21 +8,21 @@ import { MsgDelegateResponse, MsgUndelegateResponse, } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; -import { makeScalarBigMapStore } from '@agoric/vat-data'; +import { makeScalarBigMapStore, type Baggage } from '@agoric/vat-data'; import { decodeBase64 } from '@endo/base64'; import { E, Far } from '@endo/far'; import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; +import type { Coin } from '@agoric/cosmic-proto/cosmos/base/v1beta1/coin.js'; +import type { TimestampRecord, TimestampValue } from '@agoric/time'; +import type { AnyJson } from '@agoric/cosmic-proto'; import { prepareStakingAccountKit, encodeTxResponse, trivialDelegateResponse, } from '../src/exos/stakingAccountKit.js'; -/** - * @import {IcaAccount, ChainAddress, ICQConnection} from '../src/types.js'; - * @import { Coin } from '@agoric/cosmic-proto/cosmos/base/v1beta1/coin.js'; - */ +import type { IcaAccount, ChainAddress, ICQConnection } from '../src/types.js'; const { Fail } = assert; @@ -33,7 +33,7 @@ test('MsgDelegateResponse trivial response', t => { ); }); -const configStaking = /** @type {const} */ ({ +const configStaking = { acct1: { address: 'agoric1spy36ltduehs5dmszfrp792f0k2emcntrql3nx', }, @@ -47,9 +47,9 @@ const configStaking = /** @type {const} */ ({ }, startTime: '2024-06-01T00:00Z', completionTime: '2024-06-22T00:00Z', -}); +} as const; -const configRedelegate = /** @type {const} */ ({ +const configRedelegate = { validator: { address: 'agoric1valoper444', addressEncoding: 'bech32', @@ -58,30 +58,26 @@ const configRedelegate = /** @type {const} */ ({ delegations: { agoric1valoper234: { denom: 'uatom', amount: '50' }, }, -}); +} as const; const TICK = 5n * 60n; const DAY = (60n * 60n * 24n) / TICK; const DAYf = Number(DAY); const time = { - /** - * @param {string} dateString in YYYY-MM-DDTHH:mm:ss.sssZ format - * @returns {import('@agoric/time').Timestamp} - */ - parse: dateString => BigInt(Date.parse(dateString) / 1000), - - /** @param {import('@agoric/time').TimestampRecord} ts */ - format: ts => new Date(Number(ts.absValue) * 1000).toISOString(), + parse: (dateString: string) => + BigInt(Date.parse(dateString) / 1000) as TimestampValue, + + format: (ts: TimestampRecord) => + new Date(Number(ts.absValue) * 1000).toISOString(), }; const makeScenario = () => { - /** - * @param {string} [addr] - * @param {Record} [delegations] - */ - const mockAccount = (addr = 'agoric1234', delegations = {}) => { - const calls = []; + const mockAccount = ( + addr = 'agoric1234', + delegations = {} as Record, + ) => { + const calls = [] as Array<{ msgs: AnyJson[] }>; const simulate = { '/cosmos.staking.v1beta1.MsgDelegate': _m => { @@ -105,8 +101,9 @@ const makeScenario = () => { denom, amount: `${Number(amount) / 100}`, })); - /** @type {MsgWithdrawDelegatorRewardResponse} */ - const response = { amount: rewards }; + const response = { + amount: rewards, + } as MsgWithdrawDelegatorRewardResponse; return encodeTxResponse( response, @@ -123,15 +120,13 @@ const makeScenario = () => { }, }; - /** @type {ChainAddress} */ - const chainAddress = harden({ + const chainAddress: ChainAddress = harden({ address: addr, addressEncoding: 'bech32', chainId: 'FIXME', }); - /** @type {IcaAccount} */ - const account = Far('MockAccount', { + const account: IcaAccount = Far('MockAccount', { getAddress: () => chainAddress, executeEncodedTx: async msgs => { assert.equal(msgs.length, 1); @@ -156,13 +151,10 @@ const makeScenario = () => { const mockZCF = () => { const toHandler = new Map(); - /** @type {ZCF} */ - const zcf = harden({ + const zcf: ZCF = harden({ // @ts-expect-error mock makeInvitation: async (handler, _desc, _c, _patt) => { - /** @type {Invitation} */ - // @ts-expect-error mock - const invitation = Far('Invitation', {}); + const invitation = Far('Invitation', {}) as unknown as Invitation; toHandler.set(invitation, handler); return invitation; }, @@ -183,25 +175,18 @@ const makeScenario = () => { return { zcf, zoe }; }; - const makeRecorderKit = () => { - /** @type {any} */ - const kit = harden({}); - return kit; - }; - const baggage = makeScalarBigMapStore('b1'); + const makeRecorderKit = () => harden({}) as any; + + const baggage = makeScalarBigMapStore('b1') as Baggage; const { delegations, startTime } = configStaking; // TODO: when we write to chainStorage, test it. // const { rootNode } = makeFakeStorageKit('mockChainStorageRoot'); - /** @type {StorageNode} */ - // @ts-expect-error mock - const storageNode = Far('StorageNode', {}); + const storageNode = Far('StorageNode', {}) as unknown as StorageNode; - /** @type {ICQConnection} */ - // @ts-expect-error mock - const icqConnection = Far('ICQConnection', {}); + const icqConnection = Far('ICQConnection', {}) as ICQConnection; const timer = buildManualTimer(undefined, time.parse(startTime), { timeStep: TICK, @@ -245,8 +230,7 @@ test(`delegate; redelegate using invitationMakers`, async t => { const s = makeScenario(); const { account, calls, timer } = s; const { baggage, makeRecorderKit, storageNode, zcf, zoe, icqConnection } = s; - /** @type {Brand<'nat'>} */ - const aBrand = Far('Token'); + const aBrand = Far('Token') as Brand<'nat'>; const makeAccountKit = prepareStakingAccountKit( baggage, makeRecorderKit, @@ -362,8 +346,7 @@ test(`undelegate waits for unbonding period`, async t => { const { validator, delegations } = configStaking; const value = BigInt(Object.values(delegations)[0].amount); - /** @type {Amount<'nat'>} */ - const anAmount = { brand: Far('Token'), value }; + const anAmount = { brand: Far('Token'), value } as Amount<'nat'>; const delegation = { delegatorAddress: account.getAddress().address, shares: `${anAmount.value}`, diff --git a/packages/orchestration/test/tx-encoding.test.js b/packages/orchestration/test/tx-encoding.test.ts similarity index 91% rename from packages/orchestration/test/tx-encoding.test.js rename to packages/orchestration/test/tx-encoding.test.ts index 387e1eb981a..e26ee203b4f 100644 --- a/packages/orchestration/test/tx-encoding.test.js +++ b/packages/orchestration/test/tx-encoding.test.ts @@ -45,10 +45,8 @@ test('DelegateResponse decoding', t => { t.like(any, { $typeUrl: '/google.protobuf.Any', typeUrl: '' }); t.true(any.value instanceof Uint8Array); - /** @import {MsgDelegateResponseProtoMsg} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; */ - /** @type {MsgDelegateResponseProtoMsg} */ // @ts-expect-error we can tell this is the type from tye typeUrl - const protoMsg = Any.decode(any.value); + const protoMsg: MsgDelegateResponseProtoMsg = Any.decode(any.value); t.like(protoMsg, { $typeUrl: '/google.protobuf.Any', typeUrl: '/cosmos.staking.v1beta1.MsgDelegateResponse', @@ -72,8 +70,9 @@ test('tryDecodeResponse from withdraw', t => { test('MsgWithdrawDelegatorRewardResponse encoding', t => { const { delegations } = scenario1; - /** @type {MsgWithdrawDelegatorRewardResponse} */ - const response = { amount: Object.values(delegations) }; + const response: MsgWithdrawDelegatorRewardResponse = { + amount: Object.values(delegations), + }; const protoMsg = MsgWithdrawDelegatorRewardResponse.toProtoMsg(response); const typeUrl = diff --git a/packages/orchestration/test/utils/address.test.js b/packages/orchestration/test/utils/address.test.ts similarity index 100% rename from packages/orchestration/test/utils/address.test.js rename to packages/orchestration/test/utils/address.test.ts diff --git a/packages/orchestration/test/utils/packet.test.js b/packages/orchestration/test/utils/packet.test.ts similarity index 91% rename from packages/orchestration/test/utils/packet.test.js rename to packages/orchestration/test/utils/packet.test.ts index f5202de6c39..6602f721986 100644 --- a/packages/orchestration/test/utils/packet.test.js +++ b/packages/orchestration/test/utils/packet.test.ts @@ -6,6 +6,7 @@ import { } from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js'; import { RequestQuery } from '@agoric/cosmic-proto/tendermint/abci/types.js'; import { decodeBase64 } from '@endo/base64'; +import type { RequestQueryJson } from '@agoric/cosmic-proto'; import { makeTxPacket, parseTxPacket, @@ -13,8 +14,6 @@ import { makeQueryPacket, } from '../../src/utils/packet.js'; -/** @import { RequestQueryJson } from '@agoric/cosmic-proto'; */ - test('makeTxPacket', t => { const mockMsg = { typeUrl: '/foo.bar.v1', @@ -94,19 +93,17 @@ test('parseTxPacket', t => { }); test('makeQueryPacket', t => { - const mockQuery = /** @type {RequestQueryJson} */ ( - RequestQuery.toJSON( - RequestQuery.fromPartial({ - path: '/cosmos.bank.v1beta1.Query/Balance', - data: QueryBalanceRequest.encode( - QueryBalanceRequest.fromPartial({ - address: 'cosmos1test', - denom: 'uatom', - }), - ).finish(), - }), - ) - ); + const mockQuery = RequestQuery.toJSON( + RequestQuery.fromPartial({ + path: '/cosmos.bank.v1beta1.Query/Balance', + data: QueryBalanceRequest.encode( + QueryBalanceRequest.fromPartial({ + address: 'cosmos1test', + denom: 'uatom', + }), + ).finish(), + }), + ) as RequestQueryJson; t.is( makeQueryPacket([mockQuery]), '{"data":"CjoKFAoLY29zbW9zMXRlc3QSBXVhdG9tEiIvY29zbW9zLmJhbmsudjFiZXRhMS5RdWVyeS9CYWxhbmNl","memo":""}', diff --git a/packages/pegasus/test/peg.test.js b/packages/pegasus/test/peg.test.js index d3633104b40..6ea74c5e7f4 100644 --- a/packages/pegasus/test/peg.test.js +++ b/packages/pegasus/test/peg.test.js @@ -19,8 +19,7 @@ import { makePromiseKit } from '@endo/promise-kit'; import { makeScalarMapStore } from '@agoric/vat-data'; import { makeDurableZone } from '@agoric/zone/durable.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractPath = `${dirname}/../src/contract.js`; diff --git a/packages/solo/src/init-basedir.js b/packages/solo/src/init-basedir.js index 384d81c3b84..2064447501f 100644 --- a/packages/solo/src/init-basedir.js +++ b/packages/solo/src/init-basedir.js @@ -12,8 +12,7 @@ const console = anylogger('ag-solo:init'); const DEFAULT_WALLET = '@agoric/wallet'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); /** * @param {string} basedir diff --git a/packages/solo/src/pipe.js b/packages/solo/src/pipe.js index ade11381e69..782c323c0fa 100644 --- a/packages/solo/src/pipe.js +++ b/packages/solo/src/pipe.js @@ -7,8 +7,7 @@ import { parse, stringify } from '@endo/marshal'; import { makeShutdown } from '@agoric/internal/src/node/shutdown.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); export const connectToPipe = async ({ method, args, deliverInboundToMbx }) => { // console.log('connectToPipe', method, args); diff --git a/packages/spawner/test/swingsetTests/contractHost/contractHost.test.js b/packages/spawner/test/swingsetTests/contractHost/contractHost.test.js index 688c3d7b2ae..802e92e1f0e 100644 --- a/packages/spawner/test/swingsetTests/contractHost/contractHost.test.js +++ b/packages/spawner/test/swingsetTests/contractHost/contractHost.test.js @@ -8,8 +8,7 @@ import { loadBasedir, } from '@agoric/swingset-vat'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); test.before(async t => { const kernelBundles = await buildKernelBundles(); diff --git a/packages/telemetry/src/slog-sender-pipe.js b/packages/telemetry/src/slog-sender-pipe.js index f17b8c859b9..1ff69f76273 100644 --- a/packages/telemetry/src/slog-sender-pipe.js +++ b/packages/telemetry/src/slog-sender-pipe.js @@ -6,8 +6,7 @@ import { makeQueue } from '@endo/stream'; import { makeShutdown } from '@agoric/internal/src/node/shutdown.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const logger = anylogger('slog-sender-pipe'); diff --git a/packages/wallet/api/deploy.js b/packages/wallet/api/deploy.js index e6991aeecbf..0fd036d40ef 100644 --- a/packages/wallet/api/deploy.js +++ b/packages/wallet/api/deploy.js @@ -6,8 +6,7 @@ import { E } from '@endo/eventual-send'; import { Fail } from '@agoric/assert'; import path from 'path'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); export default async function deployWallet( homePromise, diff --git a/packages/zoe/test/swingsetTests/brokenContracts/crashingContract.test.js b/packages/zoe/test/swingsetTests/brokenContracts/crashingContract.test.js index de6858b7308..eb42b4b63ec 100644 --- a/packages/zoe/test/swingsetTests/brokenContracts/crashingContract.test.js +++ b/packages/zoe/test/swingsetTests/brokenContracts/crashingContract.test.js @@ -7,8 +7,7 @@ import { loadBasedir, buildVatController } from '@agoric/swingset-vat'; import bundleSource from '@endo/bundle-source'; import zcfBundle from '../../../bundles/bundle-contractFacet.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const CONTRACT_FILES = ['crashingAutoRefund']; const contractBundles = {}; diff --git a/packages/zoe/test/swingsetTests/makeKind/makeKind.test.js b/packages/zoe/test/swingsetTests/makeKind/makeKind.test.js index 9de18e88c8c..d1331a2c7a8 100644 --- a/packages/zoe/test/swingsetTests/makeKind/makeKind.test.js +++ b/packages/zoe/test/swingsetTests/makeKind/makeKind.test.js @@ -6,8 +6,7 @@ import zcfBundle from '../../../bundles/bundle-contractFacet.js'; const CONTRACT_FILES = ['minimalMakeKindContract']; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); /** @type {import('ava').TestFn<{ data: { kernelBundles: any, config: any } }>} */ const test = anyTest; diff --git a/packages/zoe/test/swingsetTests/offerArgs/offerArgs.test.js b/packages/zoe/test/swingsetTests/offerArgs/offerArgs.test.js index 12445d8d181..94a1f9f1222 100644 --- a/packages/zoe/test/swingsetTests/offerArgs/offerArgs.test.js +++ b/packages/zoe/test/swingsetTests/offerArgs/offerArgs.test.js @@ -6,8 +6,7 @@ import zcfBundle from '../../../bundles/bundle-contractFacet.js'; const CONTRACT_FILES = ['offerArgsUsageContract']; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); /** @type {import('ava').TestFn<{ data: { kernelBundles: any, config: any } }>} */ const test = anyTest; diff --git a/packages/zoe/test/swingsetTests/privateArgs/privateArgs.test.js b/packages/zoe/test/swingsetTests/privateArgs/privateArgs.test.js index d82ce759b25..6e66d4b78ef 100644 --- a/packages/zoe/test/swingsetTests/privateArgs/privateArgs.test.js +++ b/packages/zoe/test/swingsetTests/privateArgs/privateArgs.test.js @@ -6,8 +6,7 @@ import zcfBundle from '../../../bundles/bundle-contractFacet.js'; const CONTRACT_FILES = ['privateArgsUsageContract']; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); /** @type {import('ava').TestFn<{ data: { kernelBundles: any, config: any } }>} */ const test = anyTest; diff --git a/packages/zoe/test/swingsetTests/runMint/runMint.test.js b/packages/zoe/test/swingsetTests/runMint/runMint.test.js index c870fe5f195..2907f973564 100644 --- a/packages/zoe/test/swingsetTests/runMint/runMint.test.js +++ b/packages/zoe/test/swingsetTests/runMint/runMint.test.js @@ -9,8 +9,7 @@ import zcfBundle from '../../../bundles/bundle-contractFacet.js'; // feeBrand is made const CONTRACT_FILES = ['runMintContract', 'offerArgsUsageContract']; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); /** @type {import('ava').TestFn<{ data: { kernelBundles: any, config: any } }>} */ const test = anyTest; diff --git a/packages/zoe/test/swingsetTests/zoe/zoe.test.js b/packages/zoe/test/swingsetTests/zoe/zoe.test.js index dfc6161383c..20ca2522fef 100644 --- a/packages/zoe/test/swingsetTests/zoe/zoe.test.js +++ b/packages/zoe/test/swingsetTests/zoe/zoe.test.js @@ -5,8 +5,7 @@ import { buildVatController, buildKernelBundles } from '@agoric/swingset-vat'; import bundleSource from '@endo/bundle-source'; import zcfBundle from '../../../bundles/bundle-contractFacet.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const CONTRACT_FILES = [ 'automaticRefund', diff --git a/packages/zoe/test/unitTests/blockedOffers.test.js b/packages/zoe/test/unitTests/blockedOffers.test.js index 21836df7154..d59cea38d6f 100644 --- a/packages/zoe/test/unitTests/blockedOffers.test.js +++ b/packages/zoe/test/unitTests/blockedOffers.test.js @@ -15,8 +15,7 @@ import { import { assertPayoutAmount } from '../zoeTestHelpers.js'; import { makeOffer } from './makeOffer.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/zcf/zcfTesterContract.js`; diff --git a/packages/zoe/test/unitTests/contractSupport/depositTo.test.js b/packages/zoe/test/unitTests/contractSupport/depositTo.test.js index ec80e0df791..c9f31c365be 100644 --- a/packages/zoe/test/unitTests/contractSupport/depositTo.test.js +++ b/packages/zoe/test/unitTests/contractSupport/depositTo.test.js @@ -11,8 +11,7 @@ import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; import { depositToSeat } from '../../../src/contractSupport/zoeHelpers.js'; import { makeOffer } from '../makeOffer.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/../zcf/zcfTesterContract.js`; diff --git a/packages/zoe/test/unitTests/contractSupport/offerTo.test.js b/packages/zoe/test/unitTests/contractSupport/offerTo.test.js index 6a8f7b8d4ec..020eb923d23 100644 --- a/packages/zoe/test/unitTests/contractSupport/offerTo.test.js +++ b/packages/zoe/test/unitTests/contractSupport/offerTo.test.js @@ -11,8 +11,7 @@ import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; import { offerTo, swapExact } from '../../../src/contractSupport/zoeHelpers.js'; import { makeOffer } from '../makeOffer.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/../zcf/zcfTesterContract.js`; diff --git a/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js b/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js index 6f8f66e2207..d5f359c8324 100644 --- a/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js +++ b/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js @@ -15,8 +15,7 @@ import { import { assertPayoutAmount } from '../../zoeTestHelpers.js'; import { makeOffer } from '../makeOffer.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/../zcf/zcfTesterContract.js`; diff --git a/packages/zoe/test/unitTests/contracts/atomicSwap.test.js b/packages/zoe/test/unitTests/contracts/atomicSwap.test.js index dd72fb4750c..0d05695ddb0 100644 --- a/packages/zoe/test/unitTests/contracts/atomicSwap.test.js +++ b/packages/zoe/test/unitTests/contracts/atomicSwap.test.js @@ -12,8 +12,7 @@ import { setup } from '../setupBasicMints.js'; import { setupNonFungible } from '../setupNonFungibleMints.js'; import { assertAmountsEqual } from '../../zoeTestHelpers.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const atomicSwapRoot = `${dirname}/../../../src/contracts/atomicSwap.js`; diff --git a/packages/zoe/test/unitTests/contracts/auction.test.js b/packages/zoe/test/unitTests/contracts/auction.test.js index 4419cc8c899..ea2cbdfca57 100644 --- a/packages/zoe/test/unitTests/contracts/auction.test.js +++ b/packages/zoe/test/unitTests/contracts/auction.test.js @@ -12,8 +12,7 @@ import buildManualTimer from '../../../tools/manualTimer.js'; import { setup } from '../setupBasicMints.js'; import { setupMixed } from '../setupMixedMints.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const auctionRoot = `${dirname}/../../../src/contracts/auction/index.js`; diff --git a/packages/zoe/test/unitTests/contracts/automaticRefund.test.js b/packages/zoe/test/unitTests/contracts/automaticRefund.test.js index 317e668a760..73b3ad18813 100644 --- a/packages/zoe/test/unitTests/contracts/automaticRefund.test.js +++ b/packages/zoe/test/unitTests/contracts/automaticRefund.test.js @@ -9,8 +9,7 @@ import { claim, splitMany } from '@agoric/ertp/src/legacy-payment-helpers.js'; import { setup } from '../setupBasicMints.js'; import { setupNonFungible } from '../setupNonFungibleMints.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const automaticRefundRoot = `${dirname}/../../../src/contracts/automaticRefund.js`; diff --git a/packages/zoe/test/unitTests/contracts/autoswap.test.js b/packages/zoe/test/unitTests/contracts/autoswap.test.js index eec9d18d3a4..8cb619ffe1f 100644 --- a/packages/zoe/test/unitTests/contracts/autoswap.test.js +++ b/packages/zoe/test/unitTests/contracts/autoswap.test.js @@ -17,8 +17,7 @@ import { setup } from '../setupBasicMints.js'; import { installationPFromSource } from '../installFromSource.js'; import { assertOfferResult, assertPayoutAmount } from '../../zoeTestHelpers.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const autoswap = `${dirname}/../../../src/contracts/autoswap.js`; diff --git a/packages/zoe/test/unitTests/contracts/barter.test.js b/packages/zoe/test/unitTests/contracts/barter.test.js index 99df60cef5a..1bc33791679 100644 --- a/packages/zoe/test/unitTests/contracts/barter.test.js +++ b/packages/zoe/test/unitTests/contracts/barter.test.js @@ -10,8 +10,7 @@ import { setup } from '../setupBasicMints.js'; import { installationPFromSource } from '../installFromSource.js'; import { assertPayoutAmount, assertOfferResult } from '../../zoeTestHelpers.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const barter = `${dirname}/../../../src/contracts/barterExchange.js`; diff --git a/packages/zoe/test/unitTests/contracts/brokenContract.test.js b/packages/zoe/test/unitTests/contracts/brokenContract.test.js index 386746c701c..746daf4cfd4 100644 --- a/packages/zoe/test/unitTests/contracts/brokenContract.test.js +++ b/packages/zoe/test/unitTests/contracts/brokenContract.test.js @@ -9,8 +9,7 @@ import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { setup } from '../setupBasicMints.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const automaticRefundRoot = `${dirname}/brokenAutoRefund.js`; diff --git a/packages/zoe/test/unitTests/contracts/callSpread.test.js b/packages/zoe/test/unitTests/contracts/callSpread.test.js index 5734238681e..b9ffec421fb 100644 --- a/packages/zoe/test/unitTests/contracts/callSpread.test.js +++ b/packages/zoe/test/unitTests/contracts/callSpread.test.js @@ -14,8 +14,7 @@ import { } from '../../zoeTestHelpers.js'; import { makeFakePriceAuthority } from '../../../tools/fakePriceAuthority.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const fundedCallSpread = `${dirname}/../../../src/contracts/callSpread/fundedCallSpread.js`; const pricedCallSpread = `${dirname}/../../../src/contracts/callSpread/pricedCallSpread.js`; diff --git a/packages/zoe/test/unitTests/contracts/coveredCall-want-pattern.test.js b/packages/zoe/test/unitTests/contracts/coveredCall-want-pattern.test.js index 800ffec96d5..c9446b44bb8 100644 --- a/packages/zoe/test/unitTests/contracts/coveredCall-want-pattern.test.js +++ b/packages/zoe/test/unitTests/contracts/coveredCall-want-pattern.test.js @@ -12,8 +12,7 @@ import { TimeMath } from '@agoric/time'; import buildManualTimer from '../../../tools/manualTimer.js'; import { setup } from '../setupBasicMints.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const coveredCallRoot = `${dirname}/../../../src/contracts/coveredCall.js`; const atomicSwapRoot = `${dirname}/../../../src/contracts/atomicSwap.js`; diff --git a/packages/zoe/test/unitTests/contracts/coveredCall.test.js b/packages/zoe/test/unitTests/contracts/coveredCall.test.js index 12eda702891..d88810be877 100644 --- a/packages/zoe/test/unitTests/contracts/coveredCall.test.js +++ b/packages/zoe/test/unitTests/contracts/coveredCall.test.js @@ -16,8 +16,7 @@ import { setup } from '../setupBasicMints.js'; import { setupNonFungible } from '../setupNonFungibleMints.js'; import { assertAmountsEqual } from '../../zoeTestHelpers.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const coveredCallRoot = `${dirname}/../../../src/contracts/coveredCall.js`; const atomicSwapRoot = `${dirname}/../../../src/contracts/atomicSwap.js`; diff --git a/packages/zoe/test/unitTests/contracts/escrowToVote.test.js b/packages/zoe/test/unitTests/contracts/escrowToVote.test.js index d18972d2cd8..151b87d855e 100644 --- a/packages/zoe/test/unitTests/contracts/escrowToVote.test.js +++ b/packages/zoe/test/unitTests/contracts/escrowToVote.test.js @@ -9,8 +9,7 @@ import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { setup } from '../setupBasicMints.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/escrowToVote.js`; diff --git a/packages/zoe/test/unitTests/contracts/invitation-details.test.js b/packages/zoe/test/unitTests/contracts/invitation-details.test.js index cbc3af575d8..86f221ccb13 100644 --- a/packages/zoe/test/unitTests/contracts/invitation-details.test.js +++ b/packages/zoe/test/unitTests/contracts/invitation-details.test.js @@ -9,8 +9,7 @@ import { AmountMath } from '@agoric/ertp'; import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const root = `${dirname}/two-invitations.js`; diff --git a/packages/zoe/test/unitTests/contracts/loan/helpers.js b/packages/zoe/test/unitTests/contracts/loan/helpers.js index 44ee27ff284..cb6bab91bd6 100644 --- a/packages/zoe/test/unitTests/contracts/loan/helpers.js +++ b/packages/zoe/test/unitTests/contracts/loan/helpers.js @@ -14,8 +14,7 @@ import { setupZCFTest } from '../../zcf/setupZcfTest.js'; import { makeRatio } from '../../../../src/contractSupport/index.js'; import { assertAmountsEqual } from '../../../zoeTestHelpers.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); /** * @param {import("ava").ExecutionContext} t diff --git a/packages/zoe/test/unitTests/contracts/loan/loan-e2e.test.js b/packages/zoe/test/unitTests/contracts/loan/loan-e2e.test.js index a9d6d7ae923..fa8f7ea073f 100644 --- a/packages/zoe/test/unitTests/contracts/loan/loan-e2e.test.js +++ b/packages/zoe/test/unitTests/contracts/loan/loan-e2e.test.js @@ -15,8 +15,7 @@ import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority.js' import buildManualTimer from '../../../../tools/manualTimer.js'; import { makeRatio } from '../../../../src/contractSupport/index.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const loanRoot = `${dirname}/../../../../src/contracts/loan/`; const autoswapRoot = `${dirname}/../../../../src/contracts/autoswap`; diff --git a/packages/zoe/test/unitTests/contracts/mintPayments.test.js b/packages/zoe/test/unitTests/contracts/mintPayments.test.js index b6c29c4821c..d4bd1d0b5bc 100644 --- a/packages/zoe/test/unitTests/contracts/mintPayments.test.js +++ b/packages/zoe/test/unitTests/contracts/mintPayments.test.js @@ -11,8 +11,7 @@ import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; import { makeZoeForTest } from '../../../tools/setup-zoe.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const mintPaymentsRoot = `${dirname}/../../../src/contracts/mintPayments.js`; diff --git a/packages/zoe/test/unitTests/contracts/oracle.test.js b/packages/zoe/test/unitTests/contracts/oracle.test.js index d235b15166d..2f1693aee19 100644 --- a/packages/zoe/test/unitTests/contracts/oracle.test.js +++ b/packages/zoe/test/unitTests/contracts/oracle.test.js @@ -24,8 +24,7 @@ import '../../../src/contracts/exported.js'; * @typedef {import('ava').ExecutionContext} ExecutionContext */ -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractPath = `${dirname}/../../../src/contracts/oracle.js`; diff --git a/packages/zoe/test/unitTests/contracts/otcDesk.test.js b/packages/zoe/test/unitTests/contracts/otcDesk.test.js index f45df387c2a..6d48aecea32 100644 --- a/packages/zoe/test/unitTests/contracts/otcDesk.test.js +++ b/packages/zoe/test/unitTests/contracts/otcDesk.test.js @@ -11,8 +11,7 @@ import { setup } from '../setupBasicMints.js'; import buildManualTimer from '../../../tools/manualTimer.js'; import { assertPayoutAmount } from '../../zoeTestHelpers.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const root = `${dirname}/../../../src/contracts/otcDesk.js`; diff --git a/packages/zoe/test/unitTests/contracts/ownable-counter.test.js b/packages/zoe/test/unitTests/contracts/ownable-counter.test.js index 19e3834638c..9784adb00a4 100644 --- a/packages/zoe/test/unitTests/contracts/ownable-counter.test.js +++ b/packages/zoe/test/unitTests/contracts/ownable-counter.test.js @@ -9,8 +9,7 @@ import { GET_METHOD_NAMES } from '@endo/marshal'; import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const root = `${dirname}/ownable-counter.js`; diff --git a/packages/zoe/test/unitTests/contracts/priceAggregator.test.js b/packages/zoe/test/unitTests/contracts/priceAggregator.test.js index 1dd656d8230..ef855fd0ba3 100644 --- a/packages/zoe/test/unitTests/contracts/priceAggregator.test.js +++ b/packages/zoe/test/unitTests/contracts/priceAggregator.test.js @@ -69,8 +69,7 @@ const testStartFn = (zcf, privateArgs) => start(zcf, privateArgs); * @property {IssuerKit} link */ -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const oraclePath = `${dirname}/../../../src/contracts/oracle.js`; const aggregatorPath = `${dirname}/../../../src/contracts/priceAggregator.js`; diff --git a/packages/zoe/test/unitTests/contracts/scaledPriceAuthority.test.js b/packages/zoe/test/unitTests/contracts/scaledPriceAuthority.test.js index 67aede601f1..b5fff3bb0e2 100644 --- a/packages/zoe/test/unitTests/contracts/scaledPriceAuthority.test.js +++ b/packages/zoe/test/unitTests/contracts/scaledPriceAuthority.test.js @@ -28,8 +28,7 @@ import '../../../src/contracts/exported.js'; const test = /** @type {import('ava').TestFn} */ (unknownTest); -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const scaledPricePath = `${dirname}/../../../src/contracts/scaledPriceAuthority.js`; diff --git a/packages/zoe/test/unitTests/contracts/sellTickets.test.js b/packages/zoe/test/unitTests/contracts/sellTickets.test.js index 8ddb9d84894..931fc4b83a5 100644 --- a/packages/zoe/test/unitTests/contracts/sellTickets.test.js +++ b/packages/zoe/test/unitTests/contracts/sellTickets.test.js @@ -13,8 +13,7 @@ import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { defaultAcceptanceMsg } from '../../../src/contractSupport/index.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const mintAndSellNFTRoot = `${dirname}/../../../src/contracts/mintAndSellNFT.js`; const sellItemsRoot = `${dirname}/../../../src/contracts/sellItems.js`; diff --git a/packages/zoe/test/unitTests/contracts/simpleExchange.test.js b/packages/zoe/test/unitTests/contracts/simpleExchange.test.js index cedc441e370..f9da84f6a00 100644 --- a/packages/zoe/test/unitTests/contracts/simpleExchange.test.js +++ b/packages/zoe/test/unitTests/contracts/simpleExchange.test.js @@ -12,8 +12,7 @@ import { setupNonFungible } from '../setupNonFungibleMints.js'; import { installationPFromSource } from '../installFromSource.js'; import { assertPayoutAmount, assertOfferResult } from '../../zoeTestHelpers.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const simpleExchange = `${dirname}/../../../src/contracts/simpleExchange.js`; diff --git a/packages/zoe/test/unitTests/contracts/throwInOfferHandler.test.js b/packages/zoe/test/unitTests/contracts/throwInOfferHandler.test.js index 27a7947b63b..6a1e5ab73f0 100644 --- a/packages/zoe/test/unitTests/contracts/throwInOfferHandler.test.js +++ b/packages/zoe/test/unitTests/contracts/throwInOfferHandler.test.js @@ -8,8 +8,7 @@ import { E } from '@endo/eventual-send'; import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/throwInOfferHandler.js`; diff --git a/packages/zoe/test/unitTests/contracts/useObj.test.js b/packages/zoe/test/unitTests/contracts/useObj.test.js index f2633bbacf1..057d028c8c2 100644 --- a/packages/zoe/test/unitTests/contracts/useObj.test.js +++ b/packages/zoe/test/unitTests/contracts/useObj.test.js @@ -9,8 +9,7 @@ import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { setup } from '../setupBasicMints.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/useObjExample.js`; diff --git a/packages/zoe/test/unitTests/instanceStorage.test.js b/packages/zoe/test/unitTests/instanceStorage.test.js index b09ca9b3f8d..63259f83f45 100644 --- a/packages/zoe/test/unitTests/instanceStorage.test.js +++ b/packages/zoe/test/unitTests/instanceStorage.test.js @@ -12,8 +12,7 @@ import { makeScalarBigMapStore } from '@agoric/vat-data'; import { makeInstanceRecordStorage } from '../../src/instanceRecordStorage.js'; import { makeIssuerRecord } from '../../src/issuerRecord.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const root = `${dirname}/bounty.js`; diff --git a/packages/zoe/test/unitTests/makeKind.test.js b/packages/zoe/test/unitTests/makeKind.test.js index c765d77fd05..5745182c001 100644 --- a/packages/zoe/test/unitTests/makeKind.test.js +++ b/packages/zoe/test/unitTests/makeKind.test.js @@ -11,8 +11,7 @@ import { E } from '@endo/eventual-send'; import { makeZoeForTest } from '../../tools/setup-zoe.js'; import { makeFakeVatAdmin } from '../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const root = `${dirname}/../minimalMakeKindContract.js`; diff --git a/packages/zoe/test/unitTests/scriptedOracle.test.js b/packages/zoe/test/unitTests/scriptedOracle.test.js index c0dc6021061..6a817c2fe1b 100644 --- a/packages/zoe/test/unitTests/scriptedOracle.test.js +++ b/packages/zoe/test/unitTests/scriptedOracle.test.js @@ -20,8 +20,7 @@ import { makeScriptedOracle } from '../../tools/scriptedOracle.js'; // This test shows how to set up a fake oracle and use it in a contract. -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const oracleContractPath = `${dirname}/../../src/contracts/oracle.js`; const bountyContractPath = `${dirname}/bounty.js`; diff --git a/packages/zoe/test/unitTests/zcf/feeMintAccess.test.js b/packages/zoe/test/unitTests/zcf/feeMintAccess.test.js index 47d32265b35..9f3cba56721 100644 --- a/packages/zoe/test/unitTests/zcf/feeMintAccess.test.js +++ b/packages/zoe/test/unitTests/zcf/feeMintAccess.test.js @@ -10,8 +10,7 @@ import bundleSource from '@endo/bundle-source'; import { makeZoeKitForTest } from '../../../tools/setup-zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/registerFeeMintContract.js`; diff --git a/packages/zoe/test/unitTests/zcf/setupZcfTest.js b/packages/zoe/test/unitTests/zcf/setupZcfTest.js index 44f8c6d2a2c..413a0dd72c7 100644 --- a/packages/zoe/test/unitTests/zcf/setupZcfTest.js +++ b/packages/zoe/test/unitTests/zcf/setupZcfTest.js @@ -7,8 +7,7 @@ import path from 'path'; import { makeZoeKitForTest } from '../../../tools/setup-zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/zcfTesterContract.js`; diff --git a/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js b/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js index 212ae4becb8..59859f776e4 100644 --- a/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js +++ b/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js @@ -9,8 +9,7 @@ import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { setup } from '../setupBasicMints.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/zcfTesterContract.js`; diff --git a/packages/zoe/test/unitTests/zcf/zcfSeat.test.js b/packages/zoe/test/unitTests/zcf/zcfSeat.test.js index 5fa258e029a..568815a6cb1 100644 --- a/packages/zoe/test/unitTests/zcf/zcfSeat.test.js +++ b/packages/zoe/test/unitTests/zcf/zcfSeat.test.js @@ -9,8 +9,7 @@ import { makeZoeForTest } from '../../../tools/setup-zoe.js'; import { setup } from '../setupBasicMints.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); const contractRoot = `${dirname}/zcfTesterContract.js`; diff --git a/packages/zoe/test/unitTests/zoe-startInstance.test.js b/packages/zoe/test/unitTests/zoe-startInstance.test.js index fb13072e98c..af77e291326 100644 --- a/packages/zoe/test/unitTests/zoe-startInstance.test.js +++ b/packages/zoe/test/unitTests/zoe-startInstance.test.js @@ -9,8 +9,7 @@ import path from 'path'; import { setup } from './setupBasicMints.js'; import { setupZCFTest } from './zcf/setupZcfTest.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); test('bad installation', async t => { const { zoe } = setup(); diff --git a/packages/zoe/test/unitTests/zoe.test.js b/packages/zoe/test/unitTests/zoe.test.js index c2937823ea2..61d61ad830d 100644 --- a/packages/zoe/test/unitTests/zoe.test.js +++ b/packages/zoe/test/unitTests/zoe.test.js @@ -11,8 +11,7 @@ import bundleSource from '@endo/bundle-source'; import { setup } from './setupBasicMints.js'; import { setupZCFTest } from './zcf/setupZcfTest.js'; -const filename = new URL(import.meta.url).pathname; -const dirname = path.dirname(filename); +const dirname = path.dirname(new URL(import.meta.url).pathname); test(`zoe.getInvitationIssuer`, async t => { const { zoe, zcf } = await setupZCFTest(); diff --git a/packages/zoe/tools/setup-zoe.js b/packages/zoe/tools/setup-zoe.js index f209f499975..6c6a97a1b1c 100644 --- a/packages/zoe/tools/setup-zoe.js +++ b/packages/zoe/tools/setup-zoe.js @@ -1,6 +1,7 @@ -import { makeLoopback } from '@endo/captp'; +import { E, makeLoopback } from '@endo/captp'; import { makeScalarBigMapStore } from '@agoric/vat-data'; +import bundleSource from '@endo/bundle-source'; import { makeDurableZoeKit } from '../src/zoeService/zoe.js'; import fakeVatAdmin, { makeFakeVatAdmin } from './fakeVatAdmin.js'; @@ -53,9 +54,23 @@ export const setUpZoeForTest = async ({ zoeBaggage: makeScalarBigMapStore('zoe baggage', { durable: true }), }), ); + + /** + * @param {string} path + * @returns {Promise} + */ + const bundleAndInstall = async path => { + const bundle = await bundleSource(path); + const id = `b1-${path}`; + assert(vatAdminState, 'installBundle called before vatAdminState defined'); + vatAdminState.installBundle(id, bundle); + return E(zoeService).installBundleID(id); + }; + return { zoe: zoeService, feeMintAccessP: feeMintAccess, + bundleAndInstall, vatAdminSvc, vatAdminState, }; diff --git a/packages/zoe/tools/test-utils.js b/packages/zoe/tools/test-utils.js new file mode 100644 index 00000000000..6d0b13661e2 --- /dev/null +++ b/packages/zoe/tools/test-utils.js @@ -0,0 +1,24 @@ +import { AmountMath } from '@agoric/ertp'; +import { makeRatio } from '../src/contractSupport/ratio.js'; + +/** @param {Pick, 'brand' | 'issuer' | 'mint'>} kit */ +export const withAmountUtils = kit => { + const decimalPlaces = kit.issuer.getDisplayInfo?.()?.decimalPlaces ?? 6; + return { + ...kit, + /** @param {NatValue} v */ + make: v => AmountMath.make(kit.brand, v), + makeEmpty: () => AmountMath.makeEmpty(kit.brand), + /** + * @param {NatValue} n + * @param {NatValue} [d] + */ + makeRatio: (n, d) => makeRatio(n, kit.brand, d), + /** @param {number} n */ + units: n => + AmountMath.make(kit.brand, BigInt(Math.round(n * 10 ** decimalPlaces))), + }; +}; +/** @typedef {ReturnType} AmountUtils */ + +export { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';