Skip to content

Commit

Permalink
imp: check order in validate basic of MsgRegisterInterchainAccount (#…
Browse files Browse the repository at this point in the history
…5671)

* imp: check order in validate basic of msg register interchain account

* fix conflicts
  • Loading branch information
crodriguezvega committed Jan 23, 2024
1 parent df198de commit 1c1f2fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions modules/apps/27-interchain-accounts/controller/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"slices"
"strings"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -41,6 +42,10 @@ func (msg MsgRegisterInterchainAccount) ValidateBasic() error {
return errorsmod.Wrap(err, "invalid connection ID")
}

if !slices.Contains([]channeltypes.Order{channeltypes.ORDERED, channeltypes.UNORDERED}, msg.Ordering) {
return errorsmod.Wrap(channeltypes.ErrInvalidChannelOrdering, msg.Ordering.String())
}

if strings.TrimSpace(msg.Owner) == "" {
return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "owner address cannot be empty")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
},
false,
},
{
"order is not valid",
func() {
msg.Ordering = channeltypes.NONE
},
false,
},
}

for i, tc := range testCases {
Expand Down
4 changes: 3 additions & 1 deletion modules/core/04-channel/types/channel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"slices"

errorsmod "cosmossdk.io/errors"

host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
Expand Down Expand Up @@ -68,7 +70,7 @@ func (ch Channel) ValidateBasic() error {
if ch.State == UNINITIALIZED {
return ErrInvalidChannelState
}
if !(ch.Ordering == ORDERED || ch.Ordering == UNORDERED) {
if !slices.Contains([]Order{ORDERED, UNORDERED}, ch.Ordering) {
return errorsmod.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String())
}
if len(ch.ConnectionHops) != 1 {
Expand Down

0 comments on commit 1c1f2fc

Please sign in to comment.