From 72cade5f83576d410084f2e3fc4e32fc334182b4 Mon Sep 17 00:00:00 2001 From: bmo Date: Wed, 11 Dec 2024 08:27:29 +0000 Subject: [PATCH 1/3] chores: fix more connection tests --- .../03-connection/types/connection_test.go | 44 ++++++++++--------- .../core/03-connection/types/genesis_test.go | 28 ++++++------ 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/modules/core/03-connection/types/connection_test.go b/modules/core/03-connection/types/connection_test.go index ba88f05b8e9..d789662c77a 100644 --- a/modules/core/03-connection/types/connection_test.go +++ b/modules/core/03-connection/types/connection_test.go @@ -5,9 +5,11 @@ import ( "github.com/stretchr/testify/require" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" 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" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -24,32 +26,32 @@ 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, }, } @@ -57,10 +59,10 @@ func TestConnectionValidateBasic(t *testing.T) { 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) } } } @@ -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) } } } @@ -93,17 +95,17 @@ 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, }, } @@ -111,10 +113,10 @@ func TestIdentifiedConnectionValidateBasic(t *testing.T) { 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) } } -} +} \ No newline at end of file diff --git a/modules/core/03-connection/types/genesis_test.go b/modules/core/03-connection/types/genesis_test.go index 39a930c1433..96c43cebaf3 100644 --- a/modules/core/03-connection/types/genesis_test.go +++ b/modules/core/03-connection/types/genesis_test.go @@ -1,11 +1,13 @@ package types_test import ( + "errors" "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" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -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", @@ -34,7 +36,7 @@ func TestValidateGenesis(t *testing.T) { 0, types.DefaultParams(), ), - expPass: true, + expError: nil, }, { name: "invalid connection", @@ -48,7 +50,7 @@ func TestValidateGenesis(t *testing.T) { 0, types.DefaultParams(), ), - expPass: false, + expError: host.ErrInvalidID, }, { name: "invalid client id", @@ -62,7 +64,7 @@ func TestValidateGenesis(t *testing.T) { 0, types.DefaultParams(), ), - expPass: false, + expError: host.ErrInvalidID, }, { name: "invalid path", @@ -76,7 +78,7 @@ func TestValidateGenesis(t *testing.T) { 0, types.DefaultParams(), ), - expPass: false, + expError: host.ErrInvalidID, }, { name: "invalid connection identifier", @@ -90,7 +92,7 @@ func TestValidateGenesis(t *testing.T) { 0, types.DefaultParams(), ), - expPass: false, + expError: host.ErrInvalidID, }, { name: "localhost connection identifier", @@ -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", @@ -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", @@ -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()) } } -} +} \ No newline at end of file From 866f6cc065aba283e9c8a63e97068a44ffe0683b Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 11 Dec 2024 10:37:26 +0200 Subject: [PATCH 2/3] chore: make lint-fix --- modules/core/03-connection/types/connection_test.go | 4 ++-- modules/core/03-connection/types/genesis_test.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/core/03-connection/types/connection_test.go b/modules/core/03-connection/types/connection_test.go index d789662c77a..4a9250d1ec2 100644 --- a/modules/core/03-connection/types/connection_test.go +++ b/modules/core/03-connection/types/connection_test.go @@ -5,10 +5,10 @@ import ( "github.com/stretchr/testify/require" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" 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" ) @@ -119,4 +119,4 @@ func TestIdentifiedConnectionValidateBasic(t *testing.T) { require.ErrorIs(t, err, tc.expError) } } -} \ No newline at end of file +} diff --git a/modules/core/03-connection/types/genesis_test.go b/modules/core/03-connection/types/genesis_test.go index 96c43cebaf3..d541e024eeb 100644 --- a/modules/core/03-connection/types/genesis_test.go +++ b/modules/core/03-connection/types/genesis_test.go @@ -7,8 +7,9 @@ import ( "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" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/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" ) @@ -22,7 +23,7 @@ func TestValidateGenesis(t *testing.T) { { name: "default", genState: types.DefaultGenesisState(), - expError: nil, + expError: nil, }, { name: "valid genesis", @@ -147,4 +148,4 @@ func TestValidateGenesis(t *testing.T) { require.ErrorContains(t, err, tc.expError.Error()) } } -} \ No newline at end of file +} From dac2814182eae87f805f13956512963178f8e23d Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 11 Dec 2024 11:31:29 +0200 Subject: [PATCH 3/3] nit: fix linter hickup --- modules/core/03-connection/types/genesis_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/core/03-connection/types/genesis_test.go b/modules/core/03-connection/types/genesis_test.go index d541e024eeb..0ea3849294b 100644 --- a/modules/core/03-connection/types/genesis_test.go +++ b/modules/core/03-connection/types/genesis_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/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"