mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-05 19:40:44 +00:00
factory: simplify validator and genesis factory functions (#7305)
This commit is contained in:
committed by
William Banfield
parent
b20bad14ae
commit
7e17892650
@@ -109,12 +109,9 @@ func TestValidateTrustOptions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClient_SequentialVerification(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
newKeys := genPrivKeys(4)
|
||||
newVals := newKeys.ToValidators(10, 1)
|
||||
differentVals, _ := factory.RandValidatorSet(ctx, t, 10, 100)
|
||||
differentVals, _ := factory.ValidatorSet(t, 10, 100)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
@@ -942,7 +939,7 @@ func TestClient_TrustedValidatorSet(t *testing.T) {
|
||||
|
||||
logger := log.NewTestingLogger(t)
|
||||
|
||||
differentVals, _ := factory.RandValidatorSet(ctx, t, 10, 100)
|
||||
differentVals, _ := factory.ValidatorSet(t, 10, 100)
|
||||
mockBadValSetNode := mockNodeFromHeadersAndVals(
|
||||
map[int64]*types.SignedHeader{
|
||||
1: h1,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -19,9 +18,6 @@ import (
|
||||
)
|
||||
|
||||
func TestLast_FirstLightBlockHeight(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
dbStore := New(dbm.NewMemDB())
|
||||
|
||||
// Empty store
|
||||
@@ -34,7 +30,7 @@ func TestLast_FirstLightBlockHeight(t *testing.T) {
|
||||
assert.EqualValues(t, -1, height)
|
||||
|
||||
// 1 key
|
||||
err = dbStore.SaveLightBlock(randLightBlock(ctx, t, int64(1)))
|
||||
err = dbStore.SaveLightBlock(randLightBlock(t, int64(1)))
|
||||
require.NoError(t, err)
|
||||
|
||||
height, err = dbStore.LastLightBlockHeight()
|
||||
@@ -49,16 +45,13 @@ func TestLast_FirstLightBlockHeight(t *testing.T) {
|
||||
func Test_SaveLightBlock(t *testing.T) {
|
||||
dbStore := New(dbm.NewMemDB())
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Empty store
|
||||
h, err := dbStore.LightBlock(1)
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, h)
|
||||
|
||||
// 1 key
|
||||
err = dbStore.SaveLightBlock(randLightBlock(ctx, t, 1))
|
||||
err = dbStore.SaveLightBlock(randLightBlock(t, 1))
|
||||
require.NoError(t, err)
|
||||
|
||||
size := dbStore.Size()
|
||||
@@ -87,10 +80,7 @@ func Test_LightBlockBefore(t *testing.T) {
|
||||
_, _ = dbStore.LightBlockBefore(100)
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
err := dbStore.SaveLightBlock(randLightBlock(ctx, t, int64(2)))
|
||||
err := dbStore.SaveLightBlock(randLightBlock(t, int64(2)))
|
||||
require.NoError(t, err)
|
||||
|
||||
h, err := dbStore.LightBlockBefore(3)
|
||||
@@ -106,16 +96,13 @@ func Test_LightBlockBefore(t *testing.T) {
|
||||
func Test_Prune(t *testing.T) {
|
||||
dbStore := New(dbm.NewMemDB())
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Empty store
|
||||
assert.EqualValues(t, 0, dbStore.Size())
|
||||
err := dbStore.Prune(0)
|
||||
require.NoError(t, err)
|
||||
|
||||
// One header
|
||||
err = dbStore.SaveLightBlock(randLightBlock(ctx, t, 2))
|
||||
err = dbStore.SaveLightBlock(randLightBlock(t, 2))
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.EqualValues(t, 1, dbStore.Size())
|
||||
@@ -130,7 +117,7 @@ func Test_Prune(t *testing.T) {
|
||||
|
||||
// Multiple headers
|
||||
for i := 1; i <= 10; i++ {
|
||||
err = dbStore.SaveLightBlock(randLightBlock(ctx, t, int64(i)))
|
||||
err = dbStore.SaveLightBlock(randLightBlock(t, int64(i)))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -146,16 +133,13 @@ func Test_Prune(t *testing.T) {
|
||||
func Test_Concurrency(t *testing.T) {
|
||||
dbStore := New(dbm.NewMemDB())
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 1; i <= 100; i++ {
|
||||
wg.Add(1)
|
||||
go func(i int64) {
|
||||
defer wg.Done()
|
||||
|
||||
err := dbStore.SaveLightBlock(randLightBlock(ctx, t, i))
|
||||
err := dbStore.SaveLightBlock(randLightBlock(t, i))
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = dbStore.LightBlock(i)
|
||||
@@ -198,9 +182,8 @@ func Test_Concurrency(t *testing.T) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func randLightBlock(ctx context.Context, t *testing.T, height int64) *types.LightBlock {
|
||||
t.Helper()
|
||||
vals, _ := factory.RandValidatorSet(ctx, t, 2, 1)
|
||||
func randLightBlock(t *testing.T, height int64) *types.LightBlock {
|
||||
vals, _ := factory.ValidatorSet(t, 2, 1)
|
||||
return &types.LightBlock{
|
||||
SignedHeader: &types.SignedHeader{
|
||||
Header: &types.Header{
|
||||
|
||||
Reference in New Issue
Block a user