Skip to content

Commit

Permalink
fixup! refactor(orchestration): consistent naming for validator address
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed May 3, 2024
1 parent 0090372 commit cb1a005
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 45 deletions.
8 changes: 4 additions & 4 deletions packages/boot/tools/ibc/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ export const protoMsgMocks = {
},
// QueryBalanceRequest (/cosmos.bank.v1beta1.Query/Balance) of uatom for cosmos1test
queryBalance: {
msg: 'eyJ0eXBlIjoxLCJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWaGRHOXRFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmwiLCJtZW1vIjoiIn0=',
msg: 'eyJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWaGRHOXRFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmwiLCJtZW1vIjoiIn0=',
ack: responses.queryBalance,
},
// QueryBalanceRequest of uatom for cosmos1test, repeated twice
queryBalanceMulti: {
msg: 'eyJ0eXBlIjoxLCJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWaGRHOXRFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmxDam9LRkFvTFkyOXpiVzl6TVhSbGMzUVNCWFZoZEc5dEVpSXZZMjl6Ylc5ekxtSmhibXN1ZGpGaVpYUmhNUzVSZFdWeWVTOUNZV3hoYm1ObCIsIm1lbW8iOiIifQ==',
msg: 'eyJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWaGRHOXRFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmxDam9LRkFvTFkyOXpiVzl6TVhSbGMzUVNCWFZoZEc5dEVpSXZZMjl6Ylc5ekxtSmhibXN1ZGpGaVpYUmhNUzVSZFdWeWVTOUNZV3hoYm1ObCIsIm1lbW8iOiIifQ==',
ack: responses.queryBalanceMulti,
},
// QueryBalanceRequest of 'some-invalid-denom' for cosmos1test
queryBalanceUnknownDenom: {
msg: 'eyJ0eXBlIjoxLCJkYXRhIjoiQ2tjS0lRb0xZMjl6Ylc5ek1YUmxjM1FTRW5OdmJXVXRhVzUyWVd4cFpDMWtaVzV2YlJJaUwyTnZjMjF2Y3k1aVlXNXJMbll4WW1WMFlURXVVWFZsY25rdlFtRnNZVzVqWlE9PSIsIm1lbW8iOiIifQ==',
msg: 'eyJkYXRhIjoiQ2tjS0lRb0xZMjl6Ylc5ek1YUmxjM1FTRW5OdmJXVXRhVzUyWVd4cFpDMWtaVzV2YlJJaUwyTnZjMjF2Y3k1aVlXNXJMbll4WW1WMFlURXVVWFZsY25rdlFtRnNZVzVqWlE9PSIsIm1lbW8iOiIifQ==',
ack: responses.queryBalanceUnknownDenom,
},
// Query for /cosmos.bank.v1beta1.QueryBalanceRequest
queryUnknownPath: {
msg: 'eyJ0eXBlIjoxLCJkYXRhIjoiQ2tBS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWaGRHOXRFaWd2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllVUpoYkdGdVkyVlNaWEYxWlhOMCIsIm1lbW8iOiIifQ==',
msg: 'eyJkYXRhIjoiQ2tBS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWaGRHOXRFaWd2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllVUpoYkdGdVkyVlNaWEYxWlhOMCIsIm1lbW8iOiIifQ==',
ack: responses.error4,
},
// MsgDelegate 10uatom from cosmos1test to cosmosvaloper1test with memo: 'TESTING' and timeoutHeight: 1_000_000_000n
Expand Down
14 changes: 9 additions & 5 deletions packages/cosmic-proto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@
"types": "./dist/codegen/ibc/*.d.ts",
"default": "./dist/codegen/ibc/*.js"
},
"./icq/v1/*.js": {
"types": "./dist/codegen/icq/v1/*.d.ts",
"./ibc/applications/interchain_accounts/v1/packet.js": {
"types": "./dist/codegen/ibc/applications/interchain_accounts/v1/packet.d.ts",
"default": "./dist/codegen/ibc/applications/interchain_accounts/v1/packet.js"
},
"./icq/*.js": {
"types": "./dist/codegen/icq/*.d.ts",
"default": "./dist/codegen/icq/v1/*.js"
},
"./icq/v1/packet.js": {
Expand All @@ -76,9 +80,9 @@
"types": "./dist/codegen/agoric/swingset/swingset.d.ts",
"default": "./dist/codegen/agoric/swingset/swingset.js"
},
"./tendermint/abci/*.js": {
"types": "./dist/codegen/tendermint/abci/*.d.ts",
"default": "./dist/codegen/tendermint/abci/*.js"
"./tendermint/*.js": {
"types": "./dist/codegen/tendermint/*.d.ts",
"default": "./dist/codegen/tendermint/*.js"
},
"./tendermint/abci/types.js": {
"types": "./dist/codegen/tendermint/abci/types.d.ts",
Expand Down
22 changes: 12 additions & 10 deletions packages/orchestration/src/exos/chainAccountKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ export const ChainAccountI = M.interface('ChainAccount', {
prepareTransfer: M.callWhen().returns(InvitationShape),
});

/**
* @typedef {{
* port: Port;
* connection: Remote<Connection> | undefined;
* localAddress: LocalIbcAddress | undefined;
* requestedRemoteAddress: string;
* remoteAddress: RemoteIbcAddress | undefined;
* chainAddress: ChainAddress | undefined;
* }} State
*/

/** @param {Zone} zone */
export const prepareChainAccountKit = zone =>
zone.exoClassKit(
Expand All @@ -59,16 +70,7 @@ export const prepareChainAccountKit = zone =>
* @param {string} requestedRemoteAddress
*/
(port, requestedRemoteAddress) =>
/**
* @type {{
* port: Port;
* connection: Remote<Connection> | undefined;
* localAddress: LocalIbcAddress | undefined;
* requestedRemoteAddress: string;
* remoteAddress: RemoteIbcAddress | undefined;
* chainAddress: ChainAddress | undefined;
* }}
*/ (
/** @type {State} */ (
harden({
port,
connection: undefined,
Expand Down
18 changes: 10 additions & 8 deletions packages/orchestration/src/exos/icqConnectionKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export const ICQConnectionI = M.interface('ICQConnection', {
query: M.call(M.arrayOf(ICQMsgShape)).returns(M.promise()),
});

/**
* @typedef {{
* port: Port;
* connection: Remote<Connection> | undefined;
* localAddress: LocalIbcAddress | undefined;
* remoteAddress: RemoteIbcAddress | undefined;
* }} State
*/

/** @param {Zone} zone */
export const prepareICQConnectionKit = zone =>
zone.exoClassKit(
Expand All @@ -39,14 +48,7 @@ export const prepareICQConnectionKit = zone =>
* @param {Port} port
*/
port =>
/**
* @type {{
* port: Port;
* connection: Remote<Connection> | undefined;
* localAddress: LocalIbcAddress | undefined;
* remoteAddress: RemoteIbcAddress | undefined;
* }}
*/ (
/** @type {State} */ (
harden({
port,
connection: undefined,
Expand Down
4 changes: 3 additions & 1 deletion packages/orchestration/src/exos/stakingAccountKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const BalanceShape = { amount: M.string(), denom: M.string() };

export const ChainAccountHolderI = M.interface('ChainAccountHolder', {
getPublicTopics: M.call().returns(TopicsRecordShape),
makeDelegateInvitation: M.call(M.string(), AmountShape).returns(M.promise()),
makeDelegateInvitation: M.call(ChainAddressShape, AmountShape).returns(
M.promise(),
),
makeCloseAccountInvitation: M.call().returns(M.promise()),
makeTransferAccountInvitation: M.call().returns(M.promise()),
delegate: M.callWhen(ChainAddressShape, AmountShape).returns(M.string()),
Expand Down
4 changes: 2 additions & 2 deletions packages/orchestration/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export const OrchestrationI = M.interface('Orchestration', {

/**
* @param {Zone} zone
* @param {ReturnType<prepareChainAccountKit>} makeChainAccountKit
* @param {ReturnType<prepareICQConnectionKit>} makeICQConnectionKit
* @param {ReturnType<typeof prepareChainAccountKit>} makeChainAccountKit
* @param {ReturnType<typeof prepareICQConnectionKit>} makeICQConnectionKit
*/
const prepareOrchestrationKit = (
zone,
Expand Down
34 changes: 20 additions & 14 deletions packages/orchestration/src/utils/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import {
CosmosQuery,
CosmosResponse,
} from '@agoric/cosmic-proto/icq/v1/packet.js';
import { Type as PacketType } from '@agoric/cosmic-proto/ibc/applications/interchain_accounts/v1/packet.js';

/**
* @import { AnyJson, RequestQueryJson, Base64Any } from '@agoric/cosmic-proto';
* @import { ResponseQuery } from '@agoric/cosmic-proto/tendermint/abci/types.js';
* @import {AnyJson, RequestQueryJson, Base64Any} from '@agoric/cosmic-proto';
* @import {ResponseQuery} from '@agoric/cosmic-proto/tendermint/abci/types.js';
* @import {InterchainAccountPacketData} from '@agoric/cosmic-proto/ibc/applications/interchain_accounts/v1/packet.js';
* @import {InterchainQueryPacketData} from '@agoric/cosmic-proto/icq/v1/packet.js';
*/

/**
Expand All @@ -19,7 +22,7 @@ import {
* Skips checks for malformed messages in favor of interface guards.
* @param {AnyJson[]} msgs
* @param {Partial<Omit<TxBody, 'messages'>>} [opts]
* @returns {string} - IBC TX packet
* @returns {string} stringified InterchainAccountPacketData
* @throws {Error} if malformed messages are provided
*/
export function makeTxPacket(msgs, opts) {
Expand All @@ -31,11 +34,13 @@ export function makeTxPacket(msgs, opts) {
}),
).finish();

return JSON.stringify({
type: 1,
data: encodeBase64(bytes),
memo: '',
});
return JSON.stringify(
/** @type {Base64Any<InterchainAccountPacketData>} */ ({
type: PacketType.TYPE_EXECUTE_TX,
data: encodeBase64(bytes),
memo: '',
}),
);
}
harden(makeTxPacket);

Expand All @@ -44,7 +49,7 @@ harden(makeTxPacket);
* to be base64 encoded bytes.
* Skips checks for malformed messages in favor of interface guards.
* @param {RequestQueryJson[]} msgs
* @returns {string} - IBC Query packet
* @returns {string} stringified InterchainQueryPacketData
* @throws {Error} if malformed messages are provided
*/
export function makeQueryPacket(msgs) {
Expand All @@ -54,11 +59,12 @@ export function makeQueryPacket(msgs) {
}),
).finish();

return JSON.stringify({
type: 1,
data: encodeBase64(bytes),
memo: '',
});
return JSON.stringify(
/** @type {Base64Any<InterchainQueryPacketData>} */ ({
data: encodeBase64(bytes),
memo: '',
}),
);
}
harden(makeQueryPacket);

Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/test/utils/packet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ test('makeQueryPacket', t => {
);
t.is(
makeQueryPacket([mockQuery]),
'{"type":1,"data":"CjoKFAoLY29zbW9zMXRlc3QSBXVhdG9tEiIvY29zbW9zLmJhbmsudjFiZXRhMS5RdWVyeS9CYWxhbmNl","memo":""}',
'{"data":"CjoKFAoLY29zbW9zMXRlc3QSBXVhdG9tEiIvY29zbW9zLmJhbmsudjFiZXRhMS5RdWVyeS9CYWxhbmNl","memo":""}',
'makes a query packet from messages',
);
const requiredFields = {
Expand Down

0 comments on commit cb1a005

Please sign in to comment.