@@ -7,13 +7,13 @@ SPDX-License-Identifier: Apache-2.0
7
7
package statebased
8
8
9
9
import (
10
+ crand "crypto/rand"
10
11
"fmt"
11
- "math/rand"
12
+ "math/rand/v2 "
12
13
"runtime"
13
14
"strconv"
14
15
"sync"
15
16
"testing"
16
- "time"
17
17
18
18
"github.com/hyperledger/fabric-protos-go/ledger/rwset"
19
19
"github.com/hyperledger/fabric-protos-go/ledger/rwset/kvrwset"
@@ -169,8 +169,8 @@ func pvtRwsetUpdatingMetadataFor(cc, coll, key string) []byte {
169
169
})
170
170
}
171
171
172
- func runFunctions (t * testing.T , seed int64 , funcs ... func ()) {
173
- r := rand .New (rand .NewSource (seed ))
172
+ func runFunctions (t * testing.T , seed [ 32 ] byte , funcs ... func ()) {
173
+ r := rand .New (rand .NewChaCha8 (seed ))
174
174
c := make (chan struct {})
175
175
for _ , i := range r .Perm (len (funcs )) {
176
176
iLcl := i
@@ -186,7 +186,8 @@ func runFunctions(t *testing.T, seed int64, funcs ...func()) {
186
186
187
187
func TestTranslatorBadPolicy (t * testing.T ) {
188
188
t .Parallel ()
189
- seed := time .Now ().Unix ()
189
+ var seed [32 ]byte
190
+ _ , _ = crand .Read (seed [:])
190
191
191
192
// Scenario: we verify that translation from SignaturePolicyEnvelope to ApplicationPolicy fails appropriately
192
193
@@ -226,7 +227,8 @@ func TestTranslatorBadPolicy(t *testing.T) {
226
227
227
228
func TestTranslatorBadPolicyPvt (t * testing.T ) {
228
229
t .Parallel ()
229
- seed := time .Now ().Unix ()
230
+ var seed [32 ]byte
231
+ _ , _ = crand .Read (seed [:])
230
232
231
233
// Scenario: we verify that translation from SignaturePolicyEnvelope to ApplicationPolicy fails appropriately with private data
232
234
@@ -266,7 +268,8 @@ func TestTranslatorBadPolicyPvt(t *testing.T) {
266
268
267
269
func TestDependencyNoConflict (t * testing.T ) {
268
270
t .Parallel ()
269
- seed := time .Now ().Unix ()
271
+ var seed [32 ]byte
272
+ _ , _ = crand .Read (seed [:])
270
273
271
274
// Scenario: validation parameter is retrieved successfully
272
275
// for a ledger key for transaction (1,1) after waiting for
@@ -309,7 +312,8 @@ func TestDependencyNoConflict(t *testing.T) {
309
312
310
313
func TestDependencyConflict (t * testing.T ) {
311
314
t .Parallel ()
312
- seed := time .Now ().Unix ()
315
+ var seed [32 ]byte
316
+ _ , _ = crand .Read (seed [:])
313
317
314
318
// Scenario: validation parameter is retrieved
315
319
// for a ledger key for transaction (1,1) after waiting for
@@ -353,7 +357,8 @@ func TestDependencyConflict(t *testing.T) {
353
357
354
358
func TestMultipleDependencyNoConflict (t * testing.T ) {
355
359
t .Parallel ()
356
- seed := time .Now ().Unix ()
360
+ var seed [32 ]byte
361
+ _ , _ = crand .Read (seed [:])
357
362
358
363
// Scenario: validation parameter is retrieved successfully
359
364
// for a ledger key for transaction (1,2) after waiting for
@@ -402,7 +407,8 @@ func TestMultipleDependencyNoConflict(t *testing.T) {
402
407
403
408
func TestMultipleDependencyConflict (t * testing.T ) {
404
409
t .Parallel ()
405
- seed := time .Now ().Unix ()
410
+ var seed [32 ]byte
411
+ _ , _ = crand .Read (seed [:])
406
412
407
413
// Scenario: validation parameter is retrieved
408
414
// for a ledger key for transaction (1,2) after waiting for
@@ -452,7 +458,8 @@ func TestMultipleDependencyConflict(t *testing.T) {
452
458
453
459
func TestPvtDependencyNoConflict (t * testing.T ) {
454
460
t .Parallel ()
455
- seed := time .Now ().Unix ()
461
+ var seed [32 ]byte
462
+ _ , _ = crand .Read (seed [:])
456
463
457
464
// Scenario: like TestDependencyNoConflict but for private data
458
465
@@ -490,7 +497,8 @@ func TestPvtDependencyNoConflict(t *testing.T) {
490
497
491
498
func TestPvtDependencyConflict (t * testing.T ) {
492
499
t .Parallel ()
493
- seed := time .Now ().Unix ()
500
+ var seed [32 ]byte
501
+ _ , _ = crand .Read (seed [:])
494
502
495
503
// Scenario: like TestDependencyConflict but for private data
496
504
@@ -553,7 +561,8 @@ func TestBlockValidationTerminatesBeforeNewBlock(t *testing.T) {
553
561
554
562
func TestLedgerErrors (t * testing.T ) {
555
563
t .Parallel ()
556
- seed := time .Now ().Unix ()
564
+ var seed [32 ]byte
565
+ _ , _ = crand .Read (seed [:])
557
566
558
567
// Scenario: we check that if a ledger error occurs,
559
568
// GetValidationParameterForKey returns an error
@@ -625,7 +634,8 @@ func TestLedgerErrors(t *testing.T) {
625
634
626
635
func TestBadRwsetIsNoDependency (t * testing.T ) {
627
636
t .Parallel ()
628
- seed := time .Now ().Unix ()
637
+ var seed [32 ]byte
638
+ _ , _ = crand .Read (seed [:])
629
639
630
640
// Scenario: a transaction has a bogus read-write set.
631
641
// While the transaction will fail eventually, we check
@@ -663,7 +673,8 @@ func TestBadRwsetIsNoDependency(t *testing.T) {
663
673
664
674
func TestWritesIntoDifferentNamespaces (t * testing.T ) {
665
675
t .Parallel ()
666
- seed := time .Now ().Unix ()
676
+ var seed [32 ]byte
677
+ _ , _ = crand .Read (seed [:])
667
678
668
679
// Scenario: transaction (1,0) writes to namespace cc1.
669
680
// Transaction (1,1) attempts to retrieve validation
@@ -701,7 +712,8 @@ func TestWritesIntoDifferentNamespaces(t *testing.T) {
701
712
702
713
func TestCombinedCalls (t * testing.T ) {
703
714
t .Parallel ()
704
- seed := time .Now ().Unix ()
715
+ var seed [32 ]byte
716
+ _ , _ = crand .Read (seed [:])
705
717
706
718
// Scenario: transaction (1,3) requests validation parameters
707
719
// for different keys - one succeeds and one fails.
@@ -760,7 +772,8 @@ func TestCombinedCalls(t *testing.T) {
760
772
}
761
773
762
774
func TestForRaces (t * testing.T ) {
763
- seed := time .Now ().Unix ()
775
+ var seed [32 ]byte
776
+ _ , _ = crand .Read (seed [:])
764
777
765
778
// scenario to stress test the parallel validation
766
779
// this is an extended combined test
0 commit comments