Skip to content

Commit

Permalink
adopt EReturn type (#9011)
Browse files Browse the repository at this point in the history
## Description

While working on another PR, I had to type out `ReturnType<Awaited<ReturnType<` again and I wished for a utility type.

This PR first made an `ExoObj` type but has changed to use `EReturn` now available in Endo.
- endojs/endo#2659

### Security Considerations
n/a
### Scaling Considerations

n/a

### Documentation Considerations

Not necessary

### Testing Considerations

CI

### Upgrade Considerations

n/a
  • Loading branch information
mergify[bot] authored Jan 29, 2025
2 parents 83c2ebd + dc34013 commit 1d8b7d2
Show file tree
Hide file tree
Showing 49 changed files with 188 additions and 105 deletions.
6 changes: 5 additions & 1 deletion packages/SwingSet/src/controller/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import {
import { makeStartXSnap } from './startXSnap.js';
import { makeStartSubprocessWorkerNode } from './startNodeSubprocess.js';

/**
* @import {EReturn} from '@endo/far';
*/

/**
* @typedef { import('../types-internal.js').VatID } VatID
*/
Expand Down Expand Up @@ -494,7 +498,7 @@ export async function makeSwingsetController(

return controller;
}
/** @typedef {Awaited<ReturnType<typeof makeSwingsetController>>} SwingsetController */
/** @typedef {EReturn<typeof makeSwingsetController>} SwingsetController */

/**
* NB: To be used only in tests. An app with this may not survive a reboot.
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/upgrade/upgrade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const makeConfigFromPaths = (bootstrapVatPath, options = {}) => {
* Refcount incrementing should be manual,
* see https://github.com/Agoric/agoric-sdk/issues/7213
* @returns {Promise<{
* controller: Awaited<ReturnType<typeof makeSwingsetController>>,
* controller: EReturn<typeof makeSwingsetController>,
* kvStore: KVStore,
* messageToVat: (vatName: string, method: string, ...args: unknown[]) => Promise<unknown>,
* messageToVatAndRetain: (vatName: string, method: string, ...args: unknown[]) => Promise<unknown>,
Expand Down
6 changes: 5 additions & 1 deletion packages/SwingSet/tools/bundleTool.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { makeNodeBundleCache as wrappedMaker } from '@endo/bundle-source/cache.js';
import styles from 'ansi-styles'; // less authority than 'chalk'

/**
* @import {EReturn} from '@endo/far';
*/

/** @type {typeof wrappedMaker} */
export const makeNodeBundleCache = async (dest, options, loadModule, pid) => {
const log = (...args) => {
Expand All @@ -17,7 +21,7 @@ export const makeNodeBundleCache = async (dest, options, loadModule, pid) => {
};
return wrappedMaker(dest, { log, ...options }, loadModule, pid);
};
/** @typedef {Awaited<ReturnType<typeof makeNodeBundleCache>>} BundleCache */
/** @typedef {EReturn<typeof makeNodeBundleCache>} BundleCache */

/** @type {Map<string, Promise<BundleCache>>} */
const providedCaches = new Map();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import type { TestFn } from 'ava';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/boot/test/bootstrapTests/net-ibc-upgrade.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @file upgrade network / IBC vat at many points in state machine */
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
import type { TestFn } from 'ava';
import { createRequire } from 'module';
Expand Down
1 change: 1 addition & 0 deletions packages/boot/test/bootstrapTests/upgradeAPI.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test as anyTest } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';

import type { TestFn } from 'ava';
import path from 'path';
import bundleSource from '@endo/bundle-source';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import type { TestFn } from 'ava';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import {
makeWalletFactoryContext,
type WalletFactoryTestContext,
Expand Down
3 changes: 2 additions & 1 deletion packages/boot/test/upgrading/upgrade-contracts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* @file cribbed from
* packages/zoe/test/swingsetTests/upgradeCoveredCall/test-coveredCall-service-upgrade.js
*/
import { resolve as importMetaResolve } from 'import-meta-resolve';
import { test as anyTest } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';

import { resolve as importMetaResolve } from 'import-meta-resolve';
import { buildVatController } from '@agoric/swingset-vat';

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/casting/test/interpose-net-access.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
import { makeTendermintRpcClient } from '../src/makeHttpClient.js';
import { captureIO, replayIO, web1, web2 } from './net-access-fixture.js';

/** @type {import('ava').TestFn<Awaited<ReturnType<typeof makeTestContext>>>} */
/**
* @import {EReturn} from '@endo/far';
*/

/** @type {import('ava').TestFn<EReturn<typeof makeTestContext>>} */
const test = /** @type {any} */ (anyTest);

const RECORDING = false;
Expand Down
3 changes: 2 additions & 1 deletion packages/client-utils/src/smart-wallet-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { makeStargateClient } from './rpc.js';
import { makeAgoricNames, makeVstorageKit } from './vstorage-kit.js';

/**
* @import {EReturn} from '@endo/far';
* @import {Amount, Brand} from '@agoric/ertp/src/types.js'
* @import {CurrentWalletRecord, UpdateRecord} from '@agoric/smart-wallet/src/smartWallet.js';
* @import {MinimalNetworkConfig} from './network-config.js';
Expand Down Expand Up @@ -110,4 +111,4 @@ export const makeSmartWalletKit = async ({ fetch, delay }, networkConfig) => {
pollOffer,
};
};
/** @typedef {Awaited<ReturnType<typeof makeSmartWalletKit>>} SmartWalletKit */
/** @typedef {EReturn<typeof makeSmartWalletKit>} SmartWalletKit */
6 changes: 5 additions & 1 deletion packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ import {
validateImporterOptions,
} from './import-kernel-db.js';

/**
* @import {EReturn} from '@endo/far';
*/

const ignore = () => {};

// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -581,7 +585,7 @@ export default async function main(
return blockingSendSpy;
}

/** @type {Awaited<ReturnType<typeof launch>>['blockingSend'] | undefined} */
/** @type {EReturn<typeof launch>['blockingSend'] | undefined} */
let blockingSend;

async function handleSwingStoreExport(blockHeight, request, requestArgs) {
Expand Down
7 changes: 4 additions & 3 deletions packages/fast-usdc/test/cli/lp-commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
import type { EReturn } from '@endo/far';
import { Far, makeMarshal } from '@endo/marshal';
import anyTest, { type TestFn } from 'ava';
import { Command } from 'commander';
import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
import { addLPCommands } from '../../src/cli/lp-commands.js';
import { flags } from '../../tools/cli-tools.js';
import { mockStream } from '../../tools/mock-io.js';
import { addLPCommands } from '../../src/cli/lp-commands.js';

const makeTestContext = () => {
const program = new Command();
Expand Down Expand Up @@ -54,7 +55,7 @@ const makeTestContext = () => {
return { program, marshaller, out, err, USDC, FastLP, now };
};

const test = anyTest as TestFn<Awaited<ReturnType<typeof makeTestContext>>>;
const test = anyTest as TestFn<EReturn<typeof makeTestContext>>;
test.beforeEach(async t => (t.context = await makeTestContext()));

test('fast-usdc deposit command', async t => {
Expand Down
11 changes: 6 additions & 5 deletions packages/fast-usdc/test/exos/advancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,37 @@ import {
encodeAddressHook,
} from '@agoric/cosmic-proto/address-hooks.js';
import type { NatAmount } from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { ChainAddressShape, denomHash } from '@agoric/orchestration';
import fetchedChainInfo from '@agoric/orchestration/src/fetched-chain-info.js';
import { type ZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js';
import { q } from '@endo/errors';
import type { EReturn } from '@endo/far';
import { Far } from '@endo/pass-style';
import type { TestFn } from 'ava';
import { makeTracer } from '@agoric/internal';
import { M, mustMatch } from '@endo/patterns';
import type { TestFn } from 'ava';
import { PendingTxStatus } from '../../src/constants.js';
import { prepareAdvancer, stateShape } from '../../src/exos/advancer.js';
import {
makeAdvanceDetailsShape,
type SettlerKit,
} from '../../src/exos/settler.js';
import { prepareStatusManager } from '../../src/exos/status-manager.js';
import { CctpTxEvidenceShape } from '../../src/type-guards.js';
import type { LiquidityPoolKit } from '../../src/types.js';
import { makeFeeTools } from '../../src/utils/fees.js';
import {
intermediateRecipient,
MockCctpTxEvidences,
settlementAddress,
intermediateRecipient,
} from '../fixtures.js';
import {
makeTestFeeConfig,
makeTestLogger,
prepareMockOrchAccounts,
} from '../mocks.js';
import { commonSetup } from '../supports.js';
import { CctpTxEvidenceShape } from '../../src/type-guards.js';

const trace = makeTracer('AdvancerTest', false);

Expand All @@ -44,7 +45,7 @@ const LOCAL_DENOM = `ibc/${denomHash({
fetchedChainInfo.agoric.connections['noble-1'].transferChannel.channelId,
})}`;

type CommonSetup = Awaited<ReturnType<typeof commonSetup>>;
type CommonSetup = EReturn<typeof commonSetup>;

const createTestExtensions = (t, common: CommonSetup) => {
const {
Expand Down
3 changes: 2 additions & 1 deletion packages/fast-usdc/test/exos/settler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import fetchedChainInfo from '@agoric/orchestration/src/fetched-chain-info.js';
import { buildVTransferEvent } from '@agoric/orchestration/tools/ibc-mocks.js';
import type { Zone } from '@agoric/zone';
import type { EReturn } from '@endo/far';
import { PendingTxStatus, TxStatus } from '../../src/constants.js';
import {
prepareSettler,
Expand Down Expand Up @@ -215,7 +216,7 @@ const makeTestContext = async t => {
};
};

const test = anyTest as TestFn<Awaited<ReturnType<typeof makeTestContext>>>;
const test = anyTest as TestFn<EReturn<typeof makeTestContext>>;

test.beforeEach(async t => (t.context = await makeTestContext(t)));

Expand Down
11 changes: 6 additions & 5 deletions packages/fast-usdc/test/exos/status-manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import type { TestFn } from 'ava';

import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { defaultMarshaller } from '@agoric/internal/src/storage-test-utils.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import type { EReturn } from '@endo/far';
import { PendingTxStatus } from '../../src/constants.js';
import {
prepareStatusManager,
stateShape,
type StatusManager,
} from '../../src/exos/status-manager.js';
import { commonSetup, provideDurableZone } from '../supports.js';
import { MockCctpTxEvidences } from '../fixtures.js';
import type { CctpTxEvidence } from '../../src/types.js';
import { MockCctpTxEvidences } from '../fixtures.js';
import { commonSetup, provideDurableZone } from '../supports.js';

type Common = Awaited<ReturnType<typeof commonSetup>>;
type Common = EReturn<typeof commonSetup>;
type TestContext = {
statusManager: StatusManager;
storage: Common['bootstrap']['storage'];
Expand Down
8 changes: 4 additions & 4 deletions packages/fast-usdc/test/fast-usdc.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '@agoric/zoe/src/contractSupport/ratio.js';
import type { Instance } from '@agoric/zoe/src/zoeService/utils.js';
import { setUpZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
import { E } from '@endo/far';
import { E, type EReturn } from '@endo/far';
import { matches } from '@endo/patterns';
import { makePromiseKit } from '@endo/promise-kit';
import path from 'path';
Expand Down Expand Up @@ -61,7 +61,7 @@ const getInvitationProperties = async (
// Spec for Mainnet. Other values are covered in unit tests of TransactionFeed.
const operatorQty = 3;

type CommonSetup = Awaited<ReturnType<typeof commonSetup>>;
type CommonSetup = EReturn<typeof commonSetup>;
const startContract = async (
common: Pick<CommonSetup, 'brands' | 'commonPrivateArgs' | 'utils'>,
) => {
Expand Down Expand Up @@ -124,7 +124,7 @@ const makeTestContext = async (t: ExecutionContext) => {
});

const sync = {
ocw: makePromiseKit<Awaited<ReturnType<typeof makeOracleOperator>>[]>(),
ocw: makePromiseKit<EReturn<typeof makeOracleOperator>[]>(),
lp: makePromiseKit<Record<string, ReturnType<typeof makeLP>>>(),
};

Expand Down Expand Up @@ -171,7 +171,7 @@ const makeTestContext = async (t: ExecutionContext) => {
};
};

type FucContext = Awaited<ReturnType<typeof makeTestContext>>;
type FucContext = EReturn<typeof makeTestContext>;
const test = anyTest as TestFn<FucContext>;
test.before(async t => (t.context = await makeTestContext(t)));

Expand Down
7 changes: 4 additions & 3 deletions packages/governance/src/contractGovernorKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
import { ClosingRuleShape, ParamChangesSpecShape } from './typeGuards.js';

/**
* @import {VoteCounterCreatorFacet, VoteCounterPublicFacet, QuestionSpec, OutcomeRecord, AddQuestion, AddQuestionReturn, ClosingRule, GovernableStartFn, LimitedCF, PoserFacet, VoteOnApiInvocation, VoteOnOfferFilter, VoteOnParamChanges} from './types.js';
* @import {EReturn} from '@endo/far';
* @import {ClosingRule, GovernableStartFn, LimitedCF, PoserFacet, VoteOnApiInvocation, VoteOnOfferFilter, VoteOnParamChanges} from './types.js';
*/

const trace = makeTracer('CGK', false);
Expand Down Expand Up @@ -72,7 +73,7 @@ export const prepareContractGovernorKit = (baggage, powers) => {
let filterGovernance;
/** @type {ReturnType<typeof setupParamGovernance>} */
let paramGovernance;
/** @type {Awaited<ReturnType<typeof setupApiGovernance>>} */
/** @type {EReturn<typeof setupApiGovernance>} */
let apiGovernance;

/** @type {any} */
Expand Down Expand Up @@ -277,4 +278,4 @@ export const prepareContractGovernorKit = (baggage, powers) => {
return makeContractGovernorKit;
};

/** @typedef {ReturnType<ReturnType<typeof prepareContractGovernorKit>>} ContractGovernorKit */
/** @typedef {EReturn<EReturn<typeof prepareContractGovernorKit>>} ContractGovernorKit */
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
} from '../../../src/index.js';
import { MALLEABLE_NUMBER } from './governedContract.js';

/**
* @import {EReturn} from '@endo/far';
*/

const build = async (log, zoe) => {
return Far('voter', {
createVoter: async (name, invitation) => {
Expand Down Expand Up @@ -105,7 +109,7 @@ const build = async (log, zoe) => {
};

/**
* @typedef {ReturnType<Awaited<ReturnType<typeof build>>['createVoter']>} EVatVoter
* @typedef {ReturnType<EReturn<typeof build>['createVoter']>} EVatVoter
*/

/** @type {import('@agoric/swingset-vat/src/kernel/vat-loader/types.js').BuildRootObjectForTestVat} */
Expand Down
3 changes: 2 additions & 1 deletion packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from './util.js';

/**
* @import {EReturn} from '@endo/far';
* @import {Baggage} from '@agoric/vat-data';
* @import {PriceAuthority} from '@agoric/zoe/tools/types.js';
* @import {TypedPattern} from '@agoric/internal';
Expand Down Expand Up @@ -790,4 +791,4 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
};
harden(prepareAuctionBook);

/** @typedef {ReturnType<ReturnType<typeof prepareAuctionBook>>} AuctionBook */
/** @typedef {EReturn<EReturn<typeof prepareAuctionBook>>} AuctionBook */
3 changes: 2 additions & 1 deletion packages/inter-protocol/src/price/fluxAggregatorKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { prepareOracleAdminKit } from './priceOracleKit.js';
import { prepareRoundsManagerKit } from './roundsManager.js';

/**
* @import {EReturn} from '@endo/far';
* @import {TypedPattern} from '@agoric/internal';
* @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
*/
Expand Down Expand Up @@ -371,4 +372,4 @@ export const prepareFluxAggregatorKit = async (
return makeFluxAggregatorKit;
};
harden(prepareFluxAggregatorKit);
/** @typedef {ReturnType<Awaited<ReturnType<typeof prepareFluxAggregatorKit>>>} FluxAggregatorKit */
/** @typedef {EReturn<EReturn<typeof prepareFluxAggregatorKit>>} FluxAggregatorKit */
6 changes: 5 additions & 1 deletion packages/inter-protocol/src/price/priceOracleKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const trace = makeTracer('OrKit', true);

export const INVITATION_MAKERS_DESC = 'oracle invitation';

/**
* @import {EReturn} from '@endo/far';
*/

/**
* @typedef {{
* oracleId: string;
Expand Down Expand Up @@ -122,4 +126,4 @@ export const prepareOracleAdminKit = baggage =>
},
);

/** @typedef {ReturnType<ReturnType<typeof prepareOracleAdminKit>>} OracleKit */
/** @typedef {EReturn<EReturn<typeof prepareOracleAdminKit>>} OracleKit */
6 changes: 5 additions & 1 deletion packages/inter-protocol/src/psm/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import { makeNatAmountShape } from '../contractSupport.js';
* stable token are specified separately.
*/

/**
* @import {EReturn} from '@endo/far';
*/

/**
* @typedef {object} MetricsNotification Metrics naming scheme is that nouns are
* present values and past-participles are accumulative.
Expand Down Expand Up @@ -442,4 +446,4 @@ export const start = async (zcf, privateArgs, baggage) => {
};
harden(start);

/** @typedef {Awaited<ReturnType<typeof start>>['publicFacet']} PsmPublicFacet */
/** @typedef {EReturn<typeof start>['publicFacet']} PsmPublicFacet */
Loading

0 comments on commit 1d8b7d2

Please sign in to comment.