@@ -7,13 +7,13 @@ SPDX-License-Identifier: Apache-2.0
77package statebased
88
99import (
10+ crand "crypto/rand"
1011 "fmt"
11- "math/rand"
12+ "math/rand/v2 "
1213 "runtime"
1314 "strconv"
1415 "sync"
1516 "testing"
16- "time"
1717
1818 "github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset"
1919 "github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset"
@@ -169,8 +169,8 @@ func pvtRwsetUpdatingMetadataFor(cc, coll, key string) []byte {
169169 })
170170}
171171
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 ))
174174 c := make (chan struct {})
175175 for _ , i := range r .Perm (len (funcs )) {
176176 iLcl := i
@@ -186,7 +186,8 @@ func runFunctions(t *testing.T, seed int64, funcs ...func()) {
186186
187187func TestTranslatorBadPolicy (t * testing.T ) {
188188 t .Parallel ()
189- seed := time .Now ().Unix ()
189+ var seed [32 ]byte
190+ _ , _ = crand .Read (seed [:])
190191
191192 // Scenario: we verify that translation from SignaturePolicyEnvelope to ApplicationPolicy fails appropriately
192193
@@ -226,7 +227,8 @@ func TestTranslatorBadPolicy(t *testing.T) {
226227
227228func TestTranslatorBadPolicyPvt (t * testing.T ) {
228229 t .Parallel ()
229- seed := time .Now ().Unix ()
230+ var seed [32 ]byte
231+ _ , _ = crand .Read (seed [:])
230232
231233 // Scenario: we verify that translation from SignaturePolicyEnvelope to ApplicationPolicy fails appropriately with private data
232234
@@ -266,7 +268,8 @@ func TestTranslatorBadPolicyPvt(t *testing.T) {
266268
267269func TestDependencyNoConflict (t * testing.T ) {
268270 t .Parallel ()
269- seed := time .Now ().Unix ()
271+ var seed [32 ]byte
272+ _ , _ = crand .Read (seed [:])
270273
271274 // Scenario: validation parameter is retrieved successfully
272275 // for a ledger key for transaction (1,1) after waiting for
@@ -309,7 +312,8 @@ func TestDependencyNoConflict(t *testing.T) {
309312
310313func TestDependencyConflict (t * testing.T ) {
311314 t .Parallel ()
312- seed := time .Now ().Unix ()
315+ var seed [32 ]byte
316+ _ , _ = crand .Read (seed [:])
313317
314318 // Scenario: validation parameter is retrieved
315319 // for a ledger key for transaction (1,1) after waiting for
@@ -353,7 +357,8 @@ func TestDependencyConflict(t *testing.T) {
353357
354358func TestMultipleDependencyNoConflict (t * testing.T ) {
355359 t .Parallel ()
356- seed := time .Now ().Unix ()
360+ var seed [32 ]byte
361+ _ , _ = crand .Read (seed [:])
357362
358363 // Scenario: validation parameter is retrieved successfully
359364 // for a ledger key for transaction (1,2) after waiting for
@@ -402,7 +407,8 @@ func TestMultipleDependencyNoConflict(t *testing.T) {
402407
403408func TestMultipleDependencyConflict (t * testing.T ) {
404409 t .Parallel ()
405- seed := time .Now ().Unix ()
410+ var seed [32 ]byte
411+ _ , _ = crand .Read (seed [:])
406412
407413 // Scenario: validation parameter is retrieved
408414 // for a ledger key for transaction (1,2) after waiting for
@@ -452,7 +458,8 @@ func TestMultipleDependencyConflict(t *testing.T) {
452458
453459func TestPvtDependencyNoConflict (t * testing.T ) {
454460 t .Parallel ()
455- seed := time .Now ().Unix ()
461+ var seed [32 ]byte
462+ _ , _ = crand .Read (seed [:])
456463
457464 // Scenario: like TestDependencyNoConflict but for private data
458465
@@ -490,7 +497,8 @@ func TestPvtDependencyNoConflict(t *testing.T) {
490497
491498func TestPvtDependencyConflict (t * testing.T ) {
492499 t .Parallel ()
493- seed := time .Now ().Unix ()
500+ var seed [32 ]byte
501+ _ , _ = crand .Read (seed [:])
494502
495503 // Scenario: like TestDependencyConflict but for private data
496504
@@ -553,7 +561,8 @@ func TestBlockValidationTerminatesBeforeNewBlock(t *testing.T) {
553561
554562func TestLedgerErrors (t * testing.T ) {
555563 t .Parallel ()
556- seed := time .Now ().Unix ()
564+ var seed [32 ]byte
565+ _ , _ = crand .Read (seed [:])
557566
558567 // Scenario: we check that if a ledger error occurs,
559568 // GetValidationParameterForKey returns an error
@@ -625,7 +634,8 @@ func TestLedgerErrors(t *testing.T) {
625634
626635func TestBadRwsetIsNoDependency (t * testing.T ) {
627636 t .Parallel ()
628- seed := time .Now ().Unix ()
637+ var seed [32 ]byte
638+ _ , _ = crand .Read (seed [:])
629639
630640 // Scenario: a transaction has a bogus read-write set.
631641 // While the transaction will fail eventually, we check
@@ -663,7 +673,8 @@ func TestBadRwsetIsNoDependency(t *testing.T) {
663673
664674func TestWritesIntoDifferentNamespaces (t * testing.T ) {
665675 t .Parallel ()
666- seed := time .Now ().Unix ()
676+ var seed [32 ]byte
677+ _ , _ = crand .Read (seed [:])
667678
668679 // Scenario: transaction (1,0) writes to namespace cc1.
669680 // Transaction (1,1) attempts to retrieve validation
@@ -701,7 +712,8 @@ func TestWritesIntoDifferentNamespaces(t *testing.T) {
701712
702713func TestCombinedCalls (t * testing.T ) {
703714 t .Parallel ()
704- seed := time .Now ().Unix ()
715+ var seed [32 ]byte
716+ _ , _ = crand .Read (seed [:])
705717
706718 // Scenario: transaction (1,3) requests validation parameters
707719 // for different keys - one succeeds and one fails.
@@ -760,7 +772,8 @@ func TestCombinedCalls(t *testing.T) {
760772}
761773
762774func TestForRaces (t * testing.T ) {
763- seed := time .Now ().Unix ()
775+ var seed [32 ]byte
776+ _ , _ = crand .Read (seed [:])
764777
765778 // scenario to stress test the parallel validation
766779 // this is an extended combined test
0 commit comments