mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-01 21:57:03 +00:00
factory: simplify validator and genesis factory functions (#7305)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -258,7 +259,6 @@ func makeRandomStateFromValidatorSet(
|
||||
InitialHeight: 1,
|
||||
}
|
||||
}
|
||||
|
||||
func makeRandomStateFromConsensusParams(
|
||||
ctx context.Context,
|
||||
t *testing.T,
|
||||
@@ -267,7 +267,7 @@ func makeRandomStateFromConsensusParams(
|
||||
lastHeightConsensusParamsChanged int64,
|
||||
) sm.State {
|
||||
t.Helper()
|
||||
val, _, err := factory.RandValidator(ctx, true, 10)
|
||||
val, _, err := factory.Validator(10 + int64(rand.Uint32()))
|
||||
require.NoError(t, err)
|
||||
valSet := types.NewValidatorSet([]*types.Validator{val})
|
||||
return sm.State{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package state_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -19,11 +18,9 @@ func TestRollback(t *testing.T) {
|
||||
height int64 = 100
|
||||
nextHeight int64 = 101
|
||||
)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
blockStore := &mocks.BlockStore{}
|
||||
stateStore := setupStateStore(ctx, t, height)
|
||||
stateStore := setupStateStore(t, height)
|
||||
initialState, err := stateStore.Load()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -83,10 +80,7 @@ func TestRollbackNoState(t *testing.T) {
|
||||
func TestRollbackNoBlocks(t *testing.T) {
|
||||
const height = int64(100)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
stateStore := setupStateStore(ctx, t, height)
|
||||
stateStore := setupStateStore(t, height)
|
||||
blockStore := &mocks.BlockStore{}
|
||||
blockStore.On("Height").Return(height)
|
||||
blockStore.On("LoadBlockMeta", height-1).Return(nil)
|
||||
@@ -98,11 +92,7 @@ func TestRollbackNoBlocks(t *testing.T) {
|
||||
|
||||
func TestRollbackDifferentStateHeight(t *testing.T) {
|
||||
const height = int64(100)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
stateStore := setupStateStore(ctx, t, height)
|
||||
stateStore := setupStateStore(t, height)
|
||||
blockStore := &mocks.BlockStore{}
|
||||
blockStore.On("Height").Return(height + 2)
|
||||
|
||||
@@ -111,9 +101,9 @@ func TestRollbackDifferentStateHeight(t *testing.T) {
|
||||
require.Equal(t, err.Error(), "statestore height (100) is not one below or equal to blockstore height (102)")
|
||||
}
|
||||
|
||||
func setupStateStore(ctx context.Context, t *testing.T, height int64) state.Store {
|
||||
func setupStateStore(t *testing.T, height int64) state.Store {
|
||||
stateStore := state.NewStore(dbm.NewMemDB())
|
||||
valSet, _ := factory.RandValidatorSet(ctx, t, 5, 10)
|
||||
valSet, _ := factory.ValidatorSet(t, 5, 10)
|
||||
|
||||
params := types.DefaultConsensusParams()
|
||||
params.Version.AppVersion = 10
|
||||
|
||||
@@ -3,6 +3,7 @@ package state_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -27,16 +28,13 @@ const (
|
||||
)
|
||||
|
||||
func TestStoreBootstrap(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
stateDB := dbm.NewMemDB()
|
||||
stateStore := sm.NewStore(stateDB)
|
||||
val, _, err := factory.RandValidator(ctx, true, 10)
|
||||
val, _, err := factory.Validator(10 + int64(rand.Uint32()))
|
||||
require.NoError(t, err)
|
||||
val2, _, err := factory.RandValidator(ctx, true, 10)
|
||||
val2, _, err := factory.Validator(10 + int64(rand.Uint32()))
|
||||
require.NoError(t, err)
|
||||
val3, _, err := factory.RandValidator(ctx, true, 10)
|
||||
val3, _, err := factory.Validator(10 + int64(rand.Uint32()))
|
||||
require.NoError(t, err)
|
||||
vals := types.NewValidatorSet([]*types.Validator{val, val2, val3})
|
||||
bootstrapState := makeRandomStateFromValidatorSet(vals, 100, 100)
|
||||
@@ -58,16 +56,13 @@ func TestStoreBootstrap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStoreLoadValidators(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
stateDB := dbm.NewMemDB()
|
||||
stateStore := sm.NewStore(stateDB)
|
||||
val, _, err := factory.RandValidator(ctx, true, 10)
|
||||
val, _, err := factory.Validator(10 + int64(rand.Uint32()))
|
||||
require.NoError(t, err)
|
||||
val2, _, err := factory.RandValidator(ctx, true, 10)
|
||||
val2, _, err := factory.Validator(10 + int64(rand.Uint32()))
|
||||
require.NoError(t, err)
|
||||
val3, _, err := factory.RandValidator(ctx, true, 10)
|
||||
val3, _, err := factory.Validator(10 + int64(rand.Uint32()))
|
||||
require.NoError(t, err)
|
||||
vals := types.NewValidatorSet([]*types.Validator{val, val2, val3})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user