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:
parent
d025cf09f8
commit
36ffd7a6da
@ -10,4 +10,5 @@ $mockgen_cmd -source=types/router.go -package mocks -destination tests/mocks/typ
|
||||
$mockgen_cmd -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server
|
||||
$mockgen_cmd -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger
|
||||
$mockgen_cmd -source=orm/model/ormtable/hooks.go -package ormmocks -destination orm/testing/ormmocks/hooks.go
|
||||
$mockgen_cmd -source=x/nft/expected_keepers.go -package testutil -destination x/nft/testutil/expected_keepers_mocks.go
|
||||
$mockgen_cmd -source=x/nft/expected_keepers.go -package testutil -destination x/nft/testutil/expected_keepers_mocks.go
|
||||
$mockgen_cmd -source=x/params/proposal_handler_test.go -package testutil -destination x/params/testutil/staking_keeper_mock.go
|
||||
@ -6,15 +6,14 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
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"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
||||
)
|
||||
@ -28,17 +27,18 @@ type KeeperTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) SetupTest() {
|
||||
var interfaceRegistry codectypes.InterfaceRegistry
|
||||
encodingCfg := moduletestutil.MakeTestEncodingConfig(params.AppModuleBasic{})
|
||||
key := sdk.NewKVStoreKey(types.StoreKey)
|
||||
tkey := sdk.NewTransientStoreKey("params_transient_test")
|
||||
|
||||
app, err := simtestutil.Setup(
|
||||
testutil.AppConfig,
|
||||
&suite.paramsKeeper,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
suite.ctx = testutil.DefaultContext(key, tkey)
|
||||
suite.paramsKeeper = keeper.NewKeeper(encodingCfg.Codec, encodingCfg.Amino, key, tkey)
|
||||
suite.paramsKeeper.Subspace("bank")
|
||||
suite.paramsKeeper.Subspace("staking")
|
||||
|
||||
suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, interfaceRegistry)
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, encodingCfg.InterfaceRegistry)
|
||||
proposal.RegisterQueryServer(queryHelper, suite.paramsKeeper)
|
||||
|
||||
suite.queryClient = proposal.NewQueryClient(queryHelper)
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
¶msKeeper,
|
||||
&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) {
|
||||
|
||||
49
x/params/testutil/staking_keeper_mock.go
Normal file
49
x/params/testutil/staking_keeper_mock.go
Normal file
@ -0,0 +1,49 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: x/params/proposal_handler_test.go
|
||||
|
||||
// Package testutil is a generated GoMock package.
|
||||
package testutil
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
types "github.com/cosmos/cosmos-sdk/types"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
// MockStakingKeeper is a mock of StakingKeeper interface.
|
||||
type MockStakingKeeper struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockStakingKeeperMockRecorder
|
||||
}
|
||||
|
||||
// MockStakingKeeperMockRecorder is the mock recorder for MockStakingKeeper.
|
||||
type MockStakingKeeperMockRecorder struct {
|
||||
mock *MockStakingKeeper
|
||||
}
|
||||
|
||||
// NewMockStakingKeeper creates a new mock instance.
|
||||
func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper {
|
||||
mock := &MockStakingKeeper{ctrl: ctrl}
|
||||
mock.recorder = &MockStakingKeeperMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// MaxValidators mocks base method.
|
||||
func (m *MockStakingKeeper) MaxValidators(ctx types.Context) uint32 {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "MaxValidators", ctx)
|
||||
ret0, _ := ret[0].(uint32)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// MaxValidators indicates an expected call of MaxValidators.
|
||||
func (mr *MockStakingKeeperMockRecorder) MaxValidators(ctx interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MaxValidators", reflect.TypeOf((*MockStakingKeeper)(nil).MaxValidators), ctx)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user