test: add evidence e2e tests (#5488)

This commit is contained in:
Callum Waters
2020-10-23 16:04:23 +02:00
committed by Erik Grinaker
parent 75879ab1d7
commit dacbfbe1fe
38 changed files with 8869 additions and 44 deletions
+29 -2
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"math/rand"
"sort"
"strconv"
"strings"
e2e "github.com/tendermint/tendermint/test/e2e/pkg"
@@ -39,6 +40,10 @@ var (
"kill": 0.1,
"restart": 0.1,
}
nodeMisbehaviors = weightedChoice{
misbehaviorOption{"double-prevote"}: 1,
misbehaviorOption{}: 9,
}
)
// Generate generates random testnets using the given RNG.
@@ -91,7 +96,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er
nextStartAt := manifest.InitialHeight + 5
quorum := numValidators*2/3 + 1
for i := 1; i <= numValidators; i++ {
startAt := int64(0)
startAt := manifest.InitialHeight
if i > quorum {
startAt = nextStartAt
nextStartAt += 5
@@ -174,7 +179,8 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er
// generating invalid configurations. We do not set Seeds or PersistentPeers
// here, since we need to know the overall network topology and startup
// sequencing.
func generateNode(r *rand.Rand, mode e2e.Mode, startAt int64, forceArchive bool) *e2e.ManifestNode {
func generateNode(
r *rand.Rand, mode e2e.Mode, startAt int64, forceArchive bool) *e2e.ManifestNode {
node := e2e.ManifestNode{
Mode: string(mode),
StartAt: startAt,
@@ -196,6 +202,14 @@ func generateNode(r *rand.Rand, mode e2e.Mode, startAt int64, forceArchive bool)
node.SnapshotInterval = 3
}
if node.Mode == "validator" {
node.Misbehaviors = nodeMisbehaviors.Choose(r).(misbehaviorOption).
atHeight(startAt + 5 + int64(r.Intn(10)))
if len(node.Misbehaviors) != 0 {
node.PrivvalProtocol = "file"
}
}
// If a node which does not persist state also does not retain blocks, randomly
// choose to either persist state or retain all blocks.
if node.PersistInterval != nil && *node.PersistInterval == 0 && node.RetainBlocks > 0 {
@@ -223,3 +237,16 @@ func generateNode(r *rand.Rand, mode e2e.Mode, startAt int64, forceArchive bool)
func ptrUint64(i uint64) *uint64 {
return &i
}
type misbehaviorOption struct {
misbehavior string
}
func (m misbehaviorOption) atHeight(height int64) map[string]string {
misbehaviorMap := make(map[string]string)
if m.misbehavior == "" {
return misbehaviorMap
}
misbehaviorMap[strconv.Itoa(int(height))] = m.misbehavior
return misbehaviorMap
}
+1
View File
@@ -9,6 +9,7 @@ import (
"path/filepath"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/log"
)
+1 -1
View File
@@ -57,7 +57,7 @@ func (uc uniformChoice) Choose(r *rand.Rand) interface{} {
}
// weightedChoice chooses a single random key from a map of keys and weights.
type weightedChoice map[interface{}]uint // nolint:unused
type weightedChoice map[interface{}]uint
func (wc weightedChoice) Choose(r *rand.Rand) interface{} {
total := 0