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

This commit is contained in:
Matt Kocubinski 2023-01-24 12:44:35 -06:00 committed by GitHub
parent e822585666
commit a16b11d5ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 28 deletions

View File

@ -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)
}
})
}

View File

@ -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{}),
},
},
})

18
x/auth/testutil/util.go Normal file
View File

@ -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)
}
}

View File

@ -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