Skip to content

Commit

Permalink
refactor: rm dependency from x/auth -> x/feegrant (#14755)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski authored Jan 24, 2023
1 parent e822585 commit a16b11d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
16 changes: 9 additions & 7 deletions x/auth/ante/feegrant_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante_test

import (
"errors"
"math/rand"
"testing"
"time"
Expand All @@ -20,16 +21,17 @@ 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) {
cases := map[string]struct {
fee int64
valid bool
err error
errMsg string
malleate func(*AnteTestSuite) (signer TestAccount, feeAcc sdk.AccAddress)
}{
"paying with low funds": {
Expand Down Expand Up @@ -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()
},
Expand Down Expand Up @@ -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)
}
})
}
Expand Down
27 changes: 8 additions & 19 deletions x/auth/testutil/app_config.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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{}),
},
},
})
18 changes: 18 additions & 0 deletions x/auth/testutil/util.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
3 changes: 1 addition & 2 deletions x/auth/tx/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit a16b11d

Please sign in to comment.