2020-02-14 07:30:51 -08:00
|
|
|
package staking_test
|
|
|
|
|
|
|
|
import (
|
2020-11-11 07:48:42 -08:00
|
|
|
"math/big"
|
|
|
|
|
2020-08-14 10:58:53 -07:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2020-02-14 07:30:51 -08:00
|
|
|
|
2020-02-27 07:47:59 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-09-25 01:41:16 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
2020-08-28 09:02:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
2020-02-27 07:47:59 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2020-02-14 07:30:51 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-02-26 01:47:39 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
2020-02-14 07:30:51 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
|
|
)
|
|
|
|
|
2020-11-11 07:48:42 -08:00
|
|
|
func init() {
|
|
|
|
sdk.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
|
|
|
}
|
|
|
|
|
2020-02-14 07:30:51 -08:00
|
|
|
// nolint:deadcode,unused,varcheck
|
|
|
|
var (
|
|
|
|
priv1 = secp256k1.GenPrivKey()
|
|
|
|
addr1 = sdk.AccAddress(priv1.PubKey().Address())
|
|
|
|
priv2 = secp256k1.GenPrivKey()
|
|
|
|
addr2 = sdk.AccAddress(priv2.PubKey().Address())
|
|
|
|
|
2020-08-14 10:58:53 -07:00
|
|
|
valKey = ed25519.GenPrivKey()
|
|
|
|
valAddr = sdk.AccAddress(valKey.PubKey().Address())
|
|
|
|
|
2020-06-12 07:54:37 -07:00
|
|
|
commissionRates = types.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
2020-02-26 01:47:39 -08:00
|
|
|
|
2020-02-27 07:47:59 -08:00
|
|
|
PKs = simapp.CreateTestPubKeys(500)
|
2020-02-14 07:30:51 -08:00
|
|
|
)
|
|
|
|
|
2020-02-26 01:47:39 -08:00
|
|
|
// getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper
|
|
|
|
// to avoid messing with the hooks.
|
2020-08-10 12:41:21 -07:00
|
|
|
func getBaseSimappWithCustomKeeper() (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) {
|
2020-02-26 01:47:39 -08:00
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-02-26 01:47:39 -08:00
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
appCodec := app.AppCodec()
|
2020-02-26 01:47:39 -08:00
|
|
|
|
|
|
|
app.StakingKeeper = keeper.NewKeeper(
|
|
|
|
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-26 01:47:39 -08:00
|
|
|
app.BankKeeper,
|
2020-06-12 07:54:37 -07:00
|
|
|
app.GetSubspace(types.ModuleName),
|
2020-02-26 01:47:39 -08:00
|
|
|
)
|
2020-02-26 04:28:18 -08:00
|
|
|
app.StakingKeeper.SetParams(ctx, types.DefaultParams())
|
2020-02-26 01:47:39 -08:00
|
|
|
|
2020-09-07 07:47:12 -07:00
|
|
|
return codec.NewLegacyAmino(), app, ctx
|
2020-02-26 01:47:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// generateAddresses generates numAddrs of normal AccAddrs and ValAddrs
|
2020-11-09 06:14:10 -08:00
|
|
|
func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int, accAmount sdk.Int) ([]sdk.AccAddress, []sdk.ValAddress) {
|
|
|
|
addrDels := simapp.AddTestAddrsIncremental(app, ctx, numAddrs, accAmount)
|
2020-02-26 01:47:39 -08:00
|
|
|
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
|
|
|
|
|
|
|
|
return addrDels, addrVals
|
|
|
|
}
|