Skip to content

Commit

Permalink
fix: real chainId in chainAccountKit
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 12, 2024
1 parent d66276b commit 521dfd0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
5 changes: 4 additions & 1 deletion packages/boot/test/bootstrapTests/vat-orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ test('makeAccount returns an ICA connection', async t => {
await EV.vat('bootstrap').consumeItem('orchestration');

const account = await EV(orchestration).makeAccount(
'somechain-1',
'connection-0',
'connection-0',
);
Expand All @@ -95,7 +96,7 @@ test('makeAccount returns an ICA connection', async t => {
t.regex(remoteAddress, /icahost/);
t.regex(localAddress, /icacontroller/);
t.regex(chainAddress.address, /cosmos1/);
t.regex(chainAddress.chainId, /FIXME/); // TODO, use a real chainId #9063
t.is(chainAddress.chainId, 'somechain-1');
t.truthy(matches(port, M.remotable('Port')));
t.log('ICA Account Addresses', {
remoteAddress,
Expand All @@ -113,6 +114,7 @@ test('ICA connection can be closed', async t => {
await EV.vat('bootstrap').consumeItem('orchestration');

const account = await EV(orchestration).makeAccount(
'somechain-1',
'connection-0',
'connection-0',
);
Expand All @@ -134,6 +136,7 @@ test('ICA connection can send msg with proto3', async t => {
await EV.vat('bootstrap').consumeItem('orchestration');

const account = await EV(orchestration).makeAccount(
'somechain-1',
'connection-0',
'connection-0',
);
Expand Down
5 changes: 4 additions & 1 deletion packages/orchestration/src/examples/stakeIca.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const trace = makeTracer('StakeAtom');

export const meta = harden({
customTermsShape: {
chainId: M.string(),
hostConnectionId: M.string(),
controllerConnectionId: M.string(),
bondDenom: M.string(),
Expand All @@ -34,6 +35,7 @@ export const privateArgsShape = meta.privateArgsShape;

/**
* @typedef {{
* chainId: string;
* hostConnectionId: IBCConnectionID;
* controllerConnectionId: IBCConnectionID;
* bondDenom: string;
Expand All @@ -51,7 +53,7 @@ export const privateArgsShape = meta.privateArgsShape;
* @param {Baggage} baggage
*/
export const start = async (zcf, privateArgs, baggage) => {
const { hostConnectionId, controllerConnectionId, bondDenom } =
const { chainId, hostConnectionId, controllerConnectionId, bondDenom } =
zcf.getTerms();
const { orchestration, marshaller, storageNode, timer } = privateArgs;

Expand All @@ -67,6 +69,7 @@ export const start = async (zcf, privateArgs, baggage) => {

async function makeAccountKit() {
const account = await E(orchestration).makeAccount(
chainId,
hostConnectionId,
controllerConnectionId,
);
Expand Down
9 changes: 5 additions & 4 deletions packages/orchestration/src/exos/chainAccountKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const ChainAccountI = M.interface('ChainAccount', {

/**
* @typedef {{
* chainId: string;
* port: Port;
* connection: Remote<Connection> | undefined;
* localAddress: LocalIbcAddress | undefined;
Expand All @@ -60,11 +61,13 @@ export const prepareChainAccountKit = zone =>
'ChainAccountKit',
{ account: ChainAccountI, connectionHandler: ConnectionHandlerI },
/**
* @param {string} chainId
* @param {Port} port
* @param {string} requestedRemoteAddress
*/
(port, requestedRemoteAddress) =>
(chainId, port, requestedRemoteAddress) =>
/** @type {State} */ ({
chainId,
port,
connection: undefined,
requestedRemoteAddress,
Expand Down Expand Up @@ -158,9 +161,7 @@ export const prepareChainAccountKit = zone =>
this.state.localAddress = localAddr;
this.state.chainAddress = harden({
address: findAddressField(remoteAddr) || UNPARSABLE_CHAIN_ADDRESS,
// TODO get this from `Chain` object #9063
// XXX how do we get a chainId for an unknown chain? seems it may need to be a user supplied arg
chainId: 'FIXME',
chainId: this.state.chainId,
addressEncoding: 'bech32',
});
},
Expand Down
1 change: 1 addition & 0 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const makeRemoteChainFacade = (
/** @returns {Promise<OrchestrationAccount<CCI>>} */
makeAccount: async () => {
const icaAccount = await E(orchestration).makeAccount(
chainInfo.chainId,
// XXX IBCConnectionInfo concessions for JSON encoding
/** @type {IBCConnectionID} */ (connectionInfo.id),
/** @type {IBCConnectionID} */ (
Expand Down
6 changes: 4 additions & 2 deletions packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ export const startStakeAtom = async ({

const chainHub = makeChainHub(await agoricNames);

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

/** @type {StartUpgradableOpts<StakeAtomSF>} */
Expand All @@ -60,6 +61,7 @@ export const startStakeAtom = async ({
installation: stakeIca,
issuerKeywordRecord: harden({ ATOM: atomIssuer }),
terms: {
chainId: cosmoshub.chainId,
hostConnectionId: /** @type {IBCConnectionID} */ (connectionInfo.id),
controllerConnectionId: /** @type {IBCConnectionID} */ (
connectionInfo.counterparty.connection_id
Expand Down
11 changes: 8 additions & 3 deletions packages/orchestration/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const getPower = (powers, name) => {
};

export const OrchestrationI = M.interface('Orchestration', {
makeAccount: M.callWhen(M.string(), M.string()).returns(
makeAccount: M.callWhen(M.string(), M.string(), M.string()).returns(
M.remotable('ChainAccount'),
),
provideICQConnection: M.callWhen(M.string()).returns(
Expand Down Expand Up @@ -109,19 +109,24 @@ const prepareOrchestrationKit = (
},
public: {
/**
* @param {string} chainId
* @param {IBCConnectionID} hostConnectionId the counterparty
* connection_id
* @param {IBCConnectionID} controllerConnectionId self connection_id
* @returns {Promise<IcaAccount>}
*/
async makeAccount(hostConnectionId, controllerConnectionId) {
async makeAccount(chainId, hostConnectionId, controllerConnectionId) {
const port = await this.facets.self.allocateICAControllerPort();

const remoteConnAddr = makeICAChannelAddress(
hostConnectionId,
controllerConnectionId,
);
const chainAccountKit = makeChainAccountKit(port, remoteConnAddr);
const chainAccountKit = makeChainAccountKit(
chainId,
port,
remoteConnAddr,
);

// await so we do not return a ChainAccount before it successfully instantiates
await E(port).connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const startContract = async ({
installation,
{ In: bld.issuer },
{
chainId: 'cosmoshub-4',
hostConnectionId: 'connection-1',
controllerConnectionId: 'connection-2',
bondDenom: 'uatom',
Expand Down Expand Up @@ -56,7 +57,7 @@ test('makeAccount, deposit, withdraw', async t => {
const address = await E(account).getAddress();
// XXX address.address is weird
// t.regex(address.address, /agoric1/);
t.like(address, { chainId: 'FIXME', addressEncoding: 'bech32' });
t.like(address, { chainId: 'cosmoshub-4', addressEncoding: 'bech32' });

t.log('deposit 100 bld to account');
await E(account).deposit(await utils.pourPayment(ist.units(100)));
Expand Down

0 comments on commit 521dfd0

Please sign in to comment.