Skip to content

Commit

Permalink
misc testing improvements (#9381)
Browse files Browse the repository at this point in the history
refs: #9063

## Description

Extracted from #9376


### Security Considerations

<!-- Does this change introduce new assumptions or dependencies that, if
violated, could introduce security vulnerabilities? How does this PR
change the boundaries between mutually-suspicious components? What new
authorities are introduced by this change, perhaps by new API calls?
-->

### Scaling Considerations

<!-- Does this change require or encourage significant increase in
consumption of CPU cycles, RAM, on-chain storage, message exchanges, or
other scarce resources? If so, can that be prevented or mitigated? -->

### Documentation Considerations

<!-- Give our docs folks some hints about what needs to be described to
downstream users.

Backwards compatibility: what happens to existing data or deployments
when this code is shipped? Do we need to instruct users to do something
to upgrade their saved data? If there is no upgrade path possible, how
bad will that be for users?

-->

### Testing Considerations

<!-- Every PR should of course come with tests of its own functionality.
What additional tests are still needed beyond those unit tests? How does
this affect CI, other test automation, or the testnet?
-->

### Upgrade Considerations

<!-- What aspects of this PR are relevant to upgrading live production
systems, and how should they be addressed? -->
  • Loading branch information
mergify[bot] committed May 20, 2024
2 parents 16095c5 + d05f83a commit b953651
Show file tree
Hide file tree
Showing 68 changed files with 187 additions and 233 deletions.
3 changes: 1 addition & 2 deletions packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions packages/boot/test/bootstrapTests/zcf-upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
9 changes: 2 additions & 7 deletions packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions packages/governance/test/unitTests/committee.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
6 changes: 4 additions & 2 deletions packages/inter-protocol/test/auction/auctionContract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ import { setUpInstallations } from './tools.js';
/** @type {import('ava').TestFn<Awaited<ReturnType<makeTestContext>>>} */
const test = anyTest;

/** @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; */

/**
* @typedef {Record<string, any> & {
* bid: IssuerKit & import('../supports.js').AmountUtils;
* collateral: IssuerKit & import('../supports.js').AmountUtils;
* bid: IssuerKit & AmountUtils;
* collateral: IssuerKit & AmountUtils;
* zoe: ZoeService;
* }} Context
*/
Expand Down
36 changes: 8 additions & 28 deletions packages/inter-protocol/test/supports.js
Original file line number Diff line number Diff line change
@@ -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' */

Expand Down Expand Up @@ -152,25 +150,7 @@ export const produceInstallations = (space, installations) => {

export const scale6 = x => BigInt(Math.round(x * 1_000_000));

/** @param {Pick<IssuerKit<'nat'>, '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<typeof withAmountUtils>} AmountUtils */
export { withAmountUtils } from '@agoric/zoe/tools/test-utils.js';

/** @param {ERef<StoredSubscription<unknown> | StoredSubscriber<unknown>>} subscription */
export const subscriptionKey = subscription => {
Expand Down
15 changes: 9 additions & 6 deletions packages/inter-protocol/test/vaultFactory/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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({
Expand All @@ -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: {
Expand All @@ -95,7 +98,7 @@ const defaultParamValues = debt =>
* minInitialDebt: bigint;
* reserveCreatorFacet: ERef<AssetReserveLimitedCreatorFacet>;
* rates: any;
* run: IssuerKit & import('../supports.js').AmountUtils;
* run: IssuerKit & AmountUtils;
* stableInitialLiquidity: Amount<'nat'>;
* timer: ReturnType<typeof buildManualTimer>;
* zoe: ZoeService;
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> & {
* aeth: IssuerKit & import('../supports.js').AmountUtils;
* run: IssuerKit & import('../supports.js').AmountUtils;
* aeth: IssuerKit & AmountUtils;
* run: IssuerKit & AmountUtils;
* bundleCache: Awaited<ReturnType<typeof unsafeMakeBundleCache>>;
* rates: VaultManagerParamValues;
* interestTiming: InterestTiming;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> & {
* aeth: IssuerKit & import('../supports.js').AmountUtils;
* run: IssuerKit & import('../supports.js').AmountUtils;
* aeth: IssuerKit & AmountUtils;
* run: IssuerKit & AmountUtils;
* bundleCache: Awaited<ReturnType<typeof unsafeMakeBundleCache>>;
* rates: VaultManagerParamValues;
* interestTiming: InterestTiming;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> & {
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> & {
* aeth: IssuerKit & import('../supports.js').AmountUtils;
* run: IssuerKit & import('../supports.js').AmountUtils;
* aeth: IssuerKit & AmountUtils;
* run: IssuerKit & AmountUtils;
* bundleCache: Awaited<ReturnType<typeof unsafeMakeBundleCache>>;
* rates: VaultManagerParamValues;
* interestTiming: InterestTiming;
Expand Down
6 changes: 3 additions & 3 deletions packages/orchestration/src/cosmos-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;

Expand Down Expand Up @@ -168,8 +168,8 @@ export interface IcaAccount {
executeTx: (msgs: Proto3JSONMsg[]) => Promise<string>;
/**
* Submit a transaction on behalf of the remote account for execution on the remote chain.
* @param {AnyJson[]} msgs - records for the transaction
* @param {Partial<Omit<TxBody, 'messages'>>} [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: (
Expand Down
Loading

0 comments on commit b953651

Please sign in to comment.