From a16b11d5ee54c1dad16265ce2a0cb4f18c98b3b0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 24 Jan 2023 12:44:35 -0600 Subject: [PATCH] refactor: rm dependency from x/auth -> x/feegrant (#14755) --- x/auth/ante/feegrant_test.go | 16 +++++++++------- x/auth/testutil/app_config.go | 27 ++++++++------------------- x/auth/testutil/util.go | 18 ++++++++++++++++++ x/auth/tx/config/config.go | 3 +-- 4 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 x/auth/testutil/util.go diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index dc533a76e5..f819eccdad 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -1,6 +1,7 @@ package ante_test import ( + "errors" "math/rand" "testing" "time" @@ -20,9 +21,9 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/ante" authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/cosmos/cosmos-sdk/x/auth/testutil" "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" ) func TestDeductFeesNoDelegation(t *testing.T) { @@ -30,6 +31,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { fee int64 valid bool err error + errMsg string malleate func(*AnteTestSuite) (signer TestAccount, feeAcc sdk.AccAddress) }{ "paying with low funds": { @@ -114,14 +116,14 @@ func TestDeductFeesNoDelegation(t *testing.T) { }, }, "allowance smaller than requested fee": { - fee: 50, - valid: false, - err: feegrant.ErrFeeLimitExceeded, + fee: 50, + valid: false, + errMsg: "fee limit exceeded", malleate: func(suite *AnteTestSuite) (TestAccount, sdk.AccAddress) { accs := suite.CreateTestAccounts(2) suite.feeGrantKeeper.EXPECT(). UseGrantedFees(gomock.Any(), accs[1].acc.GetAddress(), accs[0].acc.GetAddress(), gomock.Any(), gomock.Any()). - Return(feegrant.ErrFeeLimitExceeded.Wrap("basic allowance")). + Return(errors.New("fee limit exceeded")). Times(2) return accs[0], accs[1].acc.GetAddress() }, @@ -169,14 +171,14 @@ func TestDeductFeesNoDelegation(t *testing.T) { if tc.valid { require.NoError(t, err) } else { - require.ErrorIs(t, err, tc.err) + testutil.AssertError(t, err, tc.err, tc.errMsg) } _, err = anteHandlerStack(suite.ctx, tx, false) // tests while stack if tc.valid { require.NoError(t, err) } else { - require.ErrorIs(t, err, tc.err) + testutil.AssertError(t, err, tc.err, tc.errMsg) } }) } diff --git a/x/auth/testutil/app_config.go b/x/auth/testutil/app_config.go index 44453a8f61..bf63c52b3a 100644 --- a/x/auth/testutil/app_config.go +++ b/x/auth/testutil/app_config.go @@ -1,22 +1,20 @@ package testutil import ( - _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/feegrant/module" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring "cosmossdk.io/core/appconfig" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -27,7 +25,6 @@ import ( authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" - feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1" genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" @@ -44,19 +41,16 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{ BeginBlockers: []string{ stakingtypes.ModuleName, genutiltypes.ModuleName, - feegrant.ModuleName, }, EndBlockers: []string{ stakingtypes.ModuleName, genutiltypes.ModuleName, - feegrant.ModuleName, }, InitGenesis: []string{ authtypes.ModuleName, banktypes.ModuleName, stakingtypes.ModuleName, genutiltypes.ModuleName, - feegrant.ModuleName, paramstypes.ModuleName, consensustypes.ModuleName, vestingtypes.ModuleName, @@ -105,10 +99,5 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{ Name: genutiltypes.ModuleName, Config: appconfig.WrapAny(&genutilmodulev1.Module{}), }, - - { - Name: feegrant.ModuleName, - Config: appconfig.WrapAny(&feegrantmodulev1.Module{}), - }, }, }) diff --git a/x/auth/testutil/util.go b/x/auth/testutil/util.go new file mode 100644 index 0000000000..93cd30355e --- /dev/null +++ b/x/auth/testutil/util.go @@ -0,0 +1,18 @@ +package testutil + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func AssertError(t *testing.T, err error, expectedErr error, expectedErrMsg string) { + switch { + case expectedErr != nil: + require.ErrorIs(t, err, expectedErr) + case expectedErrMsg != "": + require.ErrorContainsf(t, err, expectedErrMsg, "expected error %s, got %v", expectedErrMsg, err) + default: + require.Error(t, err) + } +} diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 4369bd9619..1a72654623 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/posthandler" "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" ) func init() { @@ -36,7 +35,7 @@ type TxInputs struct { BankKeeper authtypes.BankKeeper `optional:"true"` // TxBankKeeper is the expected bank keeper to be passed to Textual TxBankKeeper BankKeeper - FeeGrantKeeper feegrantkeeper.Keeper `optional:"true"` + FeeGrantKeeper ante.FeegrantKeeper `optional:"true"` } //nolint:revive