Skip to content

Commit

Permalink
feat(cosmos-orch-account): expose .executeEncodedTx
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Nov 13, 2024
1 parent ff9b882 commit 9d10be1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/orchestration/src/exos/cosmos-orchestration-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
DelegationShape,
DenomAmountShape,
IBCTransferOptionsShape,
Proto3Shape,
TxBodyOptsShape,
} from '../typeGuards.js';
import { coerceCoin, coerceDenom } from '../utils/amounts.js';
import {
Expand Down Expand Up @@ -143,6 +145,9 @@ export const IcaAccountHolderI = M.interface('IcaAccountHolder', {
...stakingAccountQueriesMethods,
deactivate: M.call().returns(VowShape),
reactivate: M.call().returns(VowShape),
executeEncodedTx: M.call(M.arrayOf(Proto3Shape))
.optional(TxBodyOptsShape)
.returns(VowShape),
});

/** @type {{ [name: string]: [description: string, valueShape: Matcher] }} */
Expand Down Expand Up @@ -1093,6 +1098,12 @@ export const prepareCosmosOrchestrationAccountKit = (
return watch(results, this.facets.rewardsQueryWatcher);
});
},
/** @type {HostOf<IcaAccount['executeEncodedTx']>} */
executeEncodedTx(msgs, opts) {
return watch(
E(this.facets.helper.owned()).executeEncodedTx(msgs, opts),
);
},
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import {
QueryDelegationRewardsResponse,
QueryDelegationTotalRewardsResponse,
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/query.js';
import { Any } from '@agoric/cosmic-proto/google/protobuf/any.js';
import {
MsgDelegate,
MsgDelegateResponse,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
import { decodeBase64 } from '@endo/base64';
import { commonSetup } from '../supports.js';
import type {
AmountArg,
Expand All @@ -48,6 +54,7 @@ import {
parseOutgoingTxPacket,
} from '../../tools/ibc-mocks.js';
import type { CosmosValidatorAddress } from '../../src/cosmos-api.js';
import { protoMsgMocks } from '../ibc-mocks.js';

type TestContext = Awaited<ReturnType<typeof commonSetup>>;

Expand Down Expand Up @@ -816,3 +823,38 @@ test('not yet implemented', async t => {
message: 'Not Implemented. Try using withdrawReward.',
});
});

test('executeEncodedTx', async t => {
const makeTestCOAKit = prepareMakeTestCOAKit(t, t.context);
const account = await makeTestCOAKit();

const delegateMsgSuccess = Any.toJSON(
MsgDelegate.toProtoMsg({
delegatorAddress: 'cosmos1test',
validatorAddress: 'cosmosvaloper1test',
amount: { denom: 'uatom', amount: '10' },
}),
);

const res = await E(account).executeEncodedTx([delegateMsgSuccess]);
t.is(
res,
'Ei0KKy9jb3Ntb3Muc3Rha2luZy52MWJldGExLk1zZ0RlbGVnYXRlUmVzcG9uc2U=', // cosmos.staking.v1beta1.MsgDelegateResponse
'delegateMsgSuccess',
);
const decodedRes = MsgDelegateResponse.decode(decodeBase64(res));
t.deepEqual(decodedRes, {}, 'MsgDelegate returns MsgDelegateResponse');

t.context.mocks.ibcBridge.addMockAck(
// Delegate 100 ubld from cosmos1test to cosmosvaloper1test observed in console, timeoutHeight: 6n
'eyJ0eXBlIjoxLCJkYXRhIjoiQ2xVS0l5OWpiM050YjNNdWMzUmhhMmx1Wnk1Mk1XSmxkR0V4TGsxelowUmxiR1ZuWVhSbEVpNEtDMk52YzIxdmN6RjBaWE4wRWhKamIzTnRiM04yWVd4dmNHVnlNWFJsYzNRYUN3b0ZkV0YwYjIwU0FqRXdHQVk9IiwibWVtbyI6IiJ9',
protoMsgMocks.delegate.ack,
);
t.is(
await E(account).executeEncodedTx([delegateMsgSuccess], {
timeoutHeight: 6n,
}),
'Ei0KKy9jb3Ntb3Muc3Rha2luZy52MWJldGExLk1zZ0RlbGVnYXRlUmVzcG9uc2U=', // cosmos.staking.v1beta1.MsgDelegateResponse
'delegateMsgSuccess',
);
});

0 comments on commit 9d10be1

Please sign in to comment.