cosmos-sdk/x/staking/common_test.go
SaReN 23a9f46aad
Update tm pubkey references (#7102)
* Update pubkey references

* Update ledger_mock

* Migrate encoding from tm

* Update pubkey prefix

* revert ed25519 to tendermint key

* random account revert

* Revert ed25519 references

* revert secp key name

* test revert

* remove ed25519

* Update x/staking/types/validator.go

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>

* Revert "remove ed25519"

This reverts commit 66d2e1d061aeae81c4c0a3daf718536b09dda19e.

* remove ed25519 & sr25519

* Apply suggestions from code review

* remove codec

Co-authored-by: Marko Baricevic <marbar3778@yahoo.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
2020-08-28 16:02:38 +00:00

69 lines
2.3 KiB
Go

package staking_test
import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"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())
valKey = ed25519.GenPrivKey()
valAddr = sdk.AccAddress(valKey.PubKey().Address())
commissionRates = types.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
PKs = simapp.CreateTestPubKeys(500)
)
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *types.MsgCreateValidator {
return types.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), types.Description{}, commissionRates, sdk.OneInt(),
)
}
func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Int) *types.MsgDelegate {
amount := sdk.NewCoin(sdk.DefaultBondDenom, amt)
return types.NewMsgDelegate(delAddr, valAddr, amount)
}
// getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper
// to avoid messing with the hooks.
func getBaseSimappWithCustomKeeper() (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
appCodec := app.AppCodec()
app.StakingKeeper = keeper.NewKeeper(
appCodec,
app.GetKey(types.StoreKey),
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(types.ModuleName),
)
app.StakingKeeper.SetParams(ctx, types.DefaultParams())
return codec.New(), app, ctx
}
// generateAddresses generates numAddrs of normal AccAddrs and ValAddrs
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))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
return addrDels, addrVals
}