Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rm dependency from x/auth -> x/feegrant #14755

Merged
merged 7 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

@julienrbrt julienrbrt Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think bez meant here: https://github.com/cosmos/cosmos-sdk/blob/main/testutil/assertHelpers.go
If you end up moving this to this file, could you rename that file too :D

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