From 1af0bfc11ad7081f3ccaaea9585b294b93e40048 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 28 Aug 2024 09:44:23 +0100 Subject: [PATCH] chore: expect specific errors in apps/transfer (#7205) * chore: expect specific errors in apps/transfer * revert changed line * mark function as helper --------- Co-authored-by: Carlos Rodriguez --- .../apps/transfer/keeper/grpc_query_test.go | 76 ++++++++++--------- modules/apps/transfer/keeper/keeper_test.go | 31 ++++---- .../apps/transfer/keeper/msg_server_test.go | 20 ++--- modules/apps/transfer/types/codec_test.go | 16 ++-- modules/apps/transfer/types/genesis_test.go | 13 ++-- modules/apps/transfer/types/msgs_test.go | 10 +-- modules/apps/transfer/types/packet_test.go | 29 +++---- .../types/transfer_authorization_test.go | 40 +++++----- 8 files changed, 122 insertions(+), 113 deletions(-) diff --git a/modules/apps/transfer/keeper/grpc_query_test.go b/modules/apps/transfer/keeper/grpc_query_test.go index 3b49c468c1f..866a5b34728 100644 --- a/modules/apps/transfer/keeper/grpc_query_test.go +++ b/modules/apps/transfer/keeper/grpc_query_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "errors" "fmt" sdkmath "cosmossdk.io/math" @@ -21,7 +22,7 @@ func (suite *KeeperTestSuite) TestQueryDenom() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "success: correct ibc denom", @@ -37,7 +38,7 @@ func (suite *KeeperTestSuite) TestQueryDenom() { Hash: expDenom.IBCDenom(), } }, - true, + nil, }, { "success: correct hex hash", @@ -53,7 +54,7 @@ func (suite *KeeperTestSuite) TestQueryDenom() { Hash: expDenom.Hash().String(), } }, - true, + nil, }, { "failure: invalid hash", @@ -62,7 +63,7 @@ func (suite *KeeperTestSuite) TestQueryDenom() { Hash: "!@#!@#!", } }, - false, + errors.New("invalid denom trace hash"), }, { "failure: not found denom trace", @@ -77,7 +78,7 @@ func (suite *KeeperTestSuite) TestQueryDenom() { Hash: expDenom.IBCDenom(), } }, - false, + errors.New("denomination not found"), }, } @@ -91,12 +92,12 @@ func (suite *KeeperTestSuite) TestQueryDenom() { res, err := suite.chainA.GetSimApp().TransferKeeper.Denom(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(&expDenom, res.Denom) } else { - suite.Require().Error(err) + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expErr, err.Error()) } }) } @@ -111,14 +112,14 @@ func (suite *KeeperTestSuite) TestQueryDenoms() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "empty pagination", func() { req = &types.QueryDenomsRequest{} }, - true, + nil, }, { "success", @@ -138,7 +139,7 @@ func (suite *KeeperTestSuite) TestQueryDenoms() { }, } }, - true, + nil, }, } @@ -152,12 +153,12 @@ func (suite *KeeperTestSuite) TestQueryDenoms() { res, err := suite.chainA.GetSimApp().TransferKeeper.Denoms(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expDenoms.Sort(), res.Denoms) } else { - suite.Require().Error(err) + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expErr, err.Error()) } }) } @@ -181,16 +182,21 @@ func (suite *KeeperTestSuite) TestQueryDenomHash() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ + { + "success", + func() {}, + nil, + }, { "invalid trace", func() { req = &types.QueryDenomHashRequest{ - Trace: "transfer/channelToA/transfer/", + Trace: "transfer%%/channel-1/transfer/channel-1/uatom", } }, - false, + errors.New("invalid trace"), }, { "not found denom trace", @@ -199,12 +205,7 @@ func (suite *KeeperTestSuite) TestQueryDenomHash() { Trace: "transfer/channelToC/uatom", } }, - false, - }, - { - "success", - func() {}, - true, + errors.New("denomination not found"), }, } @@ -223,12 +224,12 @@ func (suite *KeeperTestSuite) TestQueryDenomHash() { res, err := suite.chainA.GetSimApp().TransferKeeper.DenomHash(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().Equal(expHash, res.Hash) } else { - suite.Require().Error(err) + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expErr, err.Error()) } }) } @@ -241,7 +242,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "success", @@ -251,7 +252,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { ChannelId: path.EndpointA.ChannelID, } }, - true, + nil, }, { "failure - channel not found", @@ -261,7 +262,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { ChannelId: ibctesting.FirstChannelID, } }, - false, + errors.New("channel not found"), }, { "failure - empty channelID", @@ -271,7 +272,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { ChannelId: "", } }, - false, + errors.New("identifier cannot be blank"), }, { "failure - empty portID", @@ -281,7 +282,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { ChannelId: ibctesting.FirstChannelID, } }, - false, + errors.New("identifier cannot be blank"), }, } @@ -297,12 +298,12 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { res, err := suite.chainA.GetSimApp().TransferKeeper.EscrowAddress(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) expected := types.GetEscrowAddress(ibctesting.TransferPort, path.EndpointA.ChannelID).String() suite.Require().Equal(expected, res.EscrowAddress) } else { - suite.Require().Error(err) + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expErr, err.Error()) } }) } @@ -317,7 +318,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { testCases := []struct { msg string malleate func() - expPass bool + expErr error }{ { "valid native denom with escrow amount < 2^63", @@ -329,7 +330,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { expEscrowAmount = sdkmath.NewInt(100) suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, expEscrowAmount)) }, - true, + nil, }, { "valid ibc denom with escrow amount > 2^63", @@ -345,7 +346,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { Denom: denom.IBCDenom(), } }, - true, + nil, }, { "valid ibc denom treated as native denom", @@ -356,7 +357,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { Denom: denom.IBCDenom(), } }, - true, // denom trace is not found, thus the denom is considered a native token + nil, // denom trace is not found, thus the denom is considered a native token }, { "invalid ibc denom treated as valid native denom", @@ -365,7 +366,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { Denom: "ibc/123", } }, - true, // the ibc denom does not contain a valid hash, thus the denom is considered a native token + nil, // the ibc denom does not contain a valid hash, thus the denom is considered a native token }, { "invalid denom", @@ -374,7 +375,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { Denom: "??𓃠🐾??", } }, - false, + errors.New("invalid denom"), }, } @@ -389,10 +390,11 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { res, err := suite.chainA.GetSimApp().TransferKeeper.TotalEscrowForDenom(ctx, req) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().Equal(expEscrowAmount, res.Amount.Amount) } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expErr, err.Error()) suite.Require().Error(err) } }) diff --git a/modules/apps/transfer/keeper/keeper_test.go b/modules/apps/transfer/keeper/keeper_test.go index dc9566bd39f..b873501396b 100644 --- a/modules/apps/transfer/keeper/keeper_test.go +++ b/modules/apps/transfer/keeper/keeper_test.go @@ -53,7 +53,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { testCases := []struct { name string instantiateFn func() - expPass bool + panicMsg string }{ {"success", func() { keeper.NewKeeper( @@ -68,7 +68,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().ScopedTransferKeeper, suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(), ) - }, true}, + }, ""}, {"failure: transfer module account does not exist", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), @@ -82,7 +82,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().ScopedTransferKeeper, suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(), ) - }, false}, + }, "the IBC transfer module account has not been set"}, {"failure: empty authority", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), @@ -96,7 +96,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().ScopedTransferKeeper, "", // authority ) - }, false}, + }, "authority must be non-empty"}, } for _, tc := range testCases { @@ -104,12 +104,13 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.SetupTest() suite.Run(tc.name, func() { - if tc.expPass { + if tc.panicMsg == "" { suite.Require().NotPanics( tc.instantiateFn, ) } else { - suite.Require().Panics( + suite.Require().PanicsWithError( + tc.panicMsg, tc.instantiateFn, ) } @@ -326,15 +327,15 @@ func (suite *KeeperTestSuite) TestGetAllForwardedPackets() { func (suite *KeeperTestSuite) TestParams() { testCases := []struct { - name string - input types.Params - expPass bool + name string + input types.Params + panicMsg string }{ // it is not possible to set invalid booleans - {"success: set params false-false", types.NewParams(false, false), true}, - {"success: set params false-true", types.NewParams(false, true), true}, - {"success: set params true-false", types.NewParams(true, false), true}, - {"success: set params true-true", types.NewParams(true, true), true}, + {"success: set params false-false", types.NewParams(false, false), ""}, + {"success: set params false-true", types.NewParams(false, true), ""}, + {"success: set params true-false", types.NewParams(true, false), ""}, + {"success: set params true-true", types.NewParams(true, true), ""}, } for _, tc := range testCases { @@ -343,13 +344,13 @@ func (suite *KeeperTestSuite) TestParams() { suite.Run(tc.name, func() { suite.SetupTest() // reset ctx := suite.chainA.GetContext() - if tc.expPass { + if tc.panicMsg == "" { suite.chainA.GetSimApp().TransferKeeper.SetParams(ctx, tc.input) expected := tc.input p := suite.chainA.GetSimApp().TransferKeeper.GetParams(ctx) suite.Require().Equal(expected, p) } else { - suite.Require().Panics(func() { + suite.Require().PanicsWithError(tc.panicMsg, func() { suite.chainA.GetSimApp().TransferKeeper.SetParams(ctx, tc.input) }) } diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 793137e7843..0fb434b08fb 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -201,34 +201,34 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { func (suite *KeeperTestSuite) TestUpdateParams() { signer := suite.chainA.GetSimApp().TransferKeeper.GetAuthority() testCases := []struct { - name string - msg *types.MsgUpdateParams - expPass bool + name string + msg *types.MsgUpdateParams + expErr error }{ { "success: valid signer and default params", types.NewMsgUpdateParams(signer, types.DefaultParams()), - true, + nil, }, { "failure: malformed signer address", types.NewMsgUpdateParams(ibctesting.InvalidID, types.DefaultParams()), - false, + ibcerrors.ErrUnauthorized, }, { "failure: empty signer address", types.NewMsgUpdateParams("", types.DefaultParams()), - false, + ibcerrors.ErrUnauthorized, }, { "failure: whitespace signer address", types.NewMsgUpdateParams(" ", types.DefaultParams()), - false, + ibcerrors.ErrUnauthorized, }, { "failure: unauthorized signer address", types.NewMsgUpdateParams(ibctesting.TestAccAddress, types.DefaultParams()), - false, + ibcerrors.ErrUnauthorized, }, } @@ -237,10 +237,10 @@ func (suite *KeeperTestSuite) TestUpdateParams() { suite.Run(tc.name, func() { suite.SetupTest() _, err := suite.chainA.GetSimApp().TransferKeeper.UpdateParams(suite.chainA.GetContext(), tc.msg) - 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/apps/transfer/types/codec_test.go b/modules/apps/transfer/types/codec_test.go index 6be95087a9b..591282526b7 100644 --- a/modules/apps/transfer/types/codec_test.go +++ b/modules/apps/transfer/types/codec_test.go @@ -1,6 +1,7 @@ package types_test import ( + "errors" "strings" sdk "github.com/cosmos/cosmos-sdk/types" @@ -8,6 +9,7 @@ import ( "github.com/cosmos/ibc-go/v9/modules/apps/transfer" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" ) // TestMustMarshalProtoJSON tests that the memo field is only emitted (marshalled) if it is populated @@ -30,27 +32,27 @@ func (suite *TypesTestSuite) TestCodecTypeRegistration() { testCases := []struct { name string typeURL string - expPass bool + expErr error }{ { "success: MsgTransfer", sdk.MsgTypeURL(&types.MsgTransfer{}), - true, + nil, }, { "success: MsgUpdateParams", sdk.MsgTypeURL(&types.MsgUpdateParams{}), - true, + nil, }, { "success: TransferAuthorization", sdk.MsgTypeURL(&types.TransferAuthorization{}), - true, + nil, }, { "type not registered on codec", "ibc.invalid.MsgTypeURL", - false, + errors.New("unable to resolve type URL"), }, } @@ -61,12 +63,12 @@ func (suite *TypesTestSuite) TestCodecTypeRegistration() { encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.AppModuleBasic{}) msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) - if tc.expPass { + if tc.expErr == nil { suite.Require().NotNil(msg) suite.Require().NoError(err) } else { suite.Require().Nil(msg) - suite.Require().Error(err) + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expErr) } }) } diff --git a/modules/apps/transfer/types/genesis_test.go b/modules/apps/transfer/types/genesis_test.go index bd9acc7c9ff..b86f337ee4a 100644 --- a/modules/apps/transfer/types/genesis_test.go +++ b/modules/apps/transfer/types/genesis_test.go @@ -6,42 +6,43 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ) func TestValidateGenesis(t *testing.T) { testCases := []struct { name string genState *types.GenesisState - expPass bool + expErr error }{ { name: "default", genState: types.DefaultGenesisState(), - expPass: true, + expErr: nil, }, { "valid genesis", &types.GenesisState{ PortId: "portidone", }, - true, + nil, }, { "invalid client", &types.GenesisState{ PortId: "(INVALIDPORT)", }, - false, + host.ErrInvalidID, }, } for _, tc := range testCases { tc := tc err := tc.genState.Validate() - if tc.expPass { + if tc.expErr == nil { require.NoError(t, err, tc.name) } else { - require.Error(t, err, tc.name) + require.ErrorIs(t, err, tc.expErr, tc.name) } } } diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 625202e1816..f630b041d4b 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -148,10 +148,10 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress - expPass bool + errMsg string }{ - {"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), true}, - {"failure: nil address", nil, false}, + {"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), ""}, + {"failure: nil address", nil, "empty address string is not allowed"}, } for _, tc := range testCases { @@ -164,11 +164,11 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.AppModuleBasic{}) signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg) - if tc.expPass { + if tc.errMsg == "" { require.NoError(t, err) require.Equal(t, tc.address.Bytes(), signers[0]) } else { - require.Error(t, err) + require.ErrorContains(t, err, tc.errMsg) } }) } diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index 12911543a07..254cec03522 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -10,6 +10,7 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -26,29 +27,29 @@ func TestFungibleTokenPacketDataValidateBasic(t *testing.T) { testCases := []struct { name string packetData types.FungibleTokenPacketData - expPass bool + expErr error }{ - {"valid packet", types.NewFungibleTokenPacketData(denom, amount, sender, receiver, ""), true}, - {"valid packet with memo", types.NewFungibleTokenPacketData(denom, amount, sender, receiver, "memo"), true}, - {"valid packet with large amount", types.NewFungibleTokenPacketData(denom, largeAmount, sender, receiver, ""), true}, - {"invalid denom", types.NewFungibleTokenPacketData("", amount, sender, receiver, ""), false}, - {"invalid denom, invalid portID", types.NewFungibleTokenPacketData("(transfer)/channel-1/uatom", amount, sender, receiver, ""), false}, - {"invalid empty amount", types.NewFungibleTokenPacketData(denom, "", sender, receiver, ""), false}, - {"invalid zero amount", types.NewFungibleTokenPacketData(denom, "0", sender, receiver, ""), false}, - {"invalid negative amount", types.NewFungibleTokenPacketData(denom, "-1", sender, receiver, ""), false}, - {"invalid large amount", types.NewFungibleTokenPacketData(denom, invalidLargeAmount, sender, receiver, ""), false}, - {"missing sender address", types.NewFungibleTokenPacketData(denom, amount, emptyAddr, receiver, ""), false}, - {"missing recipient address", types.NewFungibleTokenPacketData(denom, amount, sender, emptyAddr, ""), false}, + {"valid packet", types.NewFungibleTokenPacketData(denom, amount, sender, receiver, ""), nil}, + {"valid packet with memo", types.NewFungibleTokenPacketData(denom, amount, sender, receiver, "memo"), nil}, + {"valid packet with large amount", types.NewFungibleTokenPacketData(denom, largeAmount, sender, receiver, ""), nil}, + {"invalid denom", types.NewFungibleTokenPacketData("", amount, sender, receiver, ""), types.ErrInvalidDenomForTransfer}, + {"invalid denom, invalid portID", types.NewFungibleTokenPacketData("(tranfer)/channel-1/uatom", amount, sender, receiver, ""), host.ErrInvalidID}, + {"invalid empty amount", types.NewFungibleTokenPacketData(denom, "", sender, receiver, ""), types.ErrInvalidAmount}, + {"invalid zero amount", types.NewFungibleTokenPacketData(denom, "0", sender, receiver, ""), types.ErrInvalidAmount}, + {"invalid negative amount", types.NewFungibleTokenPacketData(denom, "-1", sender, receiver, ""), types.ErrInvalidAmount}, + {"invalid large amount", types.NewFungibleTokenPacketData(denom, invalidLargeAmount, sender, receiver, ""), types.ErrInvalidAmount}, + {"missing sender address", types.NewFungibleTokenPacketData(denom, amount, emptyAddr, receiver, ""), ibcerrors.ErrInvalidAddress}, + {"missing recipient address", types.NewFungibleTokenPacketData(denom, amount, sender, emptyAddr, ""), ibcerrors.ErrInvalidAddress}, } for i, tc := range testCases { tc := tc err := tc.packetData.ValidateBasic() - if tc.expPass { + if tc.expErr == nil { require.NoError(t, err, "valid test case %d failed: %v", i, err) } else { - require.Error(t, err, "invalid test case %d passed: %s", i, tc.name) + require.ErrorIs(t, err, tc.expErr, "invalid test case %d passed: %s", i, tc.name) } } } diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index ca8bdf1819f..a02bc51a2f4 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -9,6 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibctesting "github.com/cosmos/ibc-go/v9/testing" "github.com/cosmos/ibc-go/v9/testing/mock" @@ -530,19 +532,19 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { "success", func() {}, - true, + nil, }, { "success: empty allow list", func() { transferAuthz.Allocations[0].AllowList = []string{} }, - true, + nil, }, { "success: with multiple allocations", @@ -556,21 +558,21 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { transferAuthz.Allocations = append(transferAuthz.Allocations, allocation) }, - true, + nil, }, { "success: with unlimited spend limit of max uint256", func() { transferAuthz.Allocations[0].SpendLimit = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, types.UnboundedSpendLimit())) }, - true, + nil, }, { "success: wildcard allowed packet data", func() { transferAuthz.Allocations[0].AllowedPacketData = []string{"*"} }, - true, + nil, }, { "success: with allowed forwarding hops", @@ -580,56 +582,56 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { {Hops: []types.Hop{types.NewHop(types.PortID, "channel-1")}}, } }, - true, + nil, }, { "empty allocations", func() { transferAuthz = types.TransferAuthorization{Allocations: []types.Allocation{}} }, - false, + types.ErrInvalidAuthorization, }, { "nil allocations", func() { transferAuthz = types.TransferAuthorization{} }, - false, + types.ErrInvalidAuthorization, }, { "nil spend limit coins", func() { transferAuthz.Allocations[0].SpendLimit = nil }, - false, + ibcerrors.ErrInvalidCoins, }, { "invalid spend limit coins", func() { transferAuthz.Allocations[0].SpendLimit = sdk.Coins{sdk.Coin{Denom: ""}} }, - false, + ibcerrors.ErrInvalidCoins, }, { "duplicate entry in allow list", func() { transferAuthz.Allocations[0].AllowList = []string{ibctesting.TestAccAddress, ibctesting.TestAccAddress} }, - false, + types.ErrInvalidAuthorization, }, { "invalid port identifier", func() { transferAuthz.Allocations[0].SourcePort = "" }, - false, + host.ErrInvalidID, }, { "invalid channel identifier", func() { transferAuthz.Allocations[0].SourceChannel = "" }, - false, + host.ErrInvalidID, }, { "duplicate channel ID", @@ -643,7 +645,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { transferAuthz.Allocations = append(transferAuthz.Allocations, allocation) }, - false, + channeltypes.ErrInvalidChannel, }, { "forwarding hop with invalid port ID", @@ -653,7 +655,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { {Hops: []types.Hop{types.NewHop("invalid/port", ibctesting.FirstChannelID)}}, } }, - false, + host.ErrInvalidID, }, { "forwarding hop with invalid channel ID", @@ -663,7 +665,7 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { {Hops: []types.Hop{types.NewHop(types.PortID, "invalid/channel")}}, } }, - false, + host.ErrInvalidID, }, } @@ -686,10 +688,10 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() { err := transferAuthz.ValidateBasic() - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) }