Skip to content

Commit

Permalink
feat: add hermes client to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Aug 7, 2024
1 parent 140cf7f commit e09e8fc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion multichain-testing/test/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));

Expand Down Expand Up @@ -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<ReturnType<typeof commonSetup>>;
Expand Down
71 changes: 71 additions & 0 deletions multichain-testing/tools/hermes-tools.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};

0 comments on commit e09e8fc

Please sign in to comment.