refactor: Use mocks for x/feegrant testing (#12472)

* add expected keepers mocks

* progress

* progress

* progress

* more progress

* progress

* remove debug prints

* undo simulation changes

* revert some more stuff

* Update x/feegrant/keeper/keeper.go

Co-authored-by: Marko <marbar3778@yahoo.com>

Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
Facundo Medica
2022-07-13 10:25:26 -03:00
committed by GitHub
co-authored by Marko
parent 401d17bb59
commit a2000ffb0b
13 changed files with 262 additions and 205 deletions
+6 -23
View File
@@ -8,33 +8,16 @@ import (
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
"github.com/cosmos/cosmos-sdk/x/feegrant/testutil"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)
func TestBasicFeeValidAllow(t *testing.T) {
var (
interfaceRegistry codectypes.InterfaceRegistry
bankKeeper bankkeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
feegrantKeeper keeper.Keeper
)
key := sdk.NewKVStoreKey(feegrant.StoreKey)
testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test"))
app, err := simtestutil.Setup(testutil.AppConfig,
&feegrantKeeper,
&bankKeeper,
&stakingKeeper,
&interfaceRegistry,
)
require.NoError(t, err)
ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1})
ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1})
badTime := ctx.BlockTime().AddDate(0, 0, -1)
allowace := &feegrant.BasicAllowance{
@@ -42,7 +25,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
}
require.Error(t, allowace.ValidateBasic())
ctx = app.BaseApp.NewContext(false, tmproto.Header{
ctx = ctx.WithBlockHeader(tmproto.Header{
Time: time.Now(),
})
eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 10))
@@ -150,7 +133,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
err := tc.allowance.ValidateBasic()
require.NoError(t, err)
ctx := app.BaseApp.NewContext(false, tmproto.Header{}).WithBlockTime(tc.blockTime)
ctx := testCtx.Ctx.WithBlockTime(tc.blockTime)
// now try to deduct
removed, err := tc.allowance.Accept(ctx, tc.fee, []sdk.Msg{})