Skip to content

Commit 23ffdd5

Browse files
docs: ICA queries (#6068)
* docs for ica queries * indentation * lint * lint * review comment --------- Co-authored-by: Charly <[email protected]>
1 parent 8de42f0 commit 23ffdd5

File tree

4 files changed

+118
-3
lines changed

4 files changed

+118
-3
lines changed

docs/docs/02-apps/02-interchain-accounts/04-integration.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,16 @@ scopedICAAuthKeeper := app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleNam
8282
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
8383
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
8484
app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
85-
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
85+
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
8686
scopedICAControllerKeeper, app.MsgServiceRouter(),
87+
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
8788
)
8889
app.ICAHostKeeper = icahostkeeper.NewKeeper(
8990
appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName),
9091
app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
91-
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
92-
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
92+
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper,
93+
scopedICAHostKeeper, app.MsgServiceRouter(), app.GRPCQueryRouter(),
94+
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
9395
)
9496

9597
// Create Interchain Accounts AppModule

docs/docs/02-apps/02-interchain-accounts/05-messages.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ type MsgSendTxResponse struct {
7272

7373
The packet `Sequence` is returned in the message response.
7474

75+
### Queries
76+
77+
It is possible to use [`MsgModuleQuerySafe`](https://github.com/cosmos/ibc-go/blob/eecfa5c09a4c38a5c9f2cc2a322d2286f45911da/proto/ibc/applications/interchain_accounts/host/v1/tx.proto#L41-L51) to execute a list of queries on the host chain. This message can be included in the list of encoded `sdk.Msg`s of `InterchainPacketData`. The host chain will return on the acknowledgment the responses for all the queries. Please note that only module safe queries can be executed. The following code block shows an example of how this message can be used to query the account balance of an account on the host chain. The resulting packet data variable is used to set the `PacketData` of `MsgSendTx`.
78+
79+
```go
80+
balanceQuery := banktypes.NewQueryBalanceRequest("cosmos1...", "uatom")
81+
queryBz, err := balanceQuery.Marshal()
82+
83+
// signer of message must be the interchain account on the host
84+
queryMsg := icahosttypes.NewMsgModuleQuerySafe("cosmos2...", []*icahosttypes.QueryRequest{
85+
{
86+
Path: "/cosmos.bank.v1beta1.Query/Balance",
87+
Data: queryBz,
88+
},
89+
})
90+
91+
bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{queryMsg}, icatypes.EncodingProtobuf)
92+
93+
packetData := icatypes.InterchainAccountPacketData{
94+
Type: icatypes.EXECUTE_TX,
95+
Data: bz,
96+
Memo: "",
97+
}
98+
```
99+
75100
## Atomicity
76101

77102
As the Interchain Accounts module supports the execution of multiple transactions using the Cosmos SDK `Msg` interface, it provides the same atomicity guarantees as Cosmos SDK-based applications, leveraging the [`CacheMultiStore`](https://docs.cosmos.network/main/learn/advanced/store#cachemultistore) architecture provided by the [`Context`](https://docs.cosmos.network/main/learn/advanced/context.html) type.

docs/docs/05-migrations/13-v8-to-v9.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ Please use the new functions `path.Setup`, `path.SetupClients`, `path.SetupConne
4747
- Functions `ConstructUpdateTMClientHeader` and `ConstructUpdateTMClientHeaderWithTrustedHeight` of `TestChain` type have been replaced with `IBCClientHeader`. This function will construct a `07-tendermint` header to update the light client on the counterparty chain. The trusted height must be passed in as a non-zero height.
4848
- `GetValsAtHeight` has been renamed to `GetTrustedValidators`
4949

50+
### ICS27 - Interchain Accounts
51+
52+
In [#5785](https://github.com/cosmos/ibc-go/pull/5785) the list of arguments of the `NewKeeper` constructor function of the host submodule was extended with an extra argument for the gRPC query router that the submodule uses when executing a [`MsgModuleQuerySafe`](https://github.com/cosmos/ibc-go/blob/eecfa5c09a4c38a5c9f2cc2a322d2286f45911da/proto/ibc/applications/interchain_accounts/host/v1/tx.proto#L41-L51) to perform queries that are module safe:
53+
54+
```diff
55+
func NewKeeper(
56+
cdc codec.Codec, key storetypes.StoreKey, legacySubspace icatypes.ParamSubspace,
57+
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper,
58+
portKeeper icatypes.PortKeeper, accountKeeper icatypes.AccountKeeper,
59+
scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter,
60+
+ queryRouter icatypes.QueryRouter,
61+
authority string,
62+
) Keeper
63+
```
64+
5065
## Relayers
5166

5267
- Renaming of event attribute keys in [#5603](https://github.com/cosmos/ibc-go/pull/5603).

modules/apps/27-interchain-accounts/host/types/msgs_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
1212
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
13+
ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors"
1314
ibctesting "github.com/cosmos/ibc-go/v8/testing"
1415
)
1516

@@ -74,3 +75,75 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {
7475
}
7576
}
7677
}
78+
79+
func TestMsgModuleQuerySafeValidateBasic(t *testing.T) {
80+
queryRequest := &types.QueryRequest{
81+
Path: "/cosmos.bank.v1beta1.Query/Balance",
82+
Data: []byte{},
83+
}
84+
85+
testCases := []struct {
86+
name string
87+
msg *types.MsgModuleQuerySafe
88+
expErr error
89+
}{
90+
{
91+
"success: valid signer address",
92+
types.NewMsgModuleQuerySafe(sdk.AccAddress(ibctesting.TestAccAddress).String(), []*types.QueryRequest{queryRequest}),
93+
nil,
94+
},
95+
{
96+
"failure: invalid signer address",
97+
types.NewMsgModuleQuerySafe("signer", []*types.QueryRequest{queryRequest}),
98+
ibcerrors.ErrInvalidAddress,
99+
},
100+
{
101+
"failure: empty query requests",
102+
types.NewMsgModuleQuerySafe(sdk.AccAddress(ibctesting.TestAccAddress).String(), []*types.QueryRequest{}),
103+
ibcerrors.ErrInvalidRequest,
104+
},
105+
}
106+
107+
for _, tc := range testCases {
108+
tc := tc
109+
110+
t.Run(tc.name, func(t *testing.T) {
111+
err := tc.msg.ValidateBasic()
112+
113+
expPass := tc.expErr == nil
114+
if expPass {
115+
require.NoError(t, err)
116+
} else {
117+
require.Error(t, err)
118+
require.ErrorIs(t, err, tc.expErr)
119+
}
120+
})
121+
}
122+
}
123+
124+
func TestMsgModuleQuerySafeGetSigners(t *testing.T) {
125+
testCases := []struct {
126+
name string
127+
address sdk.AccAddress
128+
expPass bool
129+
}{
130+
{"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), true},
131+
{"failure: nil address", nil, false},
132+
}
133+
134+
for _, tc := range testCases {
135+
tc := tc
136+
137+
t.Run(tc.name, func(t *testing.T) {
138+
msg := types.NewMsgModuleQuerySafe(tc.address.String(), []*types.QueryRequest{})
139+
encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{})
140+
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
141+
if tc.expPass {
142+
require.NoError(t, err)
143+
require.Equal(t, tc.address.Bytes(), signers[0])
144+
} else {
145+
require.Error(t, err)
146+
}
147+
})
148+
}
149+
}

0 commit comments

Comments
 (0)