github.com/Finschia/finschia-sdk@v0.48.1/x/staking/keeper/keeper_test.go (about) 1 package keeper_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 "github.com/stretchr/testify/suite" 8 tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 9 10 "github.com/Finschia/finschia-sdk/baseapp" 11 "github.com/Finschia/finschia-sdk/simapp" 12 sdk "github.com/Finschia/finschia-sdk/types" 13 "github.com/Finschia/finschia-sdk/x/staking/keeper" 14 "github.com/Finschia/finschia-sdk/x/staking/types" 15 ) 16 17 type KeeperTestSuite struct { 18 suite.Suite 19 20 app *simapp.SimApp 21 ctx sdk.Context 22 addrs []sdk.AccAddress 23 vals []types.Validator 24 queryClient types.QueryClient 25 } 26 27 func (suite *KeeperTestSuite) SetupTest() { 28 app := simapp.Setup(false) 29 ctx := app.BaseApp.NewContext(false, tmproto.Header{}) 30 31 querier := keeper.Querier{Keeper: app.StakingKeeper} 32 33 queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) 34 types.RegisterQueryServer(queryHelper, querier) 35 queryClient := types.NewQueryClient(queryHelper) 36 37 addrs, _, validators := createValidators(suite.T(), ctx, app, []int64{9, 8, 7}) 38 header := tmproto.Header{ 39 ChainID: "HelloChain", 40 Height: 5, 41 } 42 43 // sort a copy of the validators, so that original validators does not 44 // have its order changed 45 sortedVals := make([]types.Validator, len(validators)) 46 copy(sortedVals, validators) 47 hi := types.NewHistoricalInfo(header, sortedVals, app.StakingKeeper.PowerReduction(ctx)) 48 app.StakingKeeper.SetHistoricalInfo(ctx, 5, &hi) 49 50 suite.app, suite.ctx, suite.queryClient, suite.addrs, suite.vals = app, ctx, queryClient, addrs, validators 51 } 52 53 func TestParams(t *testing.T) { 54 app := simapp.Setup(false) 55 ctx := app.BaseApp.NewContext(false, tmproto.Header{}) 56 57 expParams := types.DefaultParams() 58 59 // check that the empty keeper loads the default 60 resParams := app.StakingKeeper.GetParams(ctx) 61 require.True(t, expParams.Equal(resParams)) 62 63 // modify a params, save, and retrieve 64 expParams.MaxValidators = 777 65 app.StakingKeeper.SetParams(ctx, expParams) 66 resParams = app.StakingKeeper.GetParams(ctx) 67 require.True(t, expParams.Equal(resParams)) 68 } 69 70 func TestKeeperTestSuite(t *testing.T) { 71 suite.Run(t, new(KeeperTestSuite)) 72 }