github.com/Finschia/finschia-sdk@v0.48.1/x/staking/keeper/common_test.go (about) 1 package keeper_test 2 3 import ( 4 "math/big" 5 "testing" 6 7 tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 8 9 "github.com/Finschia/finschia-sdk/codec" 10 "github.com/Finschia/finschia-sdk/simapp" 11 sdk "github.com/Finschia/finschia-sdk/types" 12 "github.com/Finschia/finschia-sdk/x/staking/keeper" 13 "github.com/Finschia/finschia-sdk/x/staking/types" 14 ) 15 16 var PKs = simapp.CreateTestPubKeys(500) 17 18 func init() { 19 sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)) 20 } 21 22 // createTestInput Returns a simapp with custom StakingKeeper 23 // to avoid messing with the hooks. 24 func createTestInput() (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) { 25 app := simapp.Setup(false) 26 ctx := app.BaseApp.NewContext(false, tmproto.Header{}) 27 28 app.StakingKeeper = keeper.NewKeeper( 29 app.AppCodec(), 30 app.GetKey(types.StoreKey), 31 app.AccountKeeper, 32 app.BankKeeper, 33 app.GetSubspace(types.ModuleName), 34 ) 35 return app.LegacyAmino(), app, ctx 36 } 37 38 // intended to be used with require/assert: require.True(ValEq(...)) 39 func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, types.Validator, types.Validator) { 40 return t, exp.MinEqual(&got), "expected:\n%v\ngot:\n%v", exp, got 41 } 42 43 // generateAddresses generates numAddrs of normal AccAddrs and ValAddrs 44 func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int) ([]sdk.AccAddress, []sdk.ValAddress) { 45 addrDels := simapp.AddTestAddrsIncremental(app, ctx, numAddrs, sdk.NewInt(10000)) 46 addrVals := simapp.ConvertAddrsToValAddrs(addrDels) 47 48 return addrDels, addrVals 49 }