Skip to content

Commit

Permalink
feat: added check for wildcard * to allow all message types (cosmos#1512
Browse files Browse the repository at this point in the history
) (cosmos#1537)

* added check for wildcard * to allow all message types

* update docs

* nit

(cherry picked from commit 08d91ad)

Co-authored-by: Charly <[email protected]>
  • Loading branch information
2 people authored and dudong2 committed Jan 19, 2023
1 parent cfef48a commit 4969ae9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/apps/interchain-accounts/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ For example, a Cosmos SDK based chain that elects to provide hosted Interchain A
"host_enabled": true,
"allow_messages": ["/cosmos.staking.v1beta1.MsgDelegate", "/cosmos.gov.v1beta1.MsgVote"]
}
```
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.

```
"params": {
"host_enabled": true,
"allow_messages": ["*"]
}
```
39 changes: 39 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,45 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
malleate func()
expPass bool
}{
{
"interchain account successfully executes an arbitrary message type using the * (allow all message types) param",
func() {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

// Populate the gov keeper in advance with an active proposal
testProposal := &govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}

proposal, err := govtypes.NewProposal(testProposal, govtypes.DefaultStartingProposalID, time.Now(), time.Now().Add(time.Hour))
suite.Require().NoError(err)

suite.chainB.GetSimApp().GovKeeper.SetProposal(suite.chainB.GetContext(), proposal)
suite.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(suite.chainB.GetContext(), proposal)

msg := &govtypes.MsgVote{
ProposalId: govtypes.DefaultStartingProposalID,
Voter: interchainAccountAddr,
Option: govtypes.OptionYes,
}

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []sdk.Msg{msg})
suite.Require().NoError(err)

icaPacketData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: data,
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{"*"})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
{
"interchain account successfully executes banktypes.MsgSend",
func() {
Expand Down
5 changes: 5 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const (

// ContainsMsgType returns true if the sdk.Msg TypeURL is present in allowMsgs, otherwise false
func ContainsMsgType(allowMsgs []string, msg sdk.Msg) bool {
// check that wildcard * option for allowing all message types is the only string in the array, if so, return true
if len(allowMsgs) == 1 && allowMsgs[0] == "*" {
return true
}

for _, v := range allowMsgs {
if v == sdk.MsgTypeURL(msg) {
return true
Expand Down

0 comments on commit 4969ae9

Please sign in to comment.