mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-16 20:26:12 +00:00
e2e: use more simple strings for generated transactions (#7513)
This commit is contained in:
+8
-3
@@ -10,15 +10,20 @@ const (
|
|||||||
|
|
||||||
// Str constructs a random alphanumeric string of given length
|
// Str constructs a random alphanumeric string of given length
|
||||||
// from math/rand's global default Source.
|
// from math/rand's global default Source.
|
||||||
func Str(length int) string {
|
func Str(length int) string { return buildString(length, mrand.Int63) }
|
||||||
|
|
||||||
|
// StrFromSource produces a random string of a specified length from
|
||||||
|
// the specified random source.
|
||||||
|
func StrFromSource(r *mrand.Rand, length int) string { return buildString(length, r.Int63) }
|
||||||
|
|
||||||
|
func buildString(length int, picker func() int64) string {
|
||||||
if length <= 0 {
|
if length <= 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
chars := make([]byte, 0, length)
|
chars := make([]byte, 0, length)
|
||||||
for {
|
for {
|
||||||
// nolint:gosec // G404: Use of weak random number generator
|
val := picker()
|
||||||
val := mrand.Int63()
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
v := int(val & 0x3f) // rightmost 6 bits
|
v := int(val & 0x3f) // rightmost 6 bits
|
||||||
if v >= 62 { // only 62 characters in strChars
|
if v >= 62 { // only 62 characters in strChars
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er
|
|||||||
KeyType: keyType.Choose(r).(string),
|
KeyType: keyType.Choose(r).(string),
|
||||||
Evidence: evidence.Choose(r).(int),
|
Evidence: evidence.Choose(r).(int),
|
||||||
QueueType: opt["queueType"].(string),
|
QueueType: opt["queueType"].(string),
|
||||||
TxSize: int64(txSize.Choose(r).(int)),
|
TxSize: txSize.Choose(r).(int),
|
||||||
}
|
}
|
||||||
|
|
||||||
var numSeeds, numValidators, numFulls, numLightClients int
|
var numSeeds, numValidators, numFulls, numLightClients int
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ type Manifest struct {
|
|||||||
QueueType string `toml:"queue_type"`
|
QueueType string `toml:"queue_type"`
|
||||||
|
|
||||||
// Number of bytes per tx. Default is 1kb (1024)
|
// Number of bytes per tx. Default is 1kb (1024)
|
||||||
TxSize int64
|
TxSize int
|
||||||
|
|
||||||
// ABCIProtocol specifies the protocol used to communicate with the ABCI
|
// ABCIProtocol specifies the protocol used to communicate with the ABCI
|
||||||
// application: "unix", "tcp", "grpc", or "builtin". Defaults to builtin.
|
// application: "unix", "tcp", "grpc", or "builtin". Defaults to builtin.
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ type Testnet struct {
|
|||||||
KeyType string
|
KeyType string
|
||||||
Evidence int
|
Evidence int
|
||||||
LogLevel string
|
LogLevel string
|
||||||
TxSize int64
|
TxSize int
|
||||||
ABCIProtocol string
|
ABCIProtocol string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||||
e2e "github.com/tendermint/tendermint/test/e2e/pkg"
|
e2e "github.com/tendermint/tendermint/test/e2e/pkg"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
@@ -85,7 +86,7 @@ func Load(ctx context.Context, r *rand.Rand, testnet *e2e.Testnet) error {
|
|||||||
// generation is primarily the result of backpressure from the
|
// generation is primarily the result of backpressure from the
|
||||||
// broadcast transaction, though there is still some timer-based
|
// broadcast transaction, though there is still some timer-based
|
||||||
// limiting.
|
// limiting.
|
||||||
func loadGenerate(ctx context.Context, r *rand.Rand, chTx chan<- types.Tx, txSize int64, networkSize int) {
|
func loadGenerate(ctx context.Context, r *rand.Rand, chTx chan<- types.Tx, txSize int, networkSize int) {
|
||||||
timer := time.NewTimer(0)
|
timer := time.NewTimer(0)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
defer close(chTx)
|
defer close(chTx)
|
||||||
@@ -101,12 +102,7 @@ func loadGenerate(ctx context.Context, r *rand.Rand, chTx chan<- types.Tx, txSiz
|
|||||||
// space, while reduce the size of the data in the app.
|
// space, while reduce the size of the data in the app.
|
||||||
id := r.Int63n(100)
|
id := r.Int63n(100)
|
||||||
|
|
||||||
bz := make([]byte, txSize)
|
tx := types.Tx(fmt.Sprintf("load-%X=%s", id, tmrand.StrFromSource(r, txSize)))
|
||||||
_, err := r.Read(bz)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("failed to read random bytes: %w", err))
|
|
||||||
}
|
|
||||||
tx := types.Tx(fmt.Sprintf("load-%X=%x", id, bz))
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|||||||
Reference in New Issue
Block a user