1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package integration
import (
"github.com/dexon-foundation/dexon-consensus-core/blockdb"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
"github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// PrepareValidators setups validators for testing.
func PrepareValidators(
validatorCount int,
networkLatency, proposingLatency LatencyModel) (
apps map[types.ValidatorID]*test.App,
dbs map[types.ValidatorID]blockdb.BlockDatabase,
validators map[types.ValidatorID]*Validator,
err error) {
var (
db blockdb.BlockDatabase
key crypto.PrivateKey
)
apps = make(map[types.ValidatorID]*test.App)
dbs = make(map[types.ValidatorID]blockdb.BlockDatabase)
validators = make(map[types.ValidatorID]*Validator)
gov, err := test.NewGovernance(validatorCount, 700)
if err != nil {
return
}
for vID := range gov.GetValidatorSet() {
apps[vID] = test.NewApp()
if db, err = blockdb.NewMemBackedBlockDB(); err != nil {
return
}
dbs[vID] = db
}
for vID := range gov.GetValidatorSet() {
if key, err = gov.GetPrivateKey(vID); err != nil {
return
}
validators[vID] = NewValidator(
apps[vID],
gov,
dbs[vID],
key,
vID,
networkLatency,
proposingLatency)
}
return
}
// VerifyApps is a helper to check delivery between test.Apps
func VerifyApps(apps map[types.ValidatorID]*test.App) (err error) {
for vFrom, fromApp := range apps {
if err = fromApp.Verify(); err != nil {
return
}
for vTo, toApp := range apps {
if vFrom == vTo {
continue
}
if err = fromApp.Compare(toApp); err != nil {
return
}
}
}
return
}
|