diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 9d105344a7d..a477cd42537 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -96,7 +96,10 @@ func (k Keeper) sendTransfer( for _, coin := range coins { // Using types.UnboundedSpendLimit allows us to send the entire balance of a given denom. if coin.Amount.Equal(types.UnboundedSpendLimit()) { - coin.Amount = k.bankKeeper.GetBalance(ctx, sender, coin.Denom).Amount + coin.Amount = k.bankKeeper.SpendableCoin(ctx, sender, coin.Denom).Amount + if coin.Amount.IsZero() { + return 0, errorsmod.Wrapf(types.ErrInvalidAmount, "empty spendable balance for %s", coin.Denom) + } } token, err := k.tokenFromCoin(ctx, coin) diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index daa95ce76a3..ff3a0d03eab 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -123,6 +123,64 @@ func (suite *KeeperTestSuite) TestSendTransfer() { }, nil, }, + // TODO: Migrate vesting account test cases to use x/accounts lockup accounts as mentioned in v0.52 upgrading doc. + // https://github.com/cosmos/ibc-go/issues/7681 + // { + // "successful transfer of entire spendable balance with vesting account", + // func() { + // // create vesting account + // vestingAccPrivKey := secp256k1.GenPrivKey() + // vestingAccAddress := sdk.AccAddress(vestingAccPrivKey.PubKey().Address()) + + // vestingCoins := sdk.NewCoins(sdk.NewCoin(coins[0].Denom, ibctesting.DefaultCoinAmount)) + // _, err := suite.chainA.SendMsgs(vestingtypes.NewMsgCreateVestingAccount( + // suite.chainA.SenderAccount.GetAddress(), + // vestingAccAddress, + // vestingCoins, + // suite.chainA.GetContext().BlockTime().Add(time.Hour).Unix(), + // false, + // )) + // suite.Require().NoError(err) + // sender = vestingAccAddress + + // // transfer some spendable coins to vesting account + // transferCoins := sdk.NewCoins(sdk.NewCoin(coins[0].Denom, sdkmath.NewInt(42))) + // _, err = suite.chainA.SendMsgs(banktypes.NewMsgSend(suite.chainA.SenderAccount.GetAddress(), vestingAccAddress, transferCoins)) + // suite.Require().NoError(err) + + // coins = sdk.NewCoins(sdk.NewCoin(coins[0].Denom, types.UnboundedSpendLimit())) + // expEscrowAmounts[0] = transferCoins[0].Amount + // }, + // nil, + // }, + // { + // "failure: no spendable coins for vesting account", + // func() { + // // create vesting account + // vestingAccPrivKey := secp256k1.GenPrivKey() + // vestingAccAddress := sdk.AccAddress(vestingAccPrivKey.PubKey().Address()) + + // vestingCoins := sdk.NewCoins(sdk.NewCoin(coins[0].Denom, ibctesting.DefaultCoinAmount)) + // _, err := suite.chainA.SendMsgs(vestingtypes.NewMsgCreateVestingAccount( + // suite.chainA.SenderAccount.GetAddress(), + // vestingAccAddress, + // vestingCoins, + // suite.chainA.GetContext().BlockTime().Add(time.Hour).Unix(), + // false, + // )) + // suite.Require().NoError(err) + // sender = vestingAccAddress + + // // just to prove that the vesting account has a balance (but not spendable) + // vestingAccBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), vestingAccAddress, coins[0].Denom) + // suite.Require().Equal(vestingCoins[0].Amount.Int64(), vestingAccBalance.Amount.Int64()) + // vestinSpendableBalance := suite.chainA.GetSimApp().BankKeeper.SpendableCoins(suite.chainA.GetContext(), vestingAccAddress) + // suite.Require().Zero(vestinSpendableBalance.AmountOf(coins[0].Denom).Int64()) + + // coins = sdk.NewCoins(sdk.NewCoin(coins[0].Denom, types.UnboundedSpendLimit())) + // }, + // types.ErrInvalidAmount, + // }, { "failure: source channel not found", func() { @@ -223,8 +281,8 @@ func (suite *KeeperTestSuite) TestSendTransfer() { expPass := tc.expError == nil if expPass { - suite.Require().NotNil(res) suite.Require().NoError(err) + suite.Require().NotNil(res) } else { suite.Require().Nil(res) suite.Require().Error(err) diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index 6e737bd82f6..bc8f82b7519 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -30,7 +30,7 @@ type BankKeeper interface { IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error HasDenomMetaData(ctx context.Context, denom string) bool SetDenomMetaData(ctx context.Context, denomMetaData banktypes.Metadata) - GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin + SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins } diff --git a/modules/core/04-channel/keeper/grpc_query_test.go b/modules/core/04-channel/keeper/grpc_query_test.go index 632fda80d09..3b42625120a 100644 --- a/modules/core/04-channel/keeper/grpc_query_test.go +++ b/modules/core/04-channel/keeper/grpc_query_test.go @@ -3,6 +3,11 @@ 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" @@ -26,14 +31,14 @@ func (suite *KeeperTestSuite) TestQueryChannel() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -43,7 +48,10 @@ func (suite *KeeperTestSuite) TestQueryChannel() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -53,7 +61,10 @@ func (suite *KeeperTestSuite) TestQueryChannel() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -63,7 +74,10 @@ func (suite *KeeperTestSuite) TestQueryChannel() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: test-port-id, channel-id test-channel-id").Error(), + ), }, { "success", @@ -83,7 +97,7 @@ func (suite *KeeperTestSuite) TestQueryChannel() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, } @@ -99,12 +113,13 @@ func (suite *KeeperTestSuite) TestQueryChannel() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.Channel(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(&expChannel, res.Channel) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -119,21 +134,21 @@ func (suite *KeeperTestSuite) TestQueryChannels() { 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.QueryChannelsRequest{} }, - true, + nil, }, { "success", @@ -182,7 +197,7 @@ func (suite *KeeperTestSuite) TestQueryChannels() { }, } }, - true, + nil, }, } @@ -198,13 +213,14 @@ func (suite *KeeperTestSuite) TestQueryChannels() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.Channels(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expChannels, res.Channels) suite.Require().Equal(len(expChannels), int(res.Pagination.Total)) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -219,14 +235,14 @@ func (suite *KeeperTestSuite) TestQueryConnectionChannels() { 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", @@ -235,7 +251,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionChannels() { Connection: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "success", @@ -285,7 +304,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionChannels() { }, } }, - true, + nil, }, { "success, empty response", @@ -302,7 +321,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionChannels() { }, } }, - true, + nil, }, } @@ -318,12 +337,13 @@ func (suite *KeeperTestSuite) TestQueryConnectionChannels() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.ConnectionChannels(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expChannels, res.Channels) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -338,14 +358,14 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -355,7 +375,10 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -365,7 +388,10 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -375,7 +401,10 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: test-port-id, channel-id: test-channel-id").Error(), + ), }, { "connection not found", @@ -394,7 +423,10 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { PortId: path.EndpointA.ChannelConfig.PortID, ChannelId: path.EndpointA.ChannelID, } - }, false, + }, status.Error( + codes.NotFound, + errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: doesnotexist").Error(), + ), }, { "client state for channel's connection not found", @@ -409,7 +441,10 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { PortId: path.EndpointA.ChannelConfig.PortID, ChannelId: path.EndpointA.ChannelID, } - }, false, + }, status.Error( + codes.NotFound, + errorsmod.Wrapf(clienttypes.ErrClientNotFound, "client-id: ").Error(), + ), }, { "success", @@ -430,7 +465,7 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, } @@ -446,7 +481,7 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.ChannelClientState(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(&expIdentifiedClientState, res.IdentifiedClientState) @@ -456,6 +491,7 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() { suite.Require().NotNil(cachedValue) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -471,14 +507,14 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -490,7 +526,10 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { RevisionHeight: 1, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -502,7 +541,10 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { RevisionHeight: 1, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -514,7 +556,10 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { RevisionHeight: 1, } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: test-port-id, channel-id test-channel-id").Error(), + ), }, { "connection not found", @@ -535,7 +580,10 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { RevisionNumber: 0, RevisionHeight: 1, } - }, false, + }, status.Error( + codes.NotFound, + errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: doesnotexist").Error(), + ), }, { "consensus state for channel's connection not found", @@ -549,7 +597,10 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { RevisionNumber: 0, RevisionHeight: uint64(suite.chainA.GetContext().BlockHeight()), // use current height } - }, false, + }, status.Error( + codes.NotFound, + errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: 07-tendermint-0").Error(), + ), }, { "success", @@ -573,7 +624,7 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { RevisionHeight: path.EndpointA.GetClientLatestHeight().GetRevisionHeight(), } }, - true, + nil, }, } @@ -589,7 +640,7 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.ChannelConsensusState(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) consensusState, err := clienttypes.UnpackConsensusState(res.ConsensusState) @@ -602,6 +653,7 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() { suite.Require().NotNil(cachedValue) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -616,14 +668,14 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -634,7 +686,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { Sequence: 0, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -645,7 +700,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { Sequence: 0, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid sequence", @@ -656,7 +714,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { Sequence: 0, } }, - false, + status.Error( + codes.InvalidArgument, + fmt.Errorf("packet sequence cannot be 0").Error(), + ), }, { "channel not found", @@ -667,7 +728,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { Sequence: 1, } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (test-port-id) channel ID (test-channel-id)").Error(), + ), }, { "commitment not found", @@ -682,7 +746,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { Sequence: 2, } }, - false, + status.Error( + codes.NotFound, + fmt.Errorf("packet commitment hash not found").Error(), + ), }, { "invalid ID", @@ -692,7 +759,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "success", @@ -708,7 +778,7 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { Sequence: 1, } }, - true, + nil, }, } @@ -724,12 +794,13 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitment() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.PacketCommitment(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expCommitment, res.Commitment) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -744,14 +815,14 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitments() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid ID", @@ -761,7 +832,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitments() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -771,7 +845,10 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitments() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (test-port-id) channel ID (test-channel-id)").Error(), + ), }, { "success", @@ -797,7 +874,7 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitments() { }, } }, - true, + nil, }, } @@ -813,12 +890,13 @@ func (suite *KeeperTestSuite) TestQueryPacketCommitments() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.PacketCommitments(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expCommitments, res.Commitments) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -833,14 +911,14 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -851,7 +929,10 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { Sequence: 1, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -862,7 +943,10 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { Sequence: 1, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid sequence", @@ -873,7 +957,10 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { Sequence: 0, } }, - false, + status.Error( + codes.InvalidArgument, + fmt.Errorf("packet sequence cannot be 0").Error(), + ), }, { "channel not found", @@ -884,7 +971,10 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { Sequence: 1, } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (test-port-id) channel ID (test-channel-id)").Error(), + ), }, { "success: receipt not found", @@ -900,7 +990,7 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { } expReceived = false }, - true, + nil, }, { "success: receipt found", @@ -916,7 +1006,7 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { } expReceived = true }, - true, + nil, }, } @@ -932,12 +1022,13 @@ func (suite *KeeperTestSuite) TestQueryPacketReceipt() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.PacketReceipt(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expReceived, res.Received) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -952,14 +1043,14 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -970,7 +1061,10 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { Sequence: 0, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -981,7 +1075,10 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { Sequence: 0, } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid sequence", @@ -992,7 +1089,10 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { Sequence: 0, } }, - false, + status.Error( + codes.InvalidArgument, + fmt.Errorf("packet sequence cannot be 0").Error(), + ), }, { "ack not found", @@ -1008,7 +1108,10 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { Sequence: 2, } }, - false, + status.Error( + codes.NotFound, + fmt.Errorf("packet acknowledgement hash not found").Error(), + ), }, { "channel not found", @@ -1019,7 +1122,10 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { Sequence: 1, } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (test-port-id) channel ID (test-channel-id)").Error(), + ), }, { "success", @@ -1035,7 +1141,7 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { Sequence: 1, } }, - true, + nil, }, } @@ -1051,12 +1157,13 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.PacketAcknowledgement(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expAck, res.Acknowledgement) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -1071,14 +1178,14 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid ID", @@ -1088,7 +1195,10 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -1098,7 +1208,10 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (test-port-id) channel ID (test-channel-id)").Error(), + ), }, { "success, filtered res", @@ -1125,7 +1238,7 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { Pagination: nil, } }, - true, + nil, }, { "success", @@ -1151,7 +1264,7 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { }, } }, - true, + nil, }, } @@ -1167,12 +1280,13 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.PacketAcknowledgements(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expAcknowledgements, res.Acknowledgements) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -1187,14 +1301,14 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -1204,7 +1318,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -1214,7 +1331,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid seq", @@ -1228,7 +1348,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: []uint64{0}, } }, - false, + status.Error( + codes.InvalidArgument, + fmt.Errorf("packet sequence 0 cannot be 0").Error(), + ), }, { "invalid seq, ordered channel", @@ -1243,7 +1366,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: []uint64{0}, } }, - false, + status.Error( + codes.InvalidArgument, + fmt.Errorf("packet sequence 0 cannot be 0").Error(), + ), }, { "channel not found", @@ -1253,7 +1379,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { ChannelId: "invalid-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: invalid-port-id, channel-id invalid-channel-id").Error(), + ), }, { "basic success empty packet commitments", @@ -1268,7 +1397,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: []uint64{}, } }, - true, + nil, }, { "basic success unreceived packet commitments", @@ -1285,7 +1414,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: []uint64{1}, } }, - true, + nil, }, { "basic success unreceived packet commitments, nothing to relay", @@ -1302,7 +1431,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: []uint64{1}, } }, - true, + nil, }, { "success multiple unreceived packet commitments", @@ -1329,7 +1458,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: packetCommitments, } }, - true, + nil, }, { "basic success empty packet commitments, ordered channel", @@ -1345,7 +1474,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: []uint64{}, } }, - true, + nil, }, { "basic success unreceived packet commitments, ordered channel", @@ -1362,7 +1491,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: []uint64{1}, } }, - true, + nil, }, { "basic success multiple unreceived packet commitments, ordered channel", @@ -1383,7 +1512,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { PacketCommitmentSequences: packetCommitments, } }, - true, + nil, }, } @@ -1399,12 +1528,13 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.UnreceivedPackets(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expSeq, res.Sequences) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -1419,14 +1549,14 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -1436,7 +1566,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -1446,7 +1579,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -1456,7 +1592,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (test-port-id) channel ID (test-channel-id)").Error(), + ), }, { "invalid seq", @@ -1470,7 +1609,10 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { PacketAckSequences: []uint64{0}, } }, - false, + status.Error( + codes.InvalidArgument, + fmt.Errorf("packet sequence 0 cannot be 0").Error(), + ), }, { "basic success unreceived packet acks", @@ -1487,7 +1629,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { PacketAckSequences: []uint64{1}, } }, - true, + nil, }, { "basic success unreceived packet acknowledgements, nothing to relay", @@ -1502,7 +1644,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { PacketAckSequences: []uint64{1}, } }, - true, + nil, }, { "success multiple unreceived packet acknowledgements", @@ -1528,7 +1670,7 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { PacketAckSequences: packetAcks, } }, - true, + nil, }, } @@ -1544,12 +1686,13 @@ func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.UnreceivedAcks(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expSeq, res.Sequences) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -1564,14 +1707,14 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -1581,7 +1724,10 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -1591,7 +1737,10 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -1601,7 +1750,10 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: test-port-id, channel-id test-channel-id").Error(), + ), }, { "basic success on unordered channel returns zero", @@ -1615,7 +1767,7 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, { "basic success on ordered channel returns the set receive sequence", @@ -1633,7 +1785,7 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, } @@ -1649,12 +1801,13 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceReceive() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.NextSequenceReceive(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expSeq, res.NextSequenceReceive) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -1669,14 +1822,14 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -1686,7 +1839,10 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -1696,7 +1852,10 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -1706,7 +1865,10 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrSequenceSendNotFound, "port-id: test-port-id, channel-id test-channel-id").Error(), + ), }, { "basic success on unordered channel returns the set send sequence", @@ -1722,7 +1884,7 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, { "basic success on ordered channel returns the set send sequence", @@ -1740,7 +1902,7 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, } @@ -1756,12 +1918,13 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.NextSequenceSend(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expSeq, res.NextSequenceSend) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -1776,14 +1939,14 @@ func (suite *KeeperTestSuite) TestQueryUpgradeError() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -1793,7 +1956,10 @@ func (suite *KeeperTestSuite) TestQueryUpgradeError() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -1803,7 +1969,10 @@ func (suite *KeeperTestSuite) TestQueryUpgradeError() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -1813,7 +1982,10 @@ func (suite *KeeperTestSuite) TestQueryUpgradeError() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: test-port-id, channel-id test-channel-id").Error(), + ), }, { "success", @@ -1828,7 +2000,7 @@ func (suite *KeeperTestSuite) TestQueryUpgradeError() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, } @@ -1842,12 +2014,13 @@ func (suite *KeeperTestSuite) TestQueryUpgradeError() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.UpgradeError(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(upgradeErr.GetErrorReceipt(), res.ErrorReceipt) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -1862,14 +2035,14 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty request", func() { req = nil }, - false, + status.Error(codes.InvalidArgument, "empty request"), }, { "invalid port ID", @@ -1879,7 +2052,10 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "invalid channel ID", @@ -1889,7 +2065,10 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { ChannelId: "", } }, - false, + status.Error( + codes.InvalidArgument, + errorsmod.Wrapf(host.ErrInvalidID, "identifier cannot be blank").Error(), + ), }, { "channel not found", @@ -1899,7 +2078,10 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { ChannelId: "test-channel-id", } }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: test-port-id, channel-id test-channel-id").Error(), + ), }, { "upgrade not found", @@ -1908,13 +2090,16 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { kvStore := suite.chainA.GetContext().KVStore(storeKey) kvStore.Delete(host.ChannelUpgradeKey(req.PortId, req.ChannelId)) }, - false, + status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrUpgradeNotFound, "port-id: mock, channel-id channel-420").Error(), + ), }, { "success", func() { }, - true, + nil, }, } @@ -1944,12 +2129,13 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeper) res, err := queryServer.Upgrade(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expectedUpgrade, res.Upgrade) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/core/04-channel/keeper/handshake_test.go b/modules/core/04-channel/keeper/handshake_test.go index 4ed5b5abbd6..5e42d673a49 100644 --- a/modules/core/04-channel/keeper/handshake_test.go +++ b/modules/core/04-channel/keeper/handshake_test.go @@ -3,10 +3,14 @@ package keeper_test import ( "fmt" + errorsmod "cosmossdk.io/errors" + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "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" ibctesting "github.com/cosmos/ibc-go/v9/testing" "github.com/cosmos/ibc-go/v9/testing/mock" @@ -15,7 +19,7 @@ import ( type testCase = struct { msg string malleate func() - expPass bool + expErr error } // TestChanOpenInit tests the OpenInit handshake call for channels. It uses message passing @@ -32,12 +36,12 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { {"success", func() { path.SetupConnections() features = []string{"ORDER_ORDERED", "ORDER_UNORDERED"} - }, true}, + }, nil}, {"connection doesn't exist", func() { // any non-empty values path.EndpointA.ConnectionID = "connection-0" path.EndpointB.ConnectionID = "connection-0" - }, false}, + }, connectiontypes.ErrConnectionNotFound}, {"connection version not negotiated", func() { path.SetupConnections() @@ -47,7 +51,7 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { }) features = []string{"ORDER_ORDERED", "ORDER_UNORDERED"} - }, false}, + }, connectiontypes.ErrInvalidVersion}, {"connection does not support ORDERED channels", func() { path.SetupConnections() @@ -58,10 +62,10 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { // NOTE: Opening UNORDERED channels is still expected to pass but ORDERED channels should fail features = []string{"ORDER_UNORDERED"} - }, true}, + }, nil}, { - msg: "unauthorized client", - expPass: false, + msg: "unauthorized client", + expErr: clienttypes.ErrClientNotActive, malleate: func() { expErrorMsgSubstring = "status is Unauthorized" path.SetupConnections() @@ -104,7 +108,7 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { // Testcase must have expectedPass = true AND channel order supported before // asserting the channel handshake initiation succeeded - if tc.expPass && orderSupported { + if (tc.expErr == nil) && orderSupported { suite.Require().NoError(err) suite.Require().Equal(types.FormatChannelIdentifier(0), channelID) } else { @@ -132,17 +136,17 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { path.SetChannelOrdered() err := path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - }, true}, + }, nil}, {"connection doesn't exist", func() { path.EndpointA.ConnectionID = ibctesting.FirstConnectionID path.EndpointB.ConnectionID = ibctesting.FirstConnectionID - }, false}, + }, connectiontypes.ErrConnectionNotFound}, {"connection is not OPEN", func() { path.SetupClients() err := path.EndpointB.ConnOpenInit() suite.Require().NoError(err) - }, false}, + }, connectiontypes.ErrInvalidConnectionState}, {"consensus state not found", func() { path.SetupConnections() path.SetChannelOrdered() @@ -150,11 +154,11 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { suite.Require().NoError(err) heightDiff = 3 // consensus state doesn't exist at this height - }, false}, + }, errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "")}, {"channel verification failed", func() { // not creating a channel on chainA will result in an invalid proof of existence path.SetupConnections() - }, false}, + }, commitmenttypes.ErrInvalidProof}, {"connection version not negotiated", func() { path.SetupConnections() path.SetChannelOrdered() @@ -165,7 +169,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.Versions = append(c.Versions, connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"})) }) - }, false}, + }, connectiontypes.ErrInvalidVersion}, {"connection does not support ORDERED channels", func() { path.SetupConnections() path.SetChannelOrdered() @@ -176,7 +180,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.Versions = []*connectiontypes.Version{connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"})} }) - }, false}, + }, connectiontypes.ErrInvalidVersion}, } for _, tc := range testCases { @@ -205,11 +209,12 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { proof, malleateHeight(proofHeight, heightDiff), ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotEmpty(channelID) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -234,7 +239,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) - }, true}, + }, nil}, {"success with empty stored counterparty channel ID", func() { path.SetupConnections() path.SetChannelOrdered() @@ -253,12 +258,12 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { counterpartyChannelID = path.EndpointB.ChannelID suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel) - }, true}, - {"channel doesn't exist", func() {}, false}, + }, nil}, + {"channel doesn't exist", func() {}, errorsmod.Wrap(types.ErrChannelNotFound, "")}, {"channel state is not INIT", func() { // create fully open channels on both chains path.Setup() - }, false}, + }, types.ErrInvalidChannelState}, {"connection not found", func() { path.SetupConnections() path.SetChannelOrdered() @@ -272,7 +277,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { channel := path.EndpointA.GetChannel() channel.ConnectionHops[0] = doesnotexist suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel) - }, false}, + }, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, "")}, {"connection is not OPEN", func() { path.SetupClients() @@ -284,7 +289,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - }, false}, + }, connectiontypes.ErrInvalidConnectionState}, {"consensus state not found", func() { path.SetupConnections() path.SetChannelOrdered() @@ -296,7 +301,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { suite.Require().NoError(err) heightDiff = 3 // consensus state doesn't exist at this height - }, false}, + }, ibcerrors.ErrInvalidHeight}, {"invalid counterparty channel identifier", func() { path.SetupConnections() path.SetChannelOrdered() @@ -308,7 +313,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { suite.Require().NoError(err) counterpartyChannelID = "otheridentifier" - }, false}, + }, commitmenttypes.ErrInvalidProof}, {"channel verification failed", func() { // chainB is INIT, chainA in TRYOPEN path.SetupConnections() @@ -319,7 +324,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointA.ChanOpenTry() suite.Require().NoError(err) - }, false}, + }, types.ErrInvalidChannelState}, } for _, tc := range testCases { @@ -350,10 +355,11 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { proof, malleateHeight(proofHeight, heightDiff), ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -380,12 +386,12 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err = path.EndpointA.ChanOpenAck() suite.Require().NoError(err) - }, true}, - {"channel doesn't exist", func() {}, false}, + }, nil}, + {"channel doesn't exist", func() {}, types.ErrChannelNotFound}, {"channel state is not TRYOPEN", func() { // create fully open channels on both chains path.Setup() - }, false}, + }, types.ErrInvalidChannelState}, {"connection not found", func() { path.SetupConnections() path.SetChannelOrdered() @@ -403,13 +409,13 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { channel := path.EndpointB.GetChannel() channel.ConnectionHops[0] = doesnotexist suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel) - }, false}, + }, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, "")}, {"connection is not OPEN", func() { path.SetupClients() err := path.EndpointB.ConnOpenInit() suite.Require().NoError(err) - }, false}, + }, types.ErrChannelNotFound}, {"consensus state not found", func() { path.SetupConnections() path.SetChannelOrdered() @@ -424,7 +430,7 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { suite.Require().NoError(err) heightDiff = 3 - }, false}, + }, ibcerrors.ErrInvalidHeight}, {"channel verification failed", func() { // chainA is INIT, chainB in TRYOPEN path.SetupConnections() @@ -435,7 +441,7 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) - }, false}, + }, commitmenttypes.ErrInvalidProof}, } for _, tc := range testCases { @@ -462,10 +468,11 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { proof, malleateHeight(proofHeight, heightDiff), ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -482,7 +489,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { testCases := []testCase{ {"success", func() { path.Setup() - }, true}, + }, nil}, {"channel doesn't exist", func() { // any non-nil values work for connections path.EndpointA.ConnectionID = ibctesting.FirstConnectionID @@ -490,13 +497,13 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { path.EndpointA.ChannelID = ibctesting.FirstChannelID path.EndpointB.ChannelID = ibctesting.FirstChannelID - }, false}, + }, types.ErrChannelNotFound}, {"channel state is CLOSED", func() { path.Setup() // close channel path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - }, false}, + }, types.ErrInvalidChannelState}, {"connection not found", func() { path.Setup() @@ -504,7 +511,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { channel := path.EndpointA.GetChannel() channel.ConnectionHops[0] = doesnotexist suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel) - }, false}, + }, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, "")}, {"connection is not OPEN", func() { path.SetupClients() @@ -515,10 +522,10 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { path.SetChannelOrdered() err = path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - }, false}, + }, connectiontypes.ErrInvalidConnectionState}, { - msg: "unauthorized client", - expPass: false, + msg: "unauthorized client", + expErr: clienttypes.ErrClientNotActive, malleate: func() { path.Setup() @@ -544,11 +551,12 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) suite.Require().Contains(err.Error(), expErrorMsgSubstring) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -568,7 +576,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { {"success", func() { path.Setup() path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - }, true}, + }, nil}, {"success with upgrade info", func() { path.Setup() @@ -588,17 +596,17 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { path.EndpointB.SetChannelUpgrade(upgrade) path.EndpointB.SetChannelCounterpartyUpgrade(counterpartyUpgrade) - }, true}, + }, nil}, {"channel doesn't exist", func() { // any non-nil values work for connections path.EndpointA.ChannelID = ibctesting.FirstChannelID path.EndpointB.ChannelID = ibctesting.FirstChannelID - }, false}, + }, errorsmod.Wrap(types.ErrChannelNotFound, "")}, {"channel state is CLOSED", func() { path.Setup() path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - }, false}, + }, types.ErrInvalidChannelState}, {"connection not found", func() { path.Setup() @@ -606,7 +614,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { channel := path.EndpointB.GetChannel() channel.ConnectionHops[0] = doesnotexist suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel) - }, false}, + }, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, "")}, {"connection is not OPEN", func() { path.SetupClients() @@ -617,18 +625,18 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { path.SetChannelOrdered() err = path.EndpointB.ChanOpenInit() suite.Require().NoError(err) - }, false}, + }, connectiontypes.ErrInvalidConnectionState}, {"consensus state not found", func() { path.Setup() path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) heightDiff = 3 - }, false}, + }, ibcerrors.ErrInvalidHeight}, {"channel verification failed", func() { // channel not closed path.Setup() - }, false}, + }, ibcerrors.ErrInvalidHeight}, { "failure: invalid counterparty upgrade sequence", func() { @@ -641,7 +649,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) }, - false, + commitmenttypes.ErrInvalidProof, }, } @@ -664,7 +672,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { proof, malleateHeight(proofHeight, heightDiff), counterpartyUpgradeSequence, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) // if the channel closed during an upgrade, there should not be any upgrade information @@ -674,6 +682,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { suite.Require().False(found) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/core/04-channel/keeper/keeper_test.go b/modules/core/04-channel/keeper/keeper_test.go index ef264410d19..c323e29457c 100644 --- a/modules/core/04-channel/keeper/keeper_test.go +++ b/modules/core/04-channel/keeper/keeper_test.go @@ -8,6 +8,8 @@ import ( testifysuite "github.com/stretchr/testify/suite" + errorsmod "cosmossdk.io/errors" + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -502,14 +504,14 @@ func (suite *KeeperTestSuite) TestDefaultSetParams() { // TestParams tests that Param setting and retrieval works properly func (suite *KeeperTestSuite) TestParams() { testCases := []struct { - name string - input types.Params - expPass bool + name string + input types.Params + expErr error }{ - {"success: set default params", types.DefaultParams(), true}, - {"success: zero timeout height", types.NewParams(types.NewTimeout(clienttypes.ZeroHeight(), 10000)), true}, - {"fail: zero timeout timestamp", types.NewParams(types.NewTimeout(clienttypes.NewHeight(1, 1000), 0)), false}, - {"fail: zero timeout", types.NewParams(types.NewTimeout(clienttypes.ZeroHeight(), 0)), false}, + {"success: set default params", types.DefaultParams(), nil}, + {"success: zero timeout height", types.NewParams(types.NewTimeout(clienttypes.ZeroHeight(), 10000)), nil}, + {"fail: zero timeout timestamp", types.NewParams(types.NewTimeout(clienttypes.NewHeight(1, 1000), 0)), errorsmod.Wrapf(types.ErrInvalidUpgradeTimeout, "upgrade timeout height must be zero. ")}, + {"fail: zero timeout", types.NewParams(types.NewTimeout(clienttypes.ZeroHeight(), 0)), errorsmod.Wrapf(types.ErrInvalidUpgradeTimeout, "upgrade timeout height must be zero.")}, } for _, tc := range testCases { @@ -520,13 +522,14 @@ func (suite *KeeperTestSuite) TestParams() { ctx := suite.chainA.GetContext() err := tc.input.Validate() suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetParams(ctx, tc.input) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) expected := tc.input p := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx) suite.Require().Equal(expected, p) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index bef2fd5b8bb..38fb54b2ad3 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "fmt" - "cosmossdk.io/errors" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -45,12 +45,12 @@ func (suite *KeeperTestSuite) TestSendPacket() { {"success: UNORDERED channel", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID - }, true}, + }, nil}, {"success: ORDERED channel", func() { path.SetChannelOrdered() path.Setup() sourceChannel = path.EndpointA.ChannelID - }, true}, + }, nil}, {"success with solomachine: UNORDERED channel", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID @@ -60,7 +60,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { path.EndpointA.ClientID = clienttypes.FormatClientIdentifier(exported.Solomachine, 10) path.EndpointA.SetClientState(solomachine.ClientState()) path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.ClientId = path.EndpointA.ClientID }) - }, true}, + }, nil}, {"success with solomachine: ORDERED channel", func() { path.SetChannelOrdered() path.Setup() @@ -72,50 +72,50 @@ func (suite *KeeperTestSuite) TestSendPacket() { path.EndpointA.SetClientState(solomachine.ClientState()) path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.ClientId = path.EndpointA.ClientID }) - }, true}, + }, nil}, {"packet basic validation failed, empty packet data", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID packetData = []byte{} - }, false}, + }, types.ErrInvalidPacket}, {"channel not found", func() { // use wrong channel naming path.Setup() sourceChannel = ibctesting.InvalidID - }, false}, + }, types.ErrChannelNotFound}, {"channel is in CLOSED state", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - }, false}, + }, types.ErrInvalidChannelState}, {"channel is in INIT state", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.INIT }) - }, false}, + }, types.ErrInvalidChannelState}, {"channel is in TRYOPEN stage", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.TRYOPEN }) - }, false}, + }, types.ErrInvalidChannelState}, {"connection not found", func() { // pass channel check path.Setup() sourceChannel = path.EndpointA.ChannelID path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.ConnectionHops[0] = "invalid-connection" }) - }, false}, + }, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, "")}, {"client state not found", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID // change connection client ID path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, + }, clienttypes.ErrClientNotActive}, {"client state is frozen", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID @@ -128,7 +128,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { // freeze client cs.FrozenHeight = clienttypes.NewHeight(0, 1) suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), connection.ClientId, cs) - }, false}, + }, clienttypes.ErrClientNotActive}, {"client state zero height", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID @@ -144,7 +144,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { cs.LatestHeight = clienttypes.ZeroHeight() suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), connection.ClientId, cs) - }, false}, + }, clienttypes.ErrInvalidHeight}, {"timeout height passed", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID @@ -152,7 +152,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { var ok bool timeoutHeight, ok = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) suite.Require().True(ok) - }, false}, + }, types.ErrTimeoutElapsed}, {"timeout timestamp passed", func() { path.Setup() sourceChannel = path.EndpointA.ChannelID @@ -163,7 +163,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { timeoutHeight = disabledTimeoutHeight timeoutTimestamp = timestamp - }, false}, + }, types.ErrTimeoutElapsed}, {"timeout timestamp passed with solomachine", func() { path.Setup() // swap client with solomachine @@ -180,7 +180,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { sourceChannel = path.EndpointA.ChannelID timeoutHeight = disabledTimeoutHeight timeoutTimestamp = timestamp - }, false}, + }, types.ErrTimeoutElapsed}, {"next sequence send not found", func() { path := ibctesting.NewPath(suite.chainA, suite.chainB) sourceChannel = path.EndpointA.ChannelID @@ -192,7 +192,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{path.EndpointA.ConnectionID}, path.EndpointA.ChannelConfig.Version), ) - }, false}, + }, errorsmod.Wrap(types.ErrSequenceSendNotFound, "")}, { "channel is in FLUSH_COMPLETE state", func() { @@ -201,7 +201,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE }) }, - false, + types.ErrInvalidChannelState, }, { "channel is in FLUSHING state", @@ -217,7 +217,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { err = path.EndpointA.ChanUpgradeTry() suite.Require().NoError(err) }, - false, + types.ErrChannelNotFound, }, } @@ -243,13 +243,14 @@ func (suite *KeeperTestSuite) TestSendPacket() { sequence, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.SendPacket(suite.chainA.GetContext(), sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) // verify that the returned sequence matches expected value suite.Require().True(ok) suite.Require().Equal(expectedSequence, sequence, "send packet did not return the expected sequence of the outgoing packet") } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -637,7 +638,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement }, - true, + nil, }, { "success: channel flushing", @@ -648,7 +649,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) }, - true, + nil, }, { "success: channel flush complete", @@ -659,21 +660,21 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE }) }, - true, + nil, }, {"channel not found", func() { // use wrong channel naming path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement - }, false}, + }, types.ErrChannelNotFound}, {"channel not open", func() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - }, false}, + }, types.ErrInvalidChannelState}, { "no-op, already acked", func() { @@ -682,7 +683,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { ack = ibcmock.MockAcknowledgement suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chainB.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ack.Acknowledgement()) }, - false, + types.ErrAcknowledgementExists, }, { "empty acknowledgement", @@ -691,7 +692,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.NewEmptyAcknowledgement() }, - false, + errorsmod.Wrap(types.ErrInvalidAcknowledgement, ""), }, { "acknowledgement is nil", @@ -700,7 +701,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = nil }, - false, + errorsmod.Wrap(types.ErrInvalidAcknowledgement, ""), }, { "packet already received", @@ -715,7 +716,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { // set recv seq start to indicate packet was processed in previous upgrade suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetRecvStartSequence(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sequence+1) }, - false, + errorsmod.Wrap(types.ErrPacketReceived, ""), }, } for i, tc := range testCases { @@ -728,10 +729,11 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.WriteAcknowledgement(suite.chainB.GetContext(), packet, ack) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -745,7 +747,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { ack = ibcmock.MockAcknowledgement ) - assertErr := func(errType *errors.Error) func(commitment []byte, channelVersion string, err error) { + assertErr := func(errType *errorsmod.Error) func(commitment []byte, channelVersion string, err error) { return func(commitment []byte, channelVersion string, err error) { suite.Require().Error(err) suite.Require().ErrorIs(err, errType) diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index dd24156f35c..463011f1a3d 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -13,7 +13,9 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "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" ibctesting "github.com/cosmos/ibc-go/v9/testing" "github.com/cosmos/ibc-go/v9/testing/mock" @@ -46,7 +48,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { // need to update chainA's client representing chainB to prove missing ack err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - }, true}, + }, nil}, {"success: UNORDERED", func() { ordered = false path.Setup() @@ -59,7 +61,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { // need to update chainA's client representing chainB to prove missing ack err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - }, true}, + }, nil}, {"packet already timed out: ORDERED", func() { expError = types.ErrNoOpMsg ordered = true @@ -78,7 +80,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) err = path.EndpointA.TimeoutPacket(packet) suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(types.ErrNoOpMsg, "")}, {"packet already timed out: UNORDERED", func() { expError = types.ErrNoOpMsg ordered = false @@ -95,25 +97,25 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) err = path.EndpointA.TimeoutPacket(packet) suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(types.ErrNoOpMsg, "")}, {"channel not found", func() { expError = types.ErrChannelNotFound // use wrong channel naming path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, types.ErrChannelNotFound}, {"packet destination port ≠ channel counterparty port", func() { expError = types.ErrInvalidPacket path.Setup() // use wrong port for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidPacket, "")}, {"packet destination channel ID ≠ channel counterparty channel ID", func() { expError = types.ErrInvalidPacket path.Setup() // use wrong channel for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidPacket, "")}, {"connection not found", func() { expError = connectiontypes.ErrConnectionNotFound // pass channel check @@ -123,7 +125,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), ) packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, "")}, {"timeout", func() { expError = types.ErrTimeoutNotReached path.Setup() @@ -132,7 +134,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(types.ErrTimeoutNotReached, "")}, {"packet already received ", func() { expError = types.ErrPacketReceived ordered = true @@ -147,7 +149,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, timeoutTimestamp) err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(types.ErrPacketReceived, "")}, {"packet hasn't been sent", func() { expError = types.ErrNoOpMsg ordered = true @@ -157,7 +159,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, uint64(suite.chainB.GetContext().BlockTime().UnixNano())) err := path.EndpointA.UpdateClient() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(types.ErrNoOpMsg, "")}, {"next seq receive verification failed", func() { // skip error check, error occurs in light-clients @@ -174,7 +176,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "")}, {"packet ack verification failed", func() { // skip error check, error occurs in light-clients @@ -190,7 +192,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "")}, } for _, tc := range testCases { @@ -221,11 +223,12 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { channelVersion, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutPacket(suite.chainA.GetContext(), packet, proof, proofHeight, nextSeqRecv) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().Equal(path.EndpointA.GetChannel().Version, channelVersion) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) suite.Require().Equal("", channelVersion) // only check if expError is set, since not all error codes can be known if expError != nil { @@ -533,7 +536,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - }, true}, + }, nil}, {"success: UNORDERED", func() { ordered = false path.Setup() @@ -548,22 +551,22 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - }, true}, + }, nil}, {"channel not found", func() { // use wrong channel naming path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, types.ErrChannelNotFound}, {"packet dest port ≠ channel counterparty port", func() { path.Setup() // use wrong port for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidPacket, "")}, {"packet dest channel ID ≠ channel counterparty channel ID", func() { path.Setup() // use wrong channel for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidPacket, "")}, {"connection not found", func() { // pass channel check suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel( @@ -572,13 +575,13 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), ) packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, "")}, {"packet hasn't been sent ORDERED", func() { path.SetChannelOrdered() path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.GetSelfHeight(suite.chainB.GetContext()), uint64(suite.chainB.GetContext().BlockTime().UnixNano())) - }, false}, + }, errorsmod.Wrap(types.ErrNoOpMsg, "")}, {"packet already received ORDERED", func() { path.SetChannelOrdered() nextSeqRecv = 2 @@ -596,7 +599,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidPacket, "")}, {"channel verification failed ORDERED", func() { ordered = true path.SetChannelOrdered() @@ -608,7 +611,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - }, false}, + }, ibcerrors.ErrInvalidHeight}, {"next seq receive verification failed ORDERED", func() { // set ordered to false providing the wrong proof for ORDERED case ordered = false @@ -625,7 +628,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.GetSelfHeight(suite.chainB.GetContext()), uint64(suite.chainB.GetContext().BlockTime().UnixNano())) - }, false}, + }, errorsmod.Wrap(types.ErrInvalidPacket, "")}, {"packet ack verification failed", func() { // set ordered to true providing the wrong proof for UNORDERED case ordered = true @@ -640,7 +643,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - }, false}, + }, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "")}, { "failure: invalid counterparty upgrade sequence", func() { @@ -665,7 +668,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) }, - false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, ""), }, } @@ -703,12 +706,13 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { counterpartyUpgradeSequence, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().Equal(path.EndpointA.GetChannel().Version, channelVersion) } else { suite.Require().Error(err) suite.Require().Equal("", channelVersion) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 8189e2d9bd8..8565f12a195 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -28,12 +28,12 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { "success", func() {}, - true, + nil, }, { "success with later upgrade sequence", @@ -41,7 +41,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.UpgradeSequence = 4 }) expSequence = 5 }, - true, + nil, }, { "upgrade fields are identical to channel end", @@ -49,7 +49,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { channel := path.EndpointA.GetChannel() upgradeFields = types.NewUpgradeFields(channel.Ordering, channel.ConnectionHops, channel.Version) }, - false, + errorsmod.Wrapf(types.ErrInvalidUpgrade, "existing channel end is identical to proposed upgrade channel end: got {ORDER_UNORDERED [connection-0] mock-version}"), }, { "channel not found", @@ -57,21 +57,21 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { path.EndpointA.ChannelID = "invalid-channel" path.EndpointA.ChannelConfig.PortID = "invalid-port" }, - false, + errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (invalid-port) channel ID (invalid-channel)"), }, { "channel state is not in OPEN state", func() { path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) }, - false, + errorsmod.Wrapf(types.ErrInvalidChannelState, "expected STATE_OPEN, got STATE_CLOSED"), }, { "proposed channel connection not found", func() { upgradeFields.ConnectionHops = []string{"connection-100"} }, - false, + errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "failed to retrieve connection: connection-100"), }, { "invalid proposed channel connection state", @@ -79,7 +79,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED }) upgradeFields.ConnectionHops = []string{"connection-100"} }, - false, + errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "failed to retrieve connection: connection-100"), }, } @@ -101,7 +101,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgradeFields, ) - if tc.expPass { + if tc.expErr == nil { ctx := suite.chainA.GetContext() suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeInitChannel(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgrade, upgrade.Fields.Version) channel := path.EndpointA.GetChannel() @@ -112,6 +112,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { suite.Require().Equal(types.OPEN, channel.State) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -2309,14 +2310,14 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() { tests := []struct { name string malleate func() - expPass bool + expErr error }{ { name: "change channel version", malleate: func() { proposedUpgrade.Version = mock.UpgradeVersion }, - expPass: true, + expErr: nil, }, { name: "change connection hops", @@ -2325,12 +2326,12 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() { path.Setup() proposedUpgrade.ConnectionHops = []string{path.EndpointA.ConnectionID} }, - expPass: true, + expErr: nil, }, { name: "fails with unmodified fields", malleate: func() {}, - expPass: false, + expErr: errorsmod.Wrapf(types.ErrInvalidUpgrade, "existing channel end is identical to proposed upgrade channel end: got {ORDER_UNORDERED [connection-0] mock-version}"), }, { name: "fails when connection is not set", @@ -2339,14 +2340,14 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() { kvStore := suite.chainA.GetContext().KVStore(storeKey) kvStore.Delete(host.ConnectionKey(ibctesting.FirstConnectionID)) }, - expPass: false, + expErr: errorsmod.Wrapf(types.ErrInvalidUpgrade, "existing channel end is identical to proposed upgrade channel end: got {ORDER_UNORDERED [connection-0] mock-version}"), }, { name: "fails when connection is not open", malleate: func() { path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED }) }, - expPass: false, + expErr: errorsmod.Wrapf(types.ErrInvalidUpgrade, "existing channel end is identical to proposed upgrade channel end: got {ORDER_UNORDERED [connection-0] mock-version}"), }, { name: "fails when connection versions do not exist", @@ -2358,7 +2359,7 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() { c.Versions = []*connectiontypes.Version{} }) }, - expPass: false, + expErr: errorsmod.Wrapf(connectiontypes.ErrInvalidVersion, "single version must be negotiated on connection before opening channel, got: []"), }, { name: "fails when connection version does not support the new ordering", @@ -2370,7 +2371,7 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() { c.Versions = []*connectiontypes.Version{connectiontypes.NewVersion("1", []string{"ORDER_ORDERED"})} }) }, - expPass: false, + expErr: errorsmod.Wrapf(connectiontypes.ErrInvalidVersion, "connection version identifier:\"1\" features:\"ORDER_ORDERED\" does not support channel ordering: ORDER_UNORDERED"), }, } @@ -2391,10 +2392,11 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() { tc.malleate() err := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.ValidateSelfUpgradeFields(suite.chainA.GetContext(), *proposedUpgrade, existingChannel) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -2424,12 +2426,12 @@ func (suite *KeeperTestSuite) TestAbortUpgrade() { tests := []struct { name string malleate func() - expPass bool + expErr error }{ { name: "success", malleate: func() {}, - expPass: true, + expErr: nil, }, { name: "regular error", @@ -2438,21 +2440,21 @@ func (suite *KeeperTestSuite) TestAbortUpgrade() { // i.e. not an instance of `types.UpgradeError` upgradeError = types.ErrInvalidUpgrade }, - expPass: true, + expErr: nil, }, { name: "channel does not exist", malleate: func() { suite.chainA.DeleteKey(host.ChannelKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) }, - expPass: false, + expErr: types.ErrChannelNotFound, }, { name: "fails with nil upgrade error", malleate: func() { upgradeError = nil }, - expPass: false, + expErr: types.ErrInvalidUpgradeError, }, } @@ -2476,7 +2478,7 @@ func (suite *KeeperTestSuite) TestAbortUpgrade() { tc.malleate() - if tc.expPass { + if tc.expErr == nil { ctx := suite.chainA.GetContext()