Skip to content

Commit bf062ad

Browse files
feat: added check for wildcard * to allow all message types (#1512) (#1537)
* added check for wildcard * to allow all message types * update docs * nit (cherry picked from commit 08d91ad) Co-authored-by: Charly <[email protected]>
1 parent 5d68351 commit bf062ad

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5858

5959
* (modules/core/02-client) [\#1336](https://github.com/cosmos/ibc-go/pull/1336) Adding Query/ConsensusStateHeights gRPC for fetching the height of every consensus state associated with a client.
6060
* (modules/apps/transfer) [\#1416](https://github.com/cosmos/ibc-go/pull/1416) Adding gRPC endpoint for getting an escrow account for a given port-id and channel-id.
61+
* (modules/apps/27-interchain-accounts) [\#1512](https://github.com/cosmos/ibc-go/pull/1512) Allowing ICA modules to handle all message types with "*".
6162

6263
### Bug Fixes
6364

docs/apps/interchain-accounts/parameters.md

+8
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ For example, a Cosmos SDK based chain that elects to provide hosted Interchain A
4747
"host_enabled": true,
4848
"allow_messages": ["/cosmos.staking.v1beta1.MsgDelegate", "/cosmos.gov.v1beta1.MsgVote"]
4949
}
50+
```
51+
There is also a special wildcard `"*"` message type which allows any type of message to be executed by the interchain account. This must be the only message in the `allow_messages` array.
52+
53+
```
54+
"params": {
55+
"host_enabled": true,
56+
"allow_messages": ["*"]
57+
}
5058
```

modules/apps/27-interchain-accounts/host/keeper/relay_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,45 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
2929
malleate func()
3030
expPass bool
3131
}{
32+
{
33+
"interchain account successfully executes an arbitrary message type using the * (allow all message types) param",
34+
func() {
35+
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
36+
suite.Require().True(found)
37+
38+
// Populate the gov keeper in advance with an active proposal
39+
testProposal := &govtypes.TextProposal{
40+
Title: "IBC Gov Proposal",
41+
Description: "tokens for all!",
42+
}
43+
44+
proposal, err := govtypes.NewProposal(testProposal, govtypes.DefaultStartingProposalID, time.Now(), time.Now().Add(time.Hour))
45+
suite.Require().NoError(err)
46+
47+
suite.chainB.GetSimApp().GovKeeper.SetProposal(suite.chainB.GetContext(), proposal)
48+
suite.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(suite.chainB.GetContext(), proposal)
49+
50+
msg := &govtypes.MsgVote{
51+
ProposalId: govtypes.DefaultStartingProposalID,
52+
Voter: interchainAccountAddr,
53+
Option: govtypes.OptionYes,
54+
}
55+
56+
data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []sdk.Msg{msg})
57+
suite.Require().NoError(err)
58+
59+
icaPacketData := icatypes.InterchainAccountPacketData{
60+
Type: icatypes.EXECUTE_TX,
61+
Data: data,
62+
}
63+
64+
packetData = icaPacketData.GetBytes()
65+
66+
params := types.NewParams(true, []string{"*"})
67+
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
68+
},
69+
true,
70+
},
3271
{
3372
"interchain account successfully executes banktypes.MsgSend",
3473
func() {

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

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const (
1414

1515
// ContainsMsgType returns true if the sdk.Msg TypeURL is present in allowMsgs, otherwise false
1616
func ContainsMsgType(allowMsgs []string, msg sdk.Msg) bool {
17+
// check that wildcard * option for allowing all message types is the only string in the array, if so, return true
18+
if len(allowMsgs) == 1 && allowMsgs[0] == "*" {
19+
return true
20+
}
21+
1722
for _, v := range allowMsgs {
1823
if v == sdk.MsgTypeURL(msg) {
1924
return true

0 commit comments

Comments
 (0)