2020-02-18 05:00:59 -08:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
2020-11-11 07:48:42 -08:00
|
|
|
"math/big"
|
2020-02-25 02:43:51 -08:00
|
|
|
"testing"
|
2020-02-18 05:00:59 -08:00
|
|
|
|
2020-08-14 10:58:53 -07:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2020-03-02 12:07:51 -08:00
|
|
|
|
2020-02-21 09:49:54 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2020-02-21 09:54:10 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-02-21 09:49:54 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
2020-02-25 02:43:51 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
2020-02-18 05:00:59 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-02-26 06:57:41 -08:00
|
|
|
PKs = simapp.CreateTestPubKeys(500)
|
2020-02-18 05:00:59 -08:00
|
|
|
)
|
|
|
|
|
2020-11-11 07:48:42 -08:00
|
|
|
func init() {
|
2021-01-27 02:24:00 -08:00
|
|
|
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
2020-11-11 07:48:42 -08:00
|
|
|
}
|
|
|
|
|
2020-02-26 06:57:41 -08:00
|
|
|
// createTestInput Returns a simapp with custom StakingKeeper
|
2020-02-21 09:49:54 -08:00
|
|
|
// to avoid messing with the hooks.
|
2021-08-16 17:52:06 -07:00
|
|
|
func createTestInput(t *testing.T) (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) {
|
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-02-21 09:49:54 -08:00
|
|
|
|
|
|
|
app.StakingKeeper = keeper.NewKeeper(
|
2020-10-23 05:07:52 -07:00
|
|
|
app.AppCodec(),
|
2020-06-12 07:54:37 -07:00
|
|
|
app.GetKey(types.StoreKey),
|
2020-04-20 12:32:10 -07:00
|
|
|
app.AccountKeeper,
|
2020-02-21 09:49:54 -08:00
|
|
|
app.BankKeeper,
|
2020-06-12 07:54:37 -07:00
|
|
|
app.GetSubspace(types.ModuleName),
|
2020-02-21 09:49:54 -08:00
|
|
|
)
|
2020-10-23 05:07:52 -07:00
|
|
|
return app.LegacyAmino(), app, ctx
|
2020-02-21 09:49:54 -08:00
|
|
|
}
|
2020-02-25 02:43:51 -08:00
|
|
|
|
|
|
|
// intended to be used with require/assert: require.True(ValEq(...))
|
|
|
|
func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, types.Validator, types.Validator) {
|
2020-10-23 05:07:52 -07:00
|
|
|
return t, exp.MinEqual(&got), "expected:\n%v\ngot:\n%v", exp, got
|
2020-02-25 02:43:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// generateAddresses generates numAddrs of normal AccAddrs and ValAddrs
|
|
|
|
func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int) ([]sdk.AccAddress, []sdk.ValAddress) {
|
|
|
|
addrDels := simapp.AddTestAddrsIncremental(app, ctx, numAddrs, sdk.NewInt(10000))
|
|
|
|
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
|
|
|
|
|
|
|
|
return addrDels, addrVals
|
|
|
|
}
|