2020-02-14 07:30:51 -08:00
|
|
|
package staking_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
2020-08-14 10:58:53 -07:00
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
|
|
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-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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-06-12 07:54:37 -07:00
|
|
|
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *types.MsgCreateValidator {
|
2020-02-14 07:30:51 -08:00
|
|
|
return types.NewMsgCreateValidator(
|
2020-06-12 07:54:37 -07:00
|
|
|
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), types.Description{}, commissionRates, sdk.OneInt(),
|
2020-02-14 07:30:51 -08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-12 07:54:37 -07:00
|
|
|
func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Int) *types.MsgDelegate {
|
2020-02-14 07:30:51 -08:00
|
|
|
amount := sdk.NewCoin(sdk.DefaultBondDenom, amt)
|
2020-06-12 07:54:37 -07:00
|
|
|
return types.NewMsgDelegate(delAddr, valAddr, amount)
|
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-02-26 02:33:25 -08:00
|
|
|
func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int, accAmount int64) ([]sdk.AccAddress, []sdk.ValAddress) {
|
|
|
|
addrDels := simapp.AddTestAddrsIncremental(app, ctx, numAddrs, sdk.NewInt(accAmount))
|
2020-02-26 01:47:39 -08:00
|
|
|
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
|
|
|
|
|
|
|
|
return addrDels, addrVals
|
|
|
|
}
|