Skip to content

Commit

Permalink
feat: support go-relayer rly commands
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Oct 2, 2024
1 parent aa5cf0e commit 8eaff81
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
5 changes: 5 additions & 0 deletions multichain-testing/test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ export const MAKE_ACCOUNT_AND_QUERY_BALANCE_TIMEOUT: RetryOptions = {
retryIntervalMs: 5000,
maxRetries: 24,
};

export const TWO_MINUTES: RetryOptions = {
retryIntervalMs: 5000,
maxRetries: 24,
};
2 changes: 2 additions & 0 deletions multichain-testing/test/ica-channel-close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { makeQueryClient } from '../tools/query.js';
import { parseLocalAddress, parseRemoteAddress } from '../tools/address.js';
import chainInfo from '../starship-chain-info.js';
import { TWO_MINUTES } from './config.js';

const test = anyTest as TestFn<SetupContextWithWallets>;

Expand Down Expand Up @@ -182,6 +183,7 @@ const intentionalCloseAccountScenario = test.macro({
() => remoteQueryClient.queryChannels(),
({ channels }) => !!findNewChannel(channels, { rPortID, lPortID }),
`ICA channel is reopened on ${chainName} Host`,
TWO_MINUTES,
);
const newChannel = findNewChannel(channels, { rPortID, lPortID });
t.log('New Channel after Reactivate', newChannel);
Expand Down
73 changes: 54 additions & 19 deletions multichain-testing/tools/relayer-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,37 @@ import type { ExecSync } from './agd-lib.js';

const kubectlBinary = 'kubectl';

type RelayerType = 'hermes' | 'go-relayer';

// based on config.yaml
const relayerMap: { [key: string]: string } = {
osmosis: 'hermes-agoric-osmosis-0',
cosmoshub: 'hermes-agoric-gaia-0',
const chainRelayerConfig: { [key: string]: string } = {
osmosis: 'agoric-osmosis-0',
cosmoshub: 'agoric-gaia-0',
};

const getRelayerBinary = (relayer: RelayerType) => {
switch (relayer) {
case 'hermes':
return 'hermes';
case 'go-relayer':
return 'rly';
default:
throw new Error(`Unsupported relayer type: ${relayer}`);
}
};

const makeKubeArgs = (chainName: string) => {
if (!relayerMap[chainName]) throw Error('Unsupported chain: ' + chainName);
const makeKubeArgs = (chainName: string, relayerType: RelayerType) => {
if (!chainRelayerConfig[chainName])
throw Error('Unsupported chain: ' + chainName);
return [
'exec',
'-i',
relayerMap[chainName],
`${relayerType}-${chainRelayerConfig[chainName]}`,
'-c',
'relayer',
'--tty=false',
'--',
'hermes',
getRelayerBinary(relayerType),
];
};

Expand All @@ -38,29 +52,50 @@ type ChannelCloseParams = {
};

export const makeRelayer = ({ execFileSync }: { execFileSync: ExecSync }) => {
const relayerType = (process.env.RELAYER_TYPE || 'hermes') as RelayerType;

const exec = (
chainName: string,
args: string[],
opts = { encoding: 'utf-8' as const, stdio: ['ignore', 'pipe', 'ignore'] },
) => execFileSync(kubectlBinary, [...makeKubeArgs(chainName), ...args], opts);
) =>
execFileSync(
kubectlBinary,
[...makeKubeArgs(chainName, relayerType), ...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}`,
]);
let args: string[];
if (relayerType === 'hermes') {
args = [
'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}`,
];
} else if (relayerType === 'go-relayer') {
args = [
'tx',
'channel-close',
`${src.chainId}-${dst.chainId}`, // 'pathname'
src.channelID,
src.portID,
];
} else {
throw new Error(`Unsupported relayer type: ${relayerType}`);
}
return exec(chainName, args);
};

return {
Expand Down

0 comments on commit 8eaff81

Please sign in to comment.