remove create test public keys

This commit is contained in:
Jonathan Gimeno 2020-02-26 15:57:41 +01:00
parent 64c2971c6f
commit 1d18f8839c
6 changed files with 29 additions and 63 deletions

View File

@ -1,14 +1,8 @@
package keeper_test
import (
"bytes"
"encoding/hex"
"strconv"
"testing"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
cdc "github.com/cosmos/cosmos-sdk/simapp/codec"
@ -20,40 +14,12 @@ import (
)
var (
PKs = createTestPubKeys(500)
PKs = simapp.CreateTestPubKeys(500)
)
// nolint: unparam
func createTestPubKeys(numPubKeys int) []crypto.PubKey {
var publicKeys []crypto.PubKey
var buffer bytes.Buffer
//start at 10 to avoid changing 1 to 01, 2 to 02, etc
for i := 100; i < (numPubKeys + 100); i++ {
numString := strconv.Itoa(i)
buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AF") //base pubkey string
buffer.WriteString(numString) //adding on final two digits to make pubkeys unique
publicKeys = append(publicKeys, NewPubKey(buffer.String()))
buffer.Reset()
}
return publicKeys
}
func NewPubKey(pk string) (res crypto.PubKey) {
pkBytes, err := hex.DecodeString(pk)
if err != nil {
panic(err)
}
//res, err = crypto.PubKeyFromBytes(pkBytes)
var pkEd ed25519.PubKeyEd25519
copy(pkEd[:], pkBytes)
return pkEd
}
// getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper
// createTestInput Returns a simapp with custom StakingKeeper
// to avoid messing with the hooks.
func getBaseSimappWithCustomKeeper() (*codec.Codec, *simapp.SimApp, sdk.Context) {
func createTestInput() (*codec.Codec, *simapp.SimApp, sdk.Context) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{})

View File

@ -15,7 +15,7 @@ import (
// tests GetDelegation, GetDelegatorDelegations, SetDelegation, RemoveDelegation, GetDelegatorDelegations
func TestDelegation(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(10000))
valAddrs := simapp.ConvertAddrsToValAddrs(addrDels)
@ -131,7 +131,7 @@ func TestDelegation(t *testing.T) {
// tests Get/Set/Remove UnbondingDelegation
func TestUnbondingDelegation(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
delAddrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(10000))
valAddrs := simapp.ConvertAddrsToValAddrs(delAddrs)
@ -177,7 +177,7 @@ func TestUnbondingDelegation(t *testing.T) {
}
func TestUnbondDelegation(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
delAddrs := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.NewInt(10000))
valAddrs := simapp.ConvertAddrsToValAddrs(delAddrs)
@ -222,7 +222,7 @@ func TestUnbondDelegation(t *testing.T) {
}
func TestUnbondingDelegationsMaxEntries(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.NewInt(10000))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -305,7 +305,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
//// test undelegating self delegation from a validator pushing it below MinSelfDelegation
//// shift it from the bonded to unbonding state and jailed
func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.NewInt(10000))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -371,7 +371,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) {
}
func TestUndelegateFromUnbondingValidator(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
delTokens := sdk.TokensFromConsensusPower(10)
delCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), delTokens))
@ -464,7 +464,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) {
}
func TestUndelegateFromUnbondedValidator(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
delTokens := sdk.TokensFromConsensusPower(10)
delCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), delTokens))
@ -548,7 +548,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) {
}
func TestUnbondingAllDelegationFromValidator(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
delTokens := sdk.TokensFromConsensusPower(10)
delCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), delTokens))
@ -624,7 +624,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) {
// Make sure that that the retrieving the delegations doesn't affect the state
func TestGetRedelegationsFromSrcValidator(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -651,7 +651,7 @@ func TestGetRedelegationsFromSrcValidator(t *testing.T) {
// tests Get/Set/Remove/Has UnbondingDelegation
func TestRedelegation(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -714,7 +714,7 @@ func TestRedelegation(t *testing.T) {
}
func TestRedelegateToSameValidator(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -745,7 +745,7 @@ func TestRedelegateToSameValidator(t *testing.T) {
}
func TestRedelegationMaxEntries(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -803,7 +803,7 @@ func TestRedelegationMaxEntries(t *testing.T) {
}
func TestRedelegateSelfDelegation(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -860,7 +860,7 @@ func TestRedelegateSelfDelegation(t *testing.T) {
}
func TestRedelegateFromUnbondingValidator(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -944,7 +944,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) {
}
func TestRedelegateFromUnbondedValidator(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)

View File

@ -15,7 +15,7 @@ import (
)
func TestHistoricalInfo(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 50, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
@ -43,7 +43,7 @@ func TestHistoricalInfo(t *testing.T) {
}
func TestTrackHistoricalInfo(t *testing.T) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 50, sdk.NewInt(0))
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)

View File

@ -15,7 +15,7 @@ import (
)
func TestNewQuerier(t *testing.T) {
cdc, app, ctx := getBaseSimappWithCustomKeeper()
cdc, app, ctx := createTestInput()
addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.NewInt(10000))
_, addrAcc2 := addrs[0], addrs[1]
@ -106,7 +106,7 @@ func TestNewQuerier(t *testing.T) {
}
func TestQueryParametersPool(t *testing.T) {
cdc, app, ctx := getBaseSimappWithCustomKeeper()
cdc, app, ctx := createTestInput()
querier := staking.NewQuerier(app.StakingKeeper)
bondDenom := sdk.DefaultBondDenom
@ -131,7 +131,7 @@ func TestQueryParametersPool(t *testing.T) {
}
func TestQueryValidators(t *testing.T) {
cdc, app, ctx := getBaseSimappWithCustomKeeper()
cdc, app, ctx := createTestInput()
params := app.StakingKeeper.GetParams(ctx)
querier := staking.NewQuerier(app.StakingKeeper)
@ -198,7 +198,7 @@ func TestQueryValidators(t *testing.T) {
}
func TestQueryDelegation(t *testing.T) {
cdc, app, ctx := getBaseSimappWithCustomKeeper()
cdc, app, ctx := createTestInput()
params := app.StakingKeeper.GetParams(ctx)
querier := staking.NewQuerier(app.StakingKeeper)
@ -425,7 +425,7 @@ func TestQueryDelegation(t *testing.T) {
}
func TestQueryRedelegations(t *testing.T) {
cdc, app, ctx := getBaseSimappWithCustomKeeper()
cdc, app, ctx := createTestInput()
querier := staking.NewQuerier(app.StakingKeeper)
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
@ -494,7 +494,7 @@ func TestQueryRedelegations(t *testing.T) {
}
func TestQueryUnbondingDelegation(t *testing.T) {
cdc, app, ctx := getBaseSimappWithCustomKeeper()
cdc, app, ctx := createTestInput()
querier := staking.NewQuerier(app.StakingKeeper)
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
@ -589,7 +589,7 @@ func TestQueryUnbondingDelegation(t *testing.T) {
}
func TestQueryHistoricalInfo(t *testing.T) {
cdc, app, ctx := getBaseSimappWithCustomKeeper()
cdc, app, ctx := createTestInput()
querier := staking.NewQuerier(app.StakingKeeper)
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))

View File

@ -19,7 +19,7 @@ import (
// bootstrapSlashTest creates 3 validators and bootstrap the app.
func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels, addrVals := generateAddresses(app, ctx, 100)

View File

@ -18,7 +18,7 @@ import (
)
func bootstrapValidatorTest(t *testing.T, power int64, numAddrs int) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
_, app, ctx := getBaseSimappWithCustomKeeper()
_, app, ctx := createTestInput()
addrDels, addrVals := generateAddresses(app, ctx, numAddrs)