refactor(x/params): use mocks for testing (#12473)

* remove dependency on simapp from x/params keeper tests

* refactor x/params proposal_handler_test away from simapp

* update mockgen

* import ordering

* more import ordering
This commit is contained in:
Matt Kocubinski
2022-07-08 07:44:01 +02:00
committed by GitHub
parent d025cf09f8
commit 36ffd7a6da
4 changed files with 80 additions and 25 deletions
+17 -12
View File
@@ -3,16 +3,17 @@ package params_test
import (
"testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/params/keeper"
"github.com/cosmos/cosmos-sdk/x/params/testutil"
paramstestutil "github.com/cosmos/cosmos-sdk/x/params/testutil"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -31,16 +32,20 @@ type HandlerTestSuite struct {
}
func (suite *HandlerTestSuite) SetupTest() {
var paramsKeeper keeper.Keeper
app, err := simtestutil.Setup(
testutil.AppConfig,
&paramsKeeper,
&suite.stakingKeeper,
)
suite.Require().NoError(err)
encodingCfg := moduletestutil.MakeTestEncodingConfig(params.AppModuleBasic{})
key := sdk.NewKVStoreKey(paramtypes.StoreKey)
tkey := sdk.NewTransientStoreKey("params_transient_test")
ctx := testutil.DefaultContext(key, tkey)
paramsKeeper := keeper.NewKeeper(encodingCfg.Codec, encodingCfg.Amino, key, tkey)
paramsKeeper.Subspace("staking").WithKeyTable(stakingtypes.ParamKeyTable())
ctrl := gomock.NewController(suite.T())
stakingKeeper := paramstestutil.NewMockStakingKeeper(ctrl)
stakingKeeper.EXPECT().MaxValidators(ctx).Return(uint32(1))
suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{})
suite.govHandler = params.NewParamChangeProposalHandler(paramsKeeper)
suite.stakingKeeper = stakingKeeper
suite.ctx = ctx
}
func TestHandlerTestSuite(t *testing.T) {