Skip to content

Commit

Permalink
feat: getConnectionInfo by obj or string
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 19, 2024
1 parent e033ffe commit bfd5ed9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ export const prepareLocalOrchestrationAccountKit = (

const agoricChainInfo = await chainHub.getChainInfo('agoric');
const { transferChannel } = await chainHub.getConnectionInfo(
agoricChainInfo.chainId,
destination.chainId,
agoricChainInfo,
destination,
);

await null;
Expand Down
5 changes: 1 addition & 4 deletions packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export const startStakeAtom = async ({

const agoric = await chainHub.getChainInfo('agoric');
const cosmoshub = await chainHub.getChainInfo('cosmoshub');
const connectionInfo = await chainHub.getConnectionInfo(
agoric.chainId,
cosmoshub.chainId,
);
const connectionInfo = await chainHub.getConnectionInfo(agoric, cosmoshub);

/** @type {StartUpgradableOpts<StakeIcaSF>} */
const startOpts = {
Expand Down
8 changes: 5 additions & 3 deletions packages/orchestration/src/utils/chainHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ export const makeChainHub = (agoricNames, zone = makeHeapZone()) => {
},

/**
* @param {string} chainId1
* @param {string} chainId2
* @param {string | { chainId: string }} chain1
* @param {string | { chainId: string }} chain2
* @returns {Promise<IBCConnectionInfo>}
*/
async getConnectionInfo(chainId1, chainId2) {
async getConnectionInfo(chain1, chain2) {
const chainId1 = typeof chain1 === 'string' ? chain1 : chain1.chainId;
const chainId2 = typeof chain2 === 'string' ? chain2 : chain2.chainId;
const key = connectionKey(chainId1, chainId2);
if (connectionInfos.has(key)) {
return connectionInfos.get(key);
Expand Down
44 changes: 44 additions & 0 deletions packages/orchestration/test/utils/chainHub.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable @jessie.js/safe-await-separator -- XXX irrelevant for tests */
import test from '@endo/ses-ava/prepare-endo.js';

import { makeNameHubKit } from '@agoric/vats';
import { makeChainHub } from '../../src/utils/chainHub.js';

const connection = {
id: 'connection-1',
client_id: '07-tendermint-3',
counterparty: {
client_id: '07-tendermint-2',
connection_id: 'connection-1',
prefix: {
key_prefix: '',
},
},
state: 3 /* IBCConnectionState.STATE_OPEN */,
transferChannel: {
portId: 'transfer',
channelId: 'channel-1',
counterPartyChannelId: 'channel-1',
counterPartyPortId: 'transfer',
ordering: 1 /* Order.ORDER_UNORDERED */,
state: 3 /* IBCConnectionState.STATE_OPEN */,
version: 'ics20-1',
},
} as const;

test('getConnectionInfo', async t => {
const { nameHub } = makeNameHubKit();
const chainHub = makeChainHub(nameHub);

const aChain = { chainId: 'a-1' };
const bChain = { chainId: 'b-2' };

chainHub.registerConnection(aChain.chainId, bChain.chainId, connection);

// Look up by string or info object
t.deepEqual(
await chainHub.getConnectionInfo(aChain.chainId, bChain.chainId),
connection,
);
t.deepEqual(await chainHub.getConnectionInfo(aChain, bChain), connection);
});

0 comments on commit bfd5ed9

Please sign in to comment.