From dfc830bcf5f1997a5aebd23c407aa8f1a7d52083 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 8 May 2024 14:46:00 -0700 Subject: [PATCH] feat(types): generic return for executeTx --- packages/orchestration/test/types.test-d.ts | 24 +++++++++++++++++++++ packages/vats/src/localchain.js | 11 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/orchestration/test/types.test-d.ts b/packages/orchestration/test/types.test-d.ts index d3c0b0a3eaa..edc7daee4a3 100644 --- a/packages/orchestration/test/types.test-d.ts +++ b/packages/orchestration/test/types.test-d.ts @@ -3,7 +3,11 @@ * @file pure types types, no runtime, ignored by Ava */ import { expectNotType, expectType } from 'tsd'; +import { typedJson } from '@agoric/cosmic-proto'; +import type { MsgDelegateResponse } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; +import type { QueryAllBalancesResponse } from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js'; import type { ChainAddress, CosmosValidatorAddress } from '../src/types.js'; +import type { LocalchainAccountKit } from '../src/exos/localchainAccountKit.js'; const validatorAddr = { chainId: 'agoric3', @@ -24,3 +28,23 @@ expectNotType(chainAddr); // @ts-expect-error const notVa: CosmosValidatorAddress = chainAddr; } + +{ + const lcak: LocalchainAccountKit = null as any; + const lca = lcak.helper.owned(); + const results = await lca.executeTx([ + typedJson('/cosmos.staking.v1beta1.MsgDelegate', { + amount: { + amount: '1', + denom: 'ubld', + }, + validatorAddress: 'agoric1valoperhello', + delegatorAddress: 'agoric1pleab', + }), + typedJson('/cosmos.bank.v1beta1.QueryAllBalancesRequest', { + address: 'agoric1pleab', + }), + ] as const); + expectType(results[0]); + expectType(results[1]); +} diff --git a/packages/vats/src/localchain.js b/packages/vats/src/localchain.js index ade92745c56..66d4000c2df 100644 --- a/packages/vats/src/localchain.js +++ b/packages/vats/src/localchain.js @@ -5,6 +5,8 @@ import { AmountShape } from '@agoric/ertp'; const { Fail, bare } = assert; +/** @import {TypedJson, ResponseTo} from '@agoric/cosmic-proto'; */ + /** * @typedef {{ * system: import('./types.js').ScopedBridgeManager; @@ -68,8 +70,13 @@ const prepareLocalChainAccount = zone => return E(allegedPurse).deposit(payment); }, /** - * @param {import('@agoric/cosmic-proto').TypedJson[]} messages - * @returns {Promise} + * Execute a batch of transactions and return the responses. Use + * `typedJson()` on the arguments to get typed return values. + * + * @template {TypedJson[]} MT messages tuple (use const with multiple + * elements or it will be a mixed array) + * @param {MT} messages + * @returns {Promise<{ [K in keyof MT]: ResponseTo }>} */ async executeTx(messages) { const { address, powers } = this.state;