From e09e8fccc0ab330c5b7bc64670f9d68b0244882d Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Wed, 7 Aug 2024 17:38:35 -0400 Subject: [PATCH] feat: add hermes client to tools --- multichain-testing/test/support.ts | 4 +- multichain-testing/tools/hermes-tools.ts | 71 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 multichain-testing/tools/hermes-tools.ts diff --git a/multichain-testing/test/support.ts b/multichain-testing/test/support.ts index 98f7c0490ac0..c5d129b60916 100644 --- a/multichain-testing/test/support.ts +++ b/multichain-testing/test/support.ts @@ -9,6 +9,7 @@ import { makeGetFile, makeSetupRegistry } from '../tools/registry.js'; import { generateMnemonic } from '../tools/wallet.js'; import { makeRetryUntilCondition } from '../tools/sleep.js'; import { makeDeployBuilder } from '../tools/deploy.js'; +import { makeHermes } from '../tools/hermes-tools.js'; const setupRegistry = makeSetupRegistry(makeGetFile({ dirname, join })); @@ -59,8 +60,9 @@ export const commonSetup = async (t: ExecutionContext) => { log: t.log, setTimeout: globalThis.setTimeout, }); + const hermes = makeHermes(childProcess); - return { useChain, ...tools, ...keyring, retryUntilCondition, deployBuilder }; + return { useChain, ...tools, ...keyring, retryUntilCondition, deployBuilder, hermes }; }; export type SetupContext = Awaited>; diff --git a/multichain-testing/tools/hermes-tools.ts b/multichain-testing/tools/hermes-tools.ts new file mode 100644 index 000000000000..d2b061ab6fd1 --- /dev/null +++ b/multichain-testing/tools/hermes-tools.ts @@ -0,0 +1,71 @@ +import type { IBCChannelID, IBCConnectionID, IBCPortID } from '@agoric/vats'; +import type { ExecSync } from './agd-lib.js'; + +const kubectlBinary = 'kubectl'; + +// based on config.yaml +const relayerMap = { + osmosis: 'hermes-agoric-osmosis-0', + cosmoshub: 'hermes-agoric-gaia-0', +}; + +const getBinaryArgs = (chainName: string) => { + if (!relayerMap[chainName]) throw Error('Unsupported chain: ' + chainName); + return [ + 'exec', + '-i', + relayerMap[chainName], + '-c', + 'relayer', + '--tty=false', + '--', + 'hermes', + ]; +}; + +type ChannelCloseParams = { + dst: { + chainId: string; + portID: IBCPortID; + channelID: IBCChannelID; + connectionID: IBCConnectionID; + }; + src: { + chainId: string; + portID: IBCPortID; + channelID: IBCChannelID; + }; +}; + +export const makeHermes = ({ execFileSync }: { execFileSync: ExecSync }) => { + const exec = ( + chainName: string, + args: string[], + opts = { encoding: 'utf-8' as const, stdio: ['ignore', 'pipe', 'ignore'] }, + ) => + execFileSync(kubectlBinary, [...getBinaryArgs(chainName), ...args], opts); + + /** Submit MsgChannelCloseInit to the src chain */ + const channelCloseInit = ( + chainName: string, + dst: ChannelCloseParams['dst'], + src: ChannelCloseParams['src'], + ) => { + return exec(chainName, [ + 'tx', + 'chan-close-init', + `--dst-chain=${dst.chainId}`, + `--src-chain=${src.chainId}`, + `--dst-connection=${dst.connectionID}`, + `--dst-port=${dst.portID}`, + `--src-port=${src.portID}`, + `--dst-channel=${dst.channelID}`, + `--src-channel=${src.channelID}`, + ]); + }; + + return { + exec, + channelCloseInit, + }; +};