Skip to content

Commit

Permalink
fix validate basic check (#7962)
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
colin-axner and fedekunze authored Nov 17, 2020
1 parent 715933b commit a7435d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/ibc/core/04-channel/types/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (ch Channel) GetVersion() string {

// ValidateBasic performs a basic validation of the channel fields
func (ch Channel) ValidateBasic() error {
if ch.State.String() == "" {
if ch.State == UNINITIALIZED {
return ErrInvalidChannelState
}
if !(ch.Ordering == ORDERED || ch.Ordering == UNORDERED) {
Expand Down
27 changes: 27 additions & 0 deletions x/ibc/core/04-channel/types/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
)

func TestChannelValidateBasic(t *testing.T) {
counterparty := types.Counterparty{"portidone", "channelidone"}
testCases := []struct {
name string
channel types.Channel
expPass bool
}{
{"valid channel", types.NewChannel(types.TRYOPEN, types.ORDERED, counterparty, connHops, version), true},
{"invalid state", types.NewChannel(types.UNINITIALIZED, types.ORDERED, counterparty, connHops, version), false},
{"invalid order", types.NewChannel(types.TRYOPEN, types.NONE, counterparty, connHops, version), false},
{"more than 1 connection hop", types.NewChannel(types.TRYOPEN, types.ORDERED, counterparty, []string{"connection1", "connection2"}, version), false},
{"invalid connection hop identifier", types.NewChannel(types.TRYOPEN, types.ORDERED, counterparty, []string{"(invalid)"}, version), false},
{"invalid counterparty", types.NewChannel(types.TRYOPEN, types.ORDERED, types.NewCounterparty("(invalidport)", "channelidone"), connHops, version), false},
}

for i, tc := range testCases {
tc := tc

err := tc.channel.ValidateBasic()
if tc.expPass {
require.NoError(t, err, "valid test case %d failed: %s", i, tc.name)
} else {
require.Error(t, err, "invalid test case %d passed: %s", i, tc.name)
}
}
}

func TestCounterpartyValidateBasic(t *testing.T) {
testCases := []struct {
name string
Expand Down

0 comments on commit a7435d0

Please sign in to comment.