Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp: check order in validate basic of MsgRegisterInterchainAccount #5671

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty to make this small improvement.

return errorsmod.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String())
}
if len(ch.ConnectionHops) != 1 {
Expand Down
Loading