File tree Expand file tree Collapse file tree 3 files changed +23
-9
lines changed Expand file tree Collapse file tree 3 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
20
20
"bytes"
21
21
crand "crypto/rand"
22
22
"encoding/binary"
23
+ "fmt"
23
24
mrand "math/rand"
24
25
"sort"
25
26
"testing"
@@ -30,6 +31,24 @@ import (
30
31
"github.com/ethereum/go-ethereum/ethdb/memorydb"
31
32
)
32
33
34
+ // Prng is a pseudo random number generator seeded by strong randomness.
35
+ // The randomness is printed on startup in order to make failures reproducible.
36
+ var prng = initRnd ()
37
+
38
+ func initRnd () * mrand.Rand {
39
+ var seed [8 ]byte
40
+ crand .Read (seed [:])
41
+ rnd := mrand .New (mrand .NewSource (int64 (binary .LittleEndian .Uint64 (seed [:]))))
42
+ fmt .Printf ("Seed: %x\n " , seed )
43
+ return rnd
44
+ }
45
+
46
+ func randBytes (n int ) []byte {
47
+ r := make ([]byte , n )
48
+ prng .Read (r )
49
+ return r
50
+ }
51
+
33
52
// makeProvers creates Merkle trie provers based on different implementations to
34
53
// test all variations.
35
54
func makeProvers (trie * Trie ) []func (key []byte ) * memorydb.Database {
@@ -1041,12 +1060,6 @@ func randomTrie(n int) (*Trie, map[string]*kv) {
1041
1060
return trie , vals
1042
1061
}
1043
1062
1044
- func randBytes (n int ) []byte {
1045
- r := make ([]byte , n )
1046
- crand .Read (r )
1047
- return r
1048
- }
1049
-
1050
1063
func nonRandomTrie (n int ) (* Trie , map [string ]* kv ) {
1051
1064
trie := NewEmpty (NewDatabase (rawdb .NewMemoryDatabase ()))
1052
1065
vals := make (map [string ]* kv )
Original file line number Diff line number Diff line change @@ -434,6 +434,7 @@ func TestDuplicateAvoidanceSync(t *testing.T) {
434
434
// Tests that at any point in time during a sync, only complete sub-tries are in
435
435
// the database.
436
436
func TestIncompleteSync (t * testing.T ) {
437
+ t .Parallel ()
437
438
// Create a random trie to copy
438
439
srcDb , srcTrie , _ := makeTestTrie ()
439
440
Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ package trie
18
18
19
19
import (
20
20
"bytes"
21
- crand "crypto/rand"
22
21
"encoding/binary"
23
22
"errors"
24
23
"fmt"
@@ -1146,13 +1145,14 @@ func deleteString(trie *Trie, k string) {
1146
1145
1147
1146
func TestDecodeNode (t * testing.T ) {
1148
1147
t .Parallel ()
1148
+
1149
1149
var (
1150
1150
hash = make ([]byte , 20 )
1151
1151
elems = make ([]byte , 20 )
1152
1152
)
1153
1153
for i := 0 ; i < 5000000 ; i ++ {
1154
- crand .Read (hash )
1155
- crand .Read (elems )
1154
+ prng .Read (hash )
1155
+ prng .Read (elems )
1156
1156
decodeNode (hash , elems )
1157
1157
}
1158
1158
}
You can’t perform that action at this time.
0 commit comments