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

chores: fix more connection tests #7664

Merged
merged 4 commits into from
Dec 11, 2024
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
42 changes: 22 additions & 20 deletions modules/core/03-connection/types/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)

Expand All @@ -24,43 +26,43 @@ func TestConnectionValidateBasic(t *testing.T) {
testCases := []struct {
name string
connection types.ConnectionEnd
expPass bool
expError error
}{
{
"valid connection",
types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, 500},
true,
nil,
},
{
"invalid client id",
types.ConnectionEnd{"(clientID1)", []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, 500},
false,
host.ErrInvalidID,
},
{
"empty versions",
types.ConnectionEnd{clientID, nil, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, 500},
false,
ibcerrors.ErrInvalidVersion,
},
{
"invalid version",
types.ConnectionEnd{clientID, []*types.Version{{}}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, 500},
false,
types.ErrInvalidVersion,
},
{
"invalid counterparty",
types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, emptyPrefix}, 500},
false,
types.ErrInvalidCounterparty,
},
}

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

err := tc.connection.ValidateBasic()
if tc.expPass {
if tc.expError == nil {
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)
require.ErrorIs(t, err, tc.expError)
}
}
}
Expand All @@ -69,22 +71,22 @@ func TestCounterpartyValidateBasic(t *testing.T) {
testCases := []struct {
name string
counterparty types.Counterparty
expPass bool
expError error
}{
{"valid counterparty", types.Counterparty{clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, true},
{"invalid client id", types.Counterparty{"(InvalidClient)", connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false},
{"invalid connection id", types.Counterparty{clientID, "(InvalidConnection)", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false},
{"invalid prefix", types.Counterparty{clientID, connectionID2, emptyPrefix}, false},
{"valid counterparty", types.Counterparty{clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, nil},
{"invalid client id", types.Counterparty{"(InvalidClient)", connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, host.ErrInvalidID},
{"invalid connection id", types.Counterparty{clientID, "(InvalidConnection)", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, host.ErrInvalidID},
{"invalid prefix", types.Counterparty{clientID, connectionID2, emptyPrefix}, types.ErrInvalidCounterparty},
}

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

err := tc.counterparty.ValidateBasic()
if tc.expPass {
if tc.expError == nil {
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)
require.ErrorIs(t, err, tc.expError)
}
}
}
Expand All @@ -93,28 +95,28 @@ func TestIdentifiedConnectionValidateBasic(t *testing.T) {
testCases := []struct {
name string
connection types.IdentifiedConnection
expPass bool
expError error
}{
{
"valid connection",
types.NewIdentifiedConnection(clientID, types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, 500}),
true,
nil,
},
{
"invalid connection id",
types.NewIdentifiedConnection("(connectionIDONE)", types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, 500}),
false,
host.ErrInvalidID,
},
}

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

err := tc.connection.ValidateBasic()
if tc.expPass {
if tc.expError == nil {
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)
require.ErrorIs(t, err, tc.expError)
}
}
}
26 changes: 14 additions & 12 deletions modules/core/03-connection/types/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package types_test

import (
"errors"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)
Expand All @@ -15,12 +17,12 @@ func TestValidateGenesis(t *testing.T) {
testCases := []struct {
name string
genState types.GenesisState
expPass bool
expError error
}{
{
name: "default",
genState: types.DefaultGenesisState(),
expPass: true,
expError: nil,
},
{
name: "valid genesis",
Expand All @@ -34,7 +36,7 @@ func TestValidateGenesis(t *testing.T) {
0,
types.DefaultParams(),
),
expPass: true,
expError: nil,
},
{
name: "invalid connection",
Expand All @@ -48,7 +50,7 @@ func TestValidateGenesis(t *testing.T) {
0,
types.DefaultParams(),
),
expPass: false,
expError: host.ErrInvalidID,
},
{
name: "invalid client id",
Expand All @@ -62,7 +64,7 @@ func TestValidateGenesis(t *testing.T) {
0,
types.DefaultParams(),
),
expPass: false,
expError: host.ErrInvalidID,
},
{
name: "invalid path",
Expand All @@ -76,7 +78,7 @@ func TestValidateGenesis(t *testing.T) {
0,
types.DefaultParams(),
),
expPass: false,
expError: host.ErrInvalidID,
},
{
name: "invalid connection identifier",
Expand All @@ -90,7 +92,7 @@ func TestValidateGenesis(t *testing.T) {
0,
types.DefaultParams(),
),
expPass: false,
expError: host.ErrInvalidID,
},
{
name: "localhost connection identifier",
Expand All @@ -104,7 +106,7 @@ func TestValidateGenesis(t *testing.T) {
0,
types.DefaultParams(),
),
expPass: true,
expError: nil,
},
{
name: "next connection sequence is not greater than maximum connection identifier sequence provided",
Expand All @@ -118,7 +120,7 @@ func TestValidateGenesis(t *testing.T) {
0,
types.DefaultParams(),
),
expPass: false,
expError: errors.New("next connection sequence 0 must be greater than maximum sequence used in connection identifier 10"),
},
{
name: "invalid params",
Expand All @@ -132,17 +134,17 @@ func TestValidateGenesis(t *testing.T) {
0,
types.Params{},
),
expPass: false,
expError: errors.New("MaxExpectedTimePerBlock cannot be zero"),
},
}

for _, tc := range testCases {
tc := tc
err := tc.genState.Validate()
if tc.expPass {
if tc.expError == nil {
require.NoError(t, err, tc.name)
} else {
require.Error(t, err, tc.name)
require.ErrorContains(t, err, tc.expError.Error())
}
}
}
Loading