diff --git a/modules/core/03-connection/keeper/grpc_query_test.go b/modules/core/03-connection/keeper/grpc_query_test.go index 925c877ff35..a2349aa0d5b 100644 --- a/modules/core/03-connection/keeper/grpc_query_test.go +++ b/modules/core/03-connection/keeper/grpc_query_test.go @@ -3,11 +3,17 @@ package keeper_test import ( "fmt" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/types/query" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/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" ) @@ -21,21 +27,21 @@ func (suite *KeeperTestSuite) TestQueryConnection() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid connectionID", func() { req = &types.QueryConnectionRequest{} }, - false, + status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()), }, { "connection not found", @@ -44,7 +50,10 @@ func (suite *KeeperTestSuite) TestQueryConnection() { ConnectionId: ibctesting.InvalidID, } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrap(types.ErrConnectionNotFound, "IDisInvalid").Error(), + ), }, { "success", @@ -62,7 +71,7 @@ func (suite *KeeperTestSuite) TestQueryConnection() { ConnectionId: path.EndpointA.ConnectionID, } }, - true, + nil, }, } @@ -78,12 +87,13 @@ func (suite *KeeperTestSuite) TestQueryConnection() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) res, err := queryServer.Connection(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(&expConnection, res.Connection) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -104,21 +114,21 @@ func (suite *KeeperTestSuite) TestQueryConnections() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "empty pagination", func() { req = &types.QueryConnectionsRequest{} }, - true, + nil, }, { "success", @@ -155,7 +165,7 @@ func (suite *KeeperTestSuite) TestQueryConnections() { }, } }, - true, + nil, }, } @@ -171,12 +181,13 @@ func (suite *KeeperTestSuite) TestQueryConnections() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) res, err := queryServer.Connections(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expConnections, res.Connections) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -191,21 +202,21 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid connectionID", func() { req = &types.QueryClientConnectionsRequest{} }, - false, + status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()), }, { "connection not found", @@ -214,7 +225,10 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() { ClientId: ibctesting.InvalidID, } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, "IDisInvalid").Error(), + ), }, { "success", @@ -236,7 +250,7 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() { ClientId: path1.EndpointA.ClientID, } }, - true, + nil, }, } @@ -252,12 +266,13 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) res, err := queryServer.ClientConnections(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expPaths, res.ConnectionPaths) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -272,14 +287,14 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid connection ID", @@ -288,7 +303,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { ConnectionId: "", } }, - false, + status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()), }, { "connection not found", @@ -297,7 +312,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { ConnectionId: "test-connection-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrap(types.ErrConnectionNotFound, "connection-id: test-connection-id").Error(), + ), }, { "client state not found", @@ -311,7 +329,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { req = &types.QueryConnectionClientStateRequest{ ConnectionId: path.EndpointA.ConnectionID, } - }, false, + }, status.Error( + codes.NotFound, + errorsmod.Wrap(clienttypes.ErrClientNotFound, "client-id: ").Error(), + ), }, { "success", @@ -326,7 +347,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { ConnectionId: path.EndpointA.ConnectionID, } }, - true, + nil, }, } @@ -342,7 +363,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) res, err := queryServer.ConnectionClientState(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(&expIdentifiedClientState, res.IdentifiedClientState) @@ -352,6 +373,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() { suite.Require().NotNil(cachedValue) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -367,14 +389,14 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid connection ID", @@ -385,7 +407,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { RevisionHeight: 1, } }, - false, + status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()), }, { "connection not found", @@ -396,7 +418,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { RevisionHeight: 1, } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrap(types.ErrConnectionNotFound, "connection-id: test-connection-id").Error(), + ), }, { "consensus state not found", @@ -409,7 +434,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { RevisionNumber: 0, RevisionHeight: uint64(suite.chainA.GetContext().BlockHeight()), // use current height } - }, false, + }, status.Error( + codes.NotFound, + errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "client-id: 07-tendermint-0").Error(), + ), }, { "success", @@ -429,7 +457,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { RevisionHeight: clientHeight.GetRevisionHeight(), } }, - true, + nil, }, } @@ -445,7 +473,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper) res, err := queryServer.ConnectionConsensusState(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) consensusState, err := clienttypes.UnpackConsensusState(res.ConsensusState) @@ -458,6 +486,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { suite.Require().NotNil(cachedValue) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/core/03-connection/keeper/handshake_test.go b/modules/core/03-connection/keeper/handshake_test.go index e233c68fbe3..34a101d87e0 100644 --- a/modules/core/03-connection/keeper/handshake_test.go +++ b/modules/core/03-connection/keeper/handshake_test.go @@ -3,7 +3,11 @@ package keeper_test import ( "time" + errorsmod "cosmossdk.io/errors" + + 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" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -22,30 +26,30 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ {"success", func() { - }, true}, + }, nil}, {"success with empty counterparty identifier", func() { emptyConnBID = true - }, true}, + }, nil}, {"success with non empty version", func() { version = types.GetCompatibleVersions()[0] - }, true}, + }, nil}, {"success with non zero delayPeriod", func() { delayPeriod = uint64(time.Hour.Nanoseconds()) - }, true}, + }, nil}, {"invalid version", func() { version = &types.Version{} - }, false}, + }, errorsmod.Wrap(types.ErrInvalidVersion, "version is not supported")}, {"couldn't add connection to client", func() { // set path.EndpointA.ClientID to invalid client identifier path.EndpointA.ClientID = "clientidentifier" - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (clientidentifier) status is Unauthorized")}, { - msg: "unauthorized client", - expPass: false, + msg: "unauthorized client", + expErr: errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Unauthorized"), malleate: func() { expErrorMsgSubstring = "status is Unauthorized" // remove client from allowed list @@ -75,13 +79,14 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { connectionID, err := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.ConnOpenInit(suite.chainA.GetContext(), path.EndpointA.ClientID, counterparty, version, delayPeriod) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().Equal(types.FormatConnectionIdentifier(0), connectionID) } else { suite.Require().Error(err) suite.Contains(err.Error(), expErrorMsgSubstring) suite.Require().Equal("", connectionID) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -99,12 +104,12 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ {"success", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - }, true}, + }, nil}, {"success with delay period", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) @@ -118,23 +123,23 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { suite.coordinator.CommitBlock(suite.chainA) err = path.EndpointB.UpdateClient() suite.Require().NoError(err) - }, true}, + }, nil}, {"counterparty versions is empty", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) versions = nil - }, false}, + }, errorsmod.Wrap(types.ErrVersionNegotiationFailed, "failed to find a matching counterparty version ([]) from the supported version list ([identifier:\"1\" features:\"ORDER_ORDERED\" features:\"ORDER_UNORDERED\" ])")}, {"counterparty versions don't have a match", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) version := types.NewVersion("0.0", nil) versions = []*types.Version{version} - }, false}, + }, errorsmod.Wrap(types.ErrVersionNegotiationFailed, "failed to find a matching counterparty version ([identifier:\"0.0\" ]) from the supported version list ([identifier:\"1\" features:\"ORDER_ORDERED\" features:\"ORDER_UNORDERED\" ])")}, {"connection state verification failed", func() { // chainA connection not created - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed connection state verification for client (07-tendermint-0): commitment proof must be existence proof. got: int at index &{1374402732384}")}, } for _, tc := range testCases { @@ -163,12 +168,13 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { versions, initProof, proofHeight, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().Equal(types.FormatConnectionIdentifier(0), connectionID) } else { suite.Require().Error(err) suite.Require().Equal("", connectionID) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -185,7 +191,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ {"success", func() { err := path.EndpointA.ConnOpenInit() @@ -193,10 +199,10 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) - }, true}, + }, nil}, {"connection not found", func() { // connections are never created - }, false}, + }, errorsmod.Wrap(types.ErrConnectionNotFound, "")}, {"invalid counterparty connection ID", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) @@ -213,7 +219,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = path.EndpointB.UpdateClient() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed connection state verification for client (07-tendermint-0): commitment proof must be existence proof. got: int at index &{1374412614704}")}, {"connection state is not INIT", func() { // connection state is already OPEN on chainA err := path.EndpointA.ConnOpenInit() @@ -224,7 +230,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = path.EndpointA.ConnOpenAck() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidConnectionState, "connection state is not INIT (got STATE_OPEN)")}, {"connection is in INIT but the proposed version is invalid", func() { // chainA is in INIT, chainB is in TRYOPEN err := path.EndpointA.ConnOpenInit() @@ -234,7 +240,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { suite.Require().NoError(err) version = types.NewVersion("2.0", nil) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidConnectionState, "the counterparty selected version identifier:\"2.0\" is not supported by versions selected on INIT")}, {"incompatible IBC versions", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) @@ -244,7 +250,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { // set version to a non-compatible version version = types.NewVersion("2.0", nil) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidConnectionState, "the counterparty selected version identifier:\"2.0\" is not supported by versions selected on INIT")}, {"empty version", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) @@ -253,7 +259,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { suite.Require().NoError(err) version = &types.Version{} - }, false}, + }, errorsmod.Wrap(types.ErrInvalidConnectionState, "the counterparty selected version is not supported by versions selected on INIT")}, {"feature set verification failed - unsupported feature", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) @@ -262,12 +268,12 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { suite.Require().NoError(err) version = types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED", "ORDER_UNORDERED", "ORDER_DAG"}) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidConnectionState, "the counterparty selected version identifier:\"1\" features:\"ORDER_ORDERED\" features:\"ORDER_UNORDERED\" features:\"ORDER_DAG\" is not supported by versions selected on INIT")}, {"connection state verification failed", func() { // chainB connection is not in INIT err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed connection state verification for client (07-tendermint-0): commitment proof must be existence proof. got: int at index &{1374414228888}")}, } for _, tc := range testCases { @@ -292,10 +298,11 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { path.EndpointB.ConnectionID, tryProof, proofHeight, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -308,7 +315,7 @@ func (suite *KeeperTestSuite) TestConnOpenConfirm() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ {"success", func() { err := path.EndpointA.ConnOpenInit() @@ -319,14 +326,14 @@ func (suite *KeeperTestSuite) TestConnOpenConfirm() { err = path.EndpointA.ConnOpenAck() suite.Require().NoError(err) - }, true}, + }, nil}, {"connection not found", func() { // connections are never created - }, false}, + }, errorsmod.Wrap(types.ErrConnectionNotFound, "")}, {"chain B's connection state is not TRYOPEN", func() { // connections are OPEN path.CreateConnections() - }, false}, + }, errorsmod.Wrap(types.ErrInvalidConnectionState, "connection state is not TRYOPEN (got STATE_OPEN)")}, {"connection state verification failed", func() { // chainA is in INIT err := path.EndpointA.ConnOpenInit() @@ -334,7 +341,7 @@ func (suite *KeeperTestSuite) TestConnOpenConfirm() { err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed connection state verification for client (07-tendermint-0): failed to verify membership proof at index 0: provided value doesn't match proof")}, } for _, tc := range testCases { @@ -358,10 +365,11 @@ func (suite *KeeperTestSuite) TestConnOpenConfirm() { suite.chainB.GetContext(), path.EndpointB.ConnectionID, ackProof, proofHeight, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/core/03-connection/keeper/keeper_test.go b/modules/core/03-connection/keeper/keeper_test.go index ecdcdd3ab59..60b184ad704 100644 --- a/modules/core/03-connection/keeper/keeper_test.go +++ b/modules/core/03-connection/keeper/keeper_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "errors" "testing" testifysuite "github.com/stretchr/testify/suite" @@ -139,13 +140,13 @@ func (suite *KeeperTestSuite) TestDefaultSetParams() { // TestSetAndGetParams tests that param setting and retrieval works properly func (suite *KeeperTestSuite) TestSetAndGetParams() { testCases := []struct { - name string - input types.Params - expPass bool + name string + input types.Params + expErr error }{ - {"success: set default params", types.DefaultParams(), true}, - {"success: valid value for MaxExpectedTimePerBlock", types.NewParams(10), true}, - {"failure: invalid value for MaxExpectedTimePerBlock", types.NewParams(0), false}, + {"success: set default params", types.DefaultParams(), nil}, + {"success: valid value for MaxExpectedTimePerBlock", types.NewParams(10), nil}, + {"failure: invalid value for MaxExpectedTimePerBlock", types.NewParams(0), errors.New("MaxExpectedTimePerBlock cannot be zero")}, } for _, tc := range testCases { @@ -156,13 +157,14 @@ func (suite *KeeperTestSuite) TestSetAndGetParams() { ctx := suite.chainA.GetContext() err := tc.input.Validate() suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.SetParams(ctx, tc.input) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) expected := tc.input p := suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.GetParams(ctx) suite.Require().Equal(expected, p) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } diff --git a/modules/core/03-connection/keeper/verify_test.go b/modules/core/03-connection/keeper/verify_test.go index 4177aebbbce..83b844a2fec 100644 --- a/modules/core/03-connection/keeper/verify_test.go +++ b/modules/core/03-connection/keeper/verify_test.go @@ -4,10 +4,14 @@ import ( "fmt" "time" + errorsmod "cosmossdk.io/errors" + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/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" "github.com/cosmos/ibc-go/v9/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -26,24 +30,24 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ - {"verification success", func() {}, true}, + {"verification success", func() {}, nil}, {"client state not found - changed client ID", func() { path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (IDisInvalid) status is Unauthorized")}, {"consensus state not found - increased proof height", func() { heightDiff = 5 - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed connection state verification for client (07-tendermint-0): client state height < proof height ({1 9} < {1 14}), please ensure the client has been updated")}, {"verification failed - connection state is different than proof", func() { path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.State = types.TRYOPEN }) - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed connection state verification for client (07-tendermint-0): client state height < proof height ({1 9} < {1 14}), please ensure the client has been updated")}, {"client status is not active - client is expired", func() { clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, } for _, tc := range cases { @@ -69,10 +73,11 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { malleateHeight(proofHeight, heightDiff), proof, path.EndpointB.ConnectionID, expectedConnection, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -88,24 +93,24 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ - {"verification success", func() {}, true}, + {"verification success", func() {}, nil}, {"client state not found- changed client ID", func() { path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (IDisInvalid) status is Unauthorized")}, {"consensus state not found - increased proof height", func() { heightDiff = 5 - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed channel state verification for client (07-tendermint-0): client state height < proof height ({1 15} < {1 20}), please ensure the client has been updated")}, {"verification failed - changed channel state", func() { path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.TRYOPEN }) - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed channel state verification for client (07-tendermint-0): client state height < proof height ({1 15} < {1 20}), please ensure the client has been updated")}, {"client status is not active - client is expired", func() { clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, } for _, tc := range cases { @@ -130,10 +135,11 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -153,36 +159,36 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ - {"verification success", func() {}, true}, + {"verification success", func() {}, nil}, {"verification success: delay period passed", func() { delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) - }, true}, + }, nil}, {"delay time period has not passed", func() { delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet commitment verification for client (07-tendermint-0): cannot verify packet until time: 1577926940000000000, current time: 1577923345000000000")}, {"delay block period has not passed", func() { // make timePerBlock 1 nanosecond so that block delay is not passed. // must also set a non-zero time delay to ensure block delay is enforced. delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) timePerBlock = 1 - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet commitment verification for client (07-tendermint-0): cannot verify packet until height: 1-1000000016, current height: 1-17")}, {"client state not found- changed client ID", func() { path.EndpointB.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, {"consensus state not found - increased proof height", func() { heightDiff = 5 - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed packet commitment verification for client (07-tendermint-0): client state height < proof height ({1 17} < {1 22}), please ensure the client has been updated")}, {"verification failed - changed packet commitment state", func() { packet.Data = []byte(ibctesting.InvalidID) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed packet commitment verification for client (07-tendermint-0): failed to verify membership proof at index 0: provided value doesn't match proof")}, {"client status is not active - client is expired", func() { clientState, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointB.SetClientState(clientState) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, } for _, tc := range cases { @@ -220,10 +226,11 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), commitment, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -244,36 +251,36 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ - {"verification success", func() {}, true}, + {"verification success", func() {}, nil}, {"verification success: delay period passed", func() { delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) - }, true}, + }, nil}, {"delay time period has not passed", func() { delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet acknowledgement verification for client (07-tendermint-0): cannot verify packet until time: 1577934160000000000, current time: 1577930565000000000")}, {"delay block period has not passed", func() { // make timePerBlock 1 nanosecond so that block delay is not passed. // must also set a non-zero time delay to ensure block delay is enforced. delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) timePerBlock = 1 - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet acknowledgement verification for client (07-tendermint-0): cannot verify packet until height: 1-1000000018, current height: 1-19")}, {"client state not found- changed client ID", func() { path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, {"consensus state not found - increased proof height", func() { heightDiff = 5 - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed packet acknowledgement verification for client (07-tendermint-0): client state height < proof height ({1 19} < {1 24}), please ensure the client has been updated")}, {"verification failed - changed acknowledgement", func() { ack = ibcmock.MockFailAcknowledgement - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed packet acknowledgement verification for client (07-tendermint-0): failed to verify membership proof at index 0: provided value doesn't match proof")}, {"client status is not active - client is expired", func() { clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, } for _, tc := range cases { @@ -320,10 +327,11 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ack.Acknowledgement(), ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.ErrorIs(err, tc.expErr) } }) } @@ -344,27 +352,27 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ - {"verification success", func() {}, true}, + {"verification success", func() {}, nil}, {"verification success: delay period passed", func() { delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) - }, true}, + }, nil}, {"delay time period has not passed", func() { delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet commitment verification for client (07-tendermint-0): cannot verify packet until time: 1577926940000000000, current time: 1577923345000000000")}, {"delay block period has not passed", func() { // make timePerBlock 1 nanosecond so that block delay is not passed. // must also set a non-zero time delay to ensure block delay is enforced. delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) timePerBlock = 1 - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet commitment verification for client (07-tendermint-0): cannot verify packet until height: 1-1000000016, current height: 1-17")}, {"client state not found - changed client ID", func() { path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, {"consensus state not found - increased proof height", func() { heightDiff = 5 - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed packet commitment verification for client (07-tendermint-0): client state height < proof height ({1 17} < {1 22}), please ensure the client has been updated")}, {"verification failed - acknowledgement was received", func() { // increment receiving chain's (chainB) time by 2 hour to always pass receive suite.coordinator.IncrementTimeBy(time.Hour * 2) @@ -372,13 +380,13 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { err := path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed packet commitment verification for client (07-tendermint-0): failed to verify membership proof at index 0: provided value doesn't match proof")}, {"client status is not active - client is expired", func() { clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, } for _, tc := range cases { @@ -426,10 +434,11 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -450,36 +459,36 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ - {"verification success", func() {}, true}, + {"verification success", func() {}, nil}, {"verification success: delay period passed", func() { delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) - }, true}, + }, nil}, {"delay time period has not passed", func() { delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet commitment verification for client (07-tendermint-0): cannot verify packet until time: 1577926940000000000, current time: 1577923345000000000")}, {"delay block period has not passed", func() { // make timePerBlock 1 nanosecond so that block delay is not passed. // must also set a non-zero time delay to ensure block delay is enforced. delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) timePerBlock = 1 - }, false}, + }, errorsmod.Wrap(ibctm.ErrDelayPeriodNotPassed, "failed packet commitment verification for client (07-tendermint-0): cannot verify packet until height: 1-1000000016, current height: 1-17")}, {"client state not found- changed client ID", func() { path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, {"consensus state not found - increased proof height", func() { heightDiff = 5 - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed packet commitment verification for client (07-tendermint-0): client state height < proof height ({1 17} < {1 22}), please ensure the client has been updated")}, {"verification failed - wrong expected next seq recv", func() { offsetSeq = 1 - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed packet commitment verification for client (07-tendermint-0): failed to verify membership proof at index 0: provided value doesn't match proof")}, {"client status is not active - client is expired", func() { clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) - }, false}, + }, errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen")}, } for _, tc := range cases { @@ -524,10 +533,11 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()+offsetSeq, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -542,12 +552,12 @@ func (suite *KeeperTestSuite) TestVerifyUpgradeErrorReceipt() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ { name: "success", malleate: func() {}, - expPass: true, + expErr: nil, }, { name: "fails when client state is frozen", @@ -557,14 +567,14 @@ func (suite *KeeperTestSuite) TestVerifyUpgradeErrorReceipt() { clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointB.SetClientState(clientState) }, - expPass: false, + expErr: errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen"), }, { name: "fails with bad client id", malleate: func() { path.EndpointB.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) }, - expPass: false, + expErr: errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (IDisInvalid) status is Unauthorized"), }, { name: "verification fails when the key does not exist", @@ -572,7 +582,7 @@ func (suite *KeeperTestSuite) TestVerifyUpgradeErrorReceipt() { suite.chainA.DeleteKey(host.ChannelUpgradeErrorKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) suite.coordinator.CommitBlock(suite.chainA) }, - expPass: false, + expErr: errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "failed upgrade error receipt verification for client (07-tendermint-0): client state height < proof height ({1 17} < {1 18}), please ensure the client has been updated"), }, { name: "verification fails when message differs", @@ -580,7 +590,7 @@ func (suite *KeeperTestSuite) TestVerifyUpgradeErrorReceipt() { originalSequence := upgradeError.GetErrorReceipt().Sequence upgradeError = channeltypes.NewUpgradeError(originalSequence, fmt.Errorf("new error")) }, - expPass: false, + expErr: errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed upgrade error receipt verification for client (07-tendermint-0): failed to verify membership proof at index 0: provided value doesn't match proof"), }, } @@ -606,10 +616,11 @@ func (suite *KeeperTestSuite) TestVerifyUpgradeErrorReceipt() { err := suite.chainB.GetSimApp().IBCKeeper.ConnectionKeeper.VerifyChannelUpgradeError(suite.chainB.GetContext(), path.EndpointB.GetConnection(), proofHeight, proof, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgradeError.GetErrorReceipt()) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -624,12 +635,12 @@ func (suite *KeeperTestSuite) TestVerifyUpgrade() { cases := []struct { name string malleate func() - expPass bool + expErr error }{ { name: "success", malleate: func() {}, - expPass: true, + expErr: nil, }, { name: "fails when client state is frozen", @@ -639,21 +650,21 @@ func (suite *KeeperTestSuite) TestVerifyUpgrade() { clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointB.SetClientState(clientState) }, - expPass: false, + expErr: errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (07-tendermint-0) status is Frozen"), }, { name: "fails with bad client id", malleate: func() { path.EndpointB.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) }, - expPass: false, + expErr: errorsmod.Wrap(clienttypes.ErrClientNotActive, "client (IDisInvalid) status is Unauthorized"), }, { name: "fails when the upgrade field is different", malleate: func() { upgrade.Fields.Ordering = channeltypes.ORDERED }, - expPass: false, + expErr: errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed upgrade verification for client (07-tendermint-0) on channel (channel-7): failed to verify membership proof at index 0: provided value doesn't match proof"), }, } @@ -684,10 +695,11 @@ func (suite *KeeperTestSuite) TestVerifyUpgrade() { err := suite.chainB.GetSimApp().IBCKeeper.ConnectionKeeper.VerifyChannelUpgrade(suite.chainB.GetContext(), path.EndpointB.GetConnection(), proofHeight, proof, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgrade) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) }