Skip to content

Commit

Permalink
fix(orchestration): makeAccount never resolves when icqEnabled: false
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Jun 17, 2024
1 parent 5375019 commit a74b6a2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
2 changes: 2 additions & 0 deletions packages/builders/scripts/orchestration/init-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const defaultProposalBuilder = async (
hostConnectionId = 'connection-1',
controllerConnectionId = 'connection-0',
bondDenom = 'uatom',
icqEnabled = true,
} = options;
return harden({
sourceSpec: '@agoric/orchestration/src/proposals/start-stakeAtom.js',
Expand All @@ -23,6 +24,7 @@ export const defaultProposalBuilder = async (
hostConnectionId,
controllerConnectionId,
bondDenom,
icqEnabled,
},
],
});
Expand Down
22 changes: 14 additions & 8 deletions packages/orchestration/src/examples/stakeIca.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const meta = harden({
hostConnectionId: M.string(),
controllerConnectionId: M.string(),
bondDenom: M.string(),
icqEnabled: M.boolean(),
},
privateArgsShape: {
orchestration: M.remotable('orchestration'),
Expand All @@ -40,6 +41,7 @@ export const privateArgsShape = meta.privateArgsShape;
* hostConnectionId: IBCConnectionID;
* controllerConnectionId: IBCConnectionID;
* bondDenom: string;
* icqEnabled: boolean;
* }} StakeIcaTerms
*/

Expand All @@ -54,8 +56,13 @@ export const privateArgsShape = meta.privateArgsShape;
* @param {Baggage} baggage
*/
export const start = async (zcf, privateArgs, baggage) => {
const { chainId, hostConnectionId, controllerConnectionId, bondDenom } =
zcf.getTerms();
const {
chainId,
hostConnectionId,
controllerConnectionId,
bondDenom,
icqEnabled,
} = zcf.getTerms();
const { orchestration, marshaller, storageNode, timer } = privateArgs;

const zone = makeDurableZone(baggage);
Expand All @@ -74,12 +81,11 @@ export const start = async (zcf, privateArgs, baggage) => {
hostConnectionId,
controllerConnectionId,
);
// TODO https://github.com/Agoric/agoric-sdk/issues/9326
// Should not fail if host does not have `async-icq` module;
// communicate to OrchestrationAccount that it can't send queries
const icqConnection = await E(orchestration).provideICQConnection(
controllerConnectionId,
);
// TODO permissionless queries https://github.com/Agoric/agoric-sdk/issues/9326
const icqConnection = icqEnabled
? await E(orchestration).provideICQConnection(controllerConnectionId)
: undefined;

const accountAddress = await E(account).getAddress();
trace('account address', accountAddress);
const holder = makeCosmosOrchestrationAccount(accountAddress, bondDenom, {
Expand Down
5 changes: 3 additions & 2 deletions packages/orchestration/src/exos/cosmosOrchestrationAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const { Fail } = assert;
* topicKit: RecorderKit<ComosOrchestrationAccountNotification>;
* account: IcaAccount;
* chainAddress: ChainAddress;
* icqConnection: ICQConnection;
* icqConnection: ICQConnection | undefined;
* bondDenom: string;
* timer: Remote<TimerService>;
* }} State
Expand Down Expand Up @@ -149,7 +149,7 @@ export const prepareCosmosOrchestrationAccountKit = (
* @param {object} io
* @param {IcaAccount} io.account
* @param {Remote<StorageNode>} io.storageNode
* @param {ICQConnection} io.icqConnection
* @param {ICQConnection | undefined} io.icqConnection
* @param {Remote<TimerService>} io.timer
* @returns {State}
*/
Expand Down Expand Up @@ -363,6 +363,7 @@ export const prepareCosmosOrchestrationAccountKit = (
*/
async getBalance(denom) {
const { chainAddress, icqConnection } = this.state;
if (!icqConnection) throw Error('Queries not enabled.');
// TODO #9211 lookup denom from brand
assert.typeof(denom, 'string');

Expand Down
2 changes: 2 additions & 0 deletions packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const startStakeAtom = async ({
hostConnectionId: connectionInfo.id,
controllerConnectionId: connectionInfo.counterparty.connection_id,
bondDenom: cosmoshub.stakingTokens[0].denom,
// @ts-expect-error icqEnabled exists on CosmosChainInfo type
icqEnabled: !!cosmoshub.icqEnabled,
},
privateArgs: {
orchestration: await orchestration,
Expand Down
28 changes: 20 additions & 8 deletions packages/orchestration/test/examples/stake-atom.contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { AmountMath } from '@agoric/ertp';
import { setUpZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
import { E } from '@endo/far';
import path from 'path';
import type { Installation } from '@agoric/zoe/src/zoeService/utils.js';
import { commonSetup } from '../supports.js';
import { type StakeAtomTerms } from '../../src/examples/stakeAtom.contract.js';

const dirname = path.dirname(new URL(import.meta.url).pathname);

Expand All @@ -18,7 +18,13 @@ const startContract = async ({
timer,
marshaller,
storage,
bld,
issuerKeywordRecord,
terms = {
hostConnectionId: 'connection-1',
controllerConnectionId: 'connection-2',
bondDenom: 'uatom',
icqEnabled: false,
} as StakeAtomTerms,
}) => {
const { zoe, bundleAndInstall } = await setUpZoeForTest();
const installation: Installation<StartFn> =
Expand All @@ -43,26 +49,32 @@ const startContract = async ({
return { publicFacet, zoe };
};

test('makeAccount, deposit, withdraw', async t => {
test('makeAccount, getAddress, getBalances, getBalance', async t => {
const {
bootstrap,
brands: { ist },
utils,
} = await commonSetup(t);
const { publicFacet } = await startContract({ ...bootstrap, bld: ist });
const { publicFacet } = await startContract({
...bootstrap,
issuerKeywordRecord: { In: ist.issuer },
});

t.log('make an ICA account');
const account = await E(publicFacet).makeAccount();
t.truthy(account, 'account is returned');
const address = await E(account).getAddress();
// XXX address.address is weird
// t.regex(address.address, /agoric1/);
t.like(address, { chainId: 'cosmoshub-4', addressEncoding: 'bech32' });
const chainAddress = await E(account).getAddress();
// t.regex(address.address, /cosmos1/);
t.like(chainAddress, { chainId: 'cosmoshub-4', addressEncoding: 'bech32' });

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

await t.throwsAsync(E(account).getBalances(), {
message: 'not yet implemented',
});

await t.throwsAsync(E(account).getBalance('uatom'), {
message: 'Queries not enabled.',
});
});

0 comments on commit a74b6a2

Please sign in to comment.