test: create common functions for easily producing tm data structures (#6435)

This commit is contained in:
Callum Waters
2021-05-07 17:00:02 +02:00
committed by GitHub
parent 6fdf665385
commit a91680efee
33 changed files with 474 additions and 318 deletions
+3 -2
View File
@@ -11,6 +11,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/internal/test/factory"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -77,7 +78,7 @@ func makeValidCommit(
sigs := make([]types.CommitSig, 0)
for i := 0; i < vals.Size(); i++ {
_, val := vals.GetByIndex(int32(i))
vote, err := types.MakeVote(height, blockID, vals, privVals[val.Address.String()], chainID, time.Now())
vote, err := factory.MakeVote(privVals[val.Address.String()], chainID, int32(i), height, 0, 2, blockID, time.Now())
if err != nil {
return nil, err
}
@@ -261,7 +262,7 @@ func makeRandomStateFromValidatorSet(
func makeRandomStateFromConsensusParams(consensusParams *types.ConsensusParams,
height, lastHeightConsensusParamsChanged int64) sm.State {
val, _ := types.RandValidator(true, 10)
val, _ := factory.RandValidator(true, 10)
valSet := types.NewValidatorSet([]*types.Validator{val})
return sm.State{
LastBlockHeight: height - 1,
+7 -6
View File
@@ -14,6 +14,7 @@ import (
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/internal/test/factory"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
sm "github.com/tendermint/tendermint/state"
@@ -28,9 +29,9 @@ const (
func TestStoreBootstrap(t *testing.T) {
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
val, _ := types.RandValidator(true, 10)
val2, _ := types.RandValidator(true, 10)
val3, _ := types.RandValidator(true, 10)
val, _ := factory.RandValidator(true, 10)
val2, _ := factory.RandValidator(true, 10)
val3, _ := factory.RandValidator(true, 10)
vals := types.NewValidatorSet([]*types.Validator{val, val2, val3})
bootstrapState := makeRandomStateFromValidatorSet(vals, 100, 100)
err := stateStore.Bootstrap(bootstrapState)
@@ -54,9 +55,9 @@ func TestStoreBootstrap(t *testing.T) {
func TestStoreLoadValidators(t *testing.T) {
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
val, _ := types.RandValidator(true, 10)
val2, _ := types.RandValidator(true, 10)
val3, _ := types.RandValidator(true, 10)
val, _ := factory.RandValidator(true, 10)
val2, _ := factory.RandValidator(true, 10)
val3, _ := factory.RandValidator(true, 10)
vals := types.NewValidatorSet([]*types.Validator{val, val2, val3})
// 1) LoadValidators loads validators using a height where they were last changed
+13 -7
View File
@@ -12,6 +12,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/internal/test/factory"
"github.com/tendermint/tendermint/libs/log"
memmock "github.com/tendermint/tendermint/mempool/mock"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -139,12 +140,14 @@ func TestValidateBlockCommit(t *testing.T) {
#2589: ensure state.LastValidators.VerifyCommit fails here
*/
// should be height-1 instead of height
wrongHeightVote, err := types.MakeVote(
height,
state.LastBlockID,
state.Validators,
wrongHeightVote, err := factory.MakeVote(
privVals[proposerAddr.String()],
chainID,
1,
height,
0,
2,
state.LastBlockID,
time.Now(),
)
require.NoError(t, err, "height %d", height)
@@ -191,11 +194,14 @@ func TestValidateBlockCommit(t *testing.T) {
/*
wrongSigsCommit is fine except for the extra bad precommit
*/
goodVote, err := types.MakeVote(height,
blockID,
state.Validators,
goodVote, err := factory.MakeVote(
privVals[proposerAddr.String()],
chainID,
1,
height,
0,
2,
blockID,
time.Now(),
)
require.NoError(t, err, "height %d", height)