mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 07:53:47 +00:00
use crypto rand
This commit is contained in:
parent
9d975fb833
commit
e5fcab70d2
1 changed files with 9 additions and 8 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
package bor
|
package bor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"crypto/rand"
|
||||||
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"pgregory.net/rapid"
|
"pgregory.net/rapid"
|
||||||
|
|
@ -129,16 +129,17 @@ func TestGetSignerSuccessionNumber_SignerNotFound(t *testing.T) {
|
||||||
|
|
||||||
// nolint: unparam
|
// nolint: unparam
|
||||||
func buildRandomValidatorSet(numVals int) []*valset.Validator {
|
func buildRandomValidatorSet(numVals int) []*valset.Validator {
|
||||||
rand.Seed(time.Now().Unix())
|
|
||||||
|
|
||||||
validators := make([]*valset.Validator, numVals)
|
validators := make([]*valset.Validator, numVals)
|
||||||
valAddrs := randomAddresses(numVals)
|
valAddrs := randomAddresses(numVals)
|
||||||
|
|
||||||
for i := 0; i < numVals; i++ {
|
for i := 0; i < numVals; i++ {
|
||||||
|
power, _ := rand.Int(nil, big.NewInt(99))
|
||||||
|
powerN := power.Int64() + 1
|
||||||
|
|
||||||
validators[i] = &valset.Validator{
|
validators[i] = &valset.Validator{
|
||||||
Address: valAddrs[i],
|
Address: valAddrs[i],
|
||||||
// cannot process validators with voting power 0, hence +1
|
// cannot process validators with voting power 0, hence +1
|
||||||
VotingPower: int64(rand.Intn(99) + 1),
|
VotingPower: powerN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,7 +161,7 @@ func randomAddress(exclude ...common.Address) common.Address {
|
||||||
var addr common.Address
|
var addr common.Address
|
||||||
|
|
||||||
for {
|
for {
|
||||||
rand.Read(bytes)
|
_, _ = rand.Read(bytes)
|
||||||
addr = common.BytesToAddress(bytes)
|
addr = common.BytesToAddress(bytes)
|
||||||
|
|
||||||
if _, ok := excl[addr]; ok {
|
if _, ok := excl[addr]; ok {
|
||||||
|
|
@ -187,7 +188,7 @@ func randomAddresses(n int) []common.Address {
|
||||||
bytes := make([]byte, 32)
|
bytes := make([]byte, 32)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
rand.Read(bytes)
|
_, _ = rand.Read(bytes)
|
||||||
|
|
||||||
addr = common.BytesToAddress(bytes)
|
addr = common.BytesToAddress(bytes)
|
||||||
|
|
||||||
|
|
@ -208,7 +209,7 @@ func TestRandomAddresses(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
rapid.Check(t, func(t *rapid.T) {
|
rapid.Check(t, func(t *rapid.T) {
|
||||||
length := rapid.IntMax(100).Draw(t, "length").(int)
|
length := rapid.IntMax(300).Draw(t, "length").(int)
|
||||||
|
|
||||||
addrs := randomAddresses(length)
|
addrs := randomAddresses(length)
|
||||||
addressSet := unique.New(addrs)
|
addressSet := unique.New(addrs)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue