Skip to content

Commit

Permalink
Merge branch 'main' into marko/gomod_change
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Dec 12, 2024
2 parents 1af3870 + 951a148 commit 8ea3954
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
{
"connection not found",
func() {
channel.ConnectionHops = []string{"invalid-connnection-id"}
channel.ConnectionHops = []string{"invalid-connection-id"}
path.EndpointA.SetChannel(*channel)
},
connectiontypes.ErrConnectionNotFound,
Expand All @@ -186,7 +186,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
{
"invalid controller connection ID",
func() {
metadata.ControllerConnectionId = "invalid-connnection-id"
metadata.ControllerConnectionId = "invalid-connection-id"

versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
Expand All @@ -199,7 +199,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
{
"invalid host connection ID",
func() {
metadata.HostConnectionId = "invalid-connnection-id"
metadata.HostConnectionId = "invalid-connection-id"

versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
{
"connection not found",
func() {
channel.ConnectionHops = []string{"invalid-connnection-id"}
channel.ConnectionHops = []string{"invalid-connection-id"}
path.EndpointB.SetChannel(*channel)
},
connectiontypes.ErrConnectionNotFound,
Expand Down Expand Up @@ -220,7 +220,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
{
"invalid controller connection ID",
func() {
metadata.ControllerConnectionId = "invalid-connnection-id"
metadata.ControllerConnectionId = "invalid-connection-id"

versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)
Expand Down
23 changes: 12 additions & 11 deletions modules/core/03-connection/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -15,39 +16,39 @@ import (

func TestCodecTypeRegistration(t *testing.T) {
testCases := []struct {
name string
typeURL string
expPass bool
name string
typeURL string
expError error
}{
{
"success: MsgConnectionOpenInit",
sdk.MsgTypeURL(&types.MsgConnectionOpenInit{}),
true,
nil,
},
{
"success: MsgConnectionOpenTry",
sdk.MsgTypeURL(&types.MsgConnectionOpenTry{}),
true,
nil,
},
{
"success: MsgConnectionOpenAck",
sdk.MsgTypeURL(&types.MsgConnectionOpenAck{}),
true,
nil,
},
{
"success: MsgConnectionOpenConfirm",
sdk.MsgTypeURL(&types.MsgConnectionOpenConfirm{}),
true,
nil,
},
{
"success: MsgUpdateParams",
sdk.MsgTypeURL(&types.MsgUpdateParams{}),
true,
nil,
},
{
"type not registered on codec",
"ibc.invalid.MsgTypeURL",
false,
fmt.Errorf("unable to resolve type URL ibc.invalid.MsgTypeURL"),
},
}

Expand All @@ -58,12 +59,12 @@ func TestCodecTypeRegistration(t *testing.T) {
encodingCfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, ibc.AppModule{})
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL)

if tc.expPass {
if tc.expError == nil {
require.NotNil(t, msg)
require.NoError(t, err)
} else {
require.Nil(t, msg)
require.Error(t, err)
require.ErrorContains(t, err, tc.expError.Error())
}
})
}
Expand Down
30 changes: 16 additions & 14 deletions modules/core/03-connection/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package types_test

import (
"errors"
"math"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
)

// tests ParseConnectionSequence and IsValidConnectionID
Expand All @@ -15,21 +17,21 @@ func TestParseConnectionSequence(t *testing.T) {
name string
connectionID string
expSeq uint64
expPass bool
expError error
}{
{"valid 0", "connection-0", 0, true},
{"valid 1", "connection-1", 1, true},
{"valid large sequence", types.FormatConnectionIdentifier(math.MaxUint64), math.MaxUint64, true},
{"valid 0", "connection-0", 0, nil},
{"valid 1", "connection-1", 1, nil},
{"valid large sequence", types.FormatConnectionIdentifier(math.MaxUint64), math.MaxUint64, nil},
// one above uint64 max
{"invalid uint64", "connection-18446744073709551616", 0, false},
{"invalid uint64", "connection-18446744073709551616", 0, errors.New("invalid connection identifier: failed to parse identifier sequence")},
// uint64 == 20 characters
{"invalid large sequence", "connection-2345682193567182931243", 0, false},
{"capital prefix", "Connection-0", 0, false},
{"double prefix", "connection-connection-0", 0, false},
{"missing dash", "connection0", 0, false},
{"blank id", " ", 0, false},
{"empty id", "", 0, false},
{"negative sequence", "connection--1", 0, false},
{"invalid large sequence", "connection-2345682193567182931243", 0, host.ErrInvalidID},
{"capital prefix", "Connection-0", 0, host.ErrInvalidID},
{"double prefix", "connection-connection-0", 0, host.ErrInvalidID},
{"missing dash", "connection0", 0, host.ErrInvalidID},
{"blank id", " ", 0, host.ErrInvalidID},
{"empty id", "", 0, host.ErrInvalidID},
{"negative sequence", "connection--1", 0, host.ErrInvalidID},
}

for _, tc := range testCases {
Expand All @@ -40,11 +42,11 @@ func TestParseConnectionSequence(t *testing.T) {
valid := types.IsValidConnectionID(tc.connectionID)
require.Equal(t, tc.expSeq, seq)

if tc.expPass {
if tc.expError == nil {
require.NoError(t, err, tc.name)
require.True(t, valid)
} else {
require.Error(t, err, tc.name)
require.ErrorContains(t, err, tc.expError.Error())
require.False(t, valid)
}
})
Expand Down
52 changes: 26 additions & 26 deletions modules/core/03-connection/types/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import (

func TestValidateVersion(t *testing.T) {
testCases := []struct {
name string
version *types.Version
expPass bool
name string
version *types.Version
expError error
}{
{"valid version", types.DefaultIBCVersion, true},
{"valid empty feature set", types.NewVersion(types.DefaultIBCVersionIdentifier, []string{}), true},
{"empty version identifier", types.NewVersion(" ", []string{"ORDER_UNORDERED"}), false},
{"empty feature", types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_UNORDERED", " "}), false},
{"valid version", types.DefaultIBCVersion, nil},
{"valid empty feature set", types.NewVersion(types.DefaultIBCVersionIdentifier, []string{}), nil},
{"empty version identifier", types.NewVersion(" ", []string{"ORDER_UNORDERED"}), types.ErrInvalidVersion},
{"empty feature", types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_UNORDERED", " "}), types.ErrInvalidVersion},
}

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

err := types.ValidateVersion(tc.version)

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 Down Expand Up @@ -100,25 +100,25 @@ func TestPickVersion(t *testing.T) {
supportedVersions []*types.Version
counterpartyVersions []*types.Version
expVer *types.Version
expPass bool
expError error
}{
{"valid default ibc version", types.GetCompatibleVersions(), types.GetCompatibleVersions(), types.DefaultIBCVersion, true},
{"valid version in counterparty versions", types.GetCompatibleVersions(), []*types.Version{types.NewVersion("version1", nil), types.NewVersion("2.0.0", []string{"ORDER_UNORDERED-ZK"}), types.DefaultIBCVersion}, types.DefaultIBCVersion, true},
{"valid identifier match but empty feature set not allowed", types.GetCompatibleVersions(), []*types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"DAG", "ORDERED-ZK", "UNORDERED-zk]"})}, types.NewVersion(types.DefaultIBCVersionIdentifier, nil), false},
{"empty counterparty versions", types.GetCompatibleVersions(), []*types.Version{}, &types.Version{}, false},
{"non-matching counterparty versions", types.GetCompatibleVersions(), []*types.Version{types.NewVersion("2.0.0", nil)}, &types.Version{}, false},
{"non-matching counterparty versions (uses ordered channels only) contained in supported versions (uses unordered channels only)", []*types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_UNORDERED"})}, []*types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED"})}, &types.Version{}, false},
{"valid default ibc version", types.GetCompatibleVersions(), types.GetCompatibleVersions(), types.DefaultIBCVersion, nil},
{"valid version in counterparty versions", types.GetCompatibleVersions(), []*types.Version{types.NewVersion("version1", nil), types.NewVersion("2.0.0", []string{"ORDER_UNORDERED-ZK"}), types.DefaultIBCVersion}, types.DefaultIBCVersion, nil},
{"valid identifier match but empty feature set not allowed", types.GetCompatibleVersions(), []*types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"DAG", "ORDERED-ZK", "UNORDERED-zk]"})}, types.NewVersion(types.DefaultIBCVersionIdentifier, nil), types.ErrVersionNegotiationFailed},
{"empty counterparty versions", types.GetCompatibleVersions(), []*types.Version{}, &types.Version{}, types.ErrVersionNegotiationFailed},
{"non-matching counterparty versions", types.GetCompatibleVersions(), []*types.Version{types.NewVersion("2.0.0", nil)}, &types.Version{}, types.ErrVersionNegotiationFailed},
{"non-matching counterparty versions (uses ordered channels only) contained in supported versions (uses unordered channels only)", []*types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_UNORDERED"})}, []*types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED"})}, &types.Version{}, types.ErrVersionNegotiationFailed},
}

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

version, err := types.PickVersion(tc.supportedVersions, tc.counterpartyVersions)

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)
var emptyVersion *types.Version
require.Equal(t, emptyVersion, version, "invalid test case %d passed: %s", i, tc.name)
}
Expand All @@ -130,24 +130,24 @@ func TestVerifyProposedVersion(t *testing.T) {
name string
proposedVersion *types.Version
supportedVersion *types.Version
expPass bool
expError error
}{
{"entire feature set supported", types.DefaultIBCVersion, types.NewVersion("1", []string{"ORDER_ORDERED", "ORDER_UNORDERED", "ORDER_DAG"}), true},
{"empty feature sets not supported", types.NewVersion("1", []string{}), types.DefaultIBCVersion, false},
{"one feature missing", types.DefaultIBCVersion, types.NewVersion("1", []string{"ORDER_UNORDERED", "ORDER_DAG"}), false},
{"both features missing", types.DefaultIBCVersion, types.NewVersion("1", []string{"ORDER_DAG"}), false},
{"identifiers do not match", types.NewVersion("2", []string{"ORDER_UNORDERED", "ORDER_ORDERED"}), types.DefaultIBCVersion, false},
{"entire feature set supported", types.DefaultIBCVersion, types.NewVersion("1", []string{"ORDER_ORDERED", "ORDER_UNORDERED", "ORDER_DAG"}), nil},
{"empty feature sets not supported", types.NewVersion("1", []string{}), types.DefaultIBCVersion, types.ErrVersionNegotiationFailed},
{"one feature missing", types.DefaultIBCVersion, types.NewVersion("1", []string{"ORDER_UNORDERED", "ORDER_DAG"}), types.ErrVersionNegotiationFailed},
{"both features missing", types.DefaultIBCVersion, types.NewVersion("1", []string{"ORDER_DAG"}), types.ErrVersionNegotiationFailed},
{"identifiers do not match", types.NewVersion("2", []string{"ORDER_UNORDERED", "ORDER_ORDERED"}), types.DefaultIBCVersion, types.ErrVersionNegotiationFailed},
}

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

err := tc.supportedVersion.VerifyProposedVersion(tc.proposedVersion)

if tc.expPass {
if tc.expError == nil {
require.NoError(t, err, "test case %d: %s", i, tc.name)
} else {
require.Error(t, err, "test case %d: %s", i, tc.name)
require.ErrorIs(t, err, tc.expError)
}
}
}
Expand Down
Loading

0 comments on commit 8ea3954

Please sign in to comment.