Help us shape the future of Go! Take the 2026 Go Developer Survey

loadtest

package
v0.1.103 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRandomAddress

func GetRandomAddress(randSrc *rand.Rand) *common.Address

GetRandomAddress generates a random Ethereum address.

func LightSummary

func LightSummary(results []Sample, startTime, endTime time.Time, rl *rate.Limiter)

LightSummary prints a quick summary of load test results.

func NewHexwordReader

func NewHexwordReader(randSrc *rand.Rand) io.Reader

NewHexwordReader creates a new hexword reader with the given random source.

func OutputRawBytes

func OutputRawBytes(rawTx []byte) error

OutputRawBytes outputs raw bytes as a 0x-prefixed hex string.

func OutputRawTransaction

func OutputRawTransaction(tx *ethtypes.Transaction) error

OutputRawTransaction outputs a raw signed transaction as hex.

func Run

func Run(ctx context.Context, cfg *config.Config) error

Run is a convenience function that creates a runner, initializes it, and runs the load test. This allows both the main loadtest command and subcommands to use the same entry point.

func SummarizeResults

func SummarizeResults(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client, cfg *config.Config, ap *AccountPool, results []Sample, startBlockNumber, lastBlockNumber uint64) error

SummarizeResults handles the post-load-test summarization.

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

Account represents a single account used by the load test.

func (*Account) Address

func (a *Account) Address() common.Address

Address returns the address of the account.

func (*Account) Nonce

func (a *Account) Nonce() uint64

Nonce returns the current nonce of the account.

func (*Account) PrivateKey

func (a *Account) PrivateKey() *ecdsa.PrivateKey

PrivateKey returns the private key of the account.

type AccountPool

type AccountPool struct {
	// contains filtered or unexported fields
}

AccountPool manages a pool of accounts used for sending transactions.

func NewAccountPool

func NewAccountPool(ctx context.Context, client *ethclient.Client, cfg *AccountPoolConfig) (*AccountPool, error)

NewAccountPool creates a new account pool with the given configuration.

func (*AccountPool) Add

func (ap *AccountPool) Add(ctx context.Context, privateKey *ecdsa.PrivateKey, startNonce *uint64) error

Add adds an account to the pool with the given private key.

func (*AccountPool) AddN

func (ap *AccountPool) AddN(ctx context.Context, privateKeys ...*ecdsa.PrivateKey) error

AddN adds multiple accounts to the pool with the given private keys.

func (*AccountPool) AddRandom

func (ap *AccountPool) AddRandom(ctx context.Context) error

AddRandom adds a random account to the pool.

func (*AccountPool) AddRandomN

func (ap *AccountPool) AddRandomN(ctx context.Context, n uint64) error

AddRandomN adds N random accounts to the pool.

func (*AccountPool) AddReusableNonce

func (ap *AccountPool) AddReusableNonce(ctx context.Context, address common.Address, nonce uint64) error

AddReusableNonce adds a reusable nonce to the account with the given address.

func (*AccountPool) AllAccountsReady

func (ap *AccountPool) AllAccountsReady() (bool, int, int)

AllAccountsReady returns whether all accounts are ready for use.

func (*AccountPool) FundAccounts

func (ap *AccountPool) FundAccounts(ctx context.Context) error

FundAccounts funds all accounts in the pool.

func (*AccountPool) Next

func (ap *AccountPool) Next(ctx context.Context) (Account, error)

Next returns the next account in the pool.

func (*AccountPool) Nonces

func (ap *AccountPool) Nonces(ctx context.Context, onlyUsed bool) *sync.Map

Nonces returns the nonces of all accounts in the pool.

func (*AccountPool) NoncesOf

func (ap *AccountPool) NoncesOf(address common.Address) (startNonce, nonce uint64)

NoncesOf returns the start nonce and current nonce for a given address.

func (*AccountPool) NumberOfPendingTxs

func (ap *AccountPool) NumberOfPendingTxs(ctx context.Context) (uint64, error)

NumberOfPendingTxs returns the difference between the internal nonce and the network pending nonce for all accounts in the pool.

func (*AccountPool) RefreshNonce

func (ap *AccountPool) RefreshNonce(ctx context.Context, address common.Address) error

RefreshNonce refreshes the nonce for the given address.

func (*AccountPool) ReturnFunds

func (ap *AccountPool) ReturnFunds(ctx context.Context) error

ReturnFunds returns funds from all accounts back to the funding account.

func (*AccountPool) SetFundingAmount

func (ap *AccountPool) SetFundingAmount(amount *big.Int)

SetFundingAmount updates the funding amount for the pool.

type AccountPoolConfig

type AccountPoolConfig struct {
	FundingPrivateKey         *ecdsa.PrivateKey
	FundingAmount             *big.Int
	RateLimit                 float64
	EthCallOnly               bool
	RefundRemainingFunds      bool
	CheckBalanceBeforeFunding bool
	LegacyTxMode              bool
	// Gas override settings
	ForceGasPrice         uint64
	ForcePriorityGasPrice uint64
	GasPriceMultiplier    *big.Float
	ChainSupportBaseFee   bool
}

AccountPoolConfig holds configuration for the account pool.

type BlobCommitment

type BlobCommitment struct {
	Blob          [131072]byte // kzg4844.Blob size
	Commitment    [48]byte     // kzg4844.Commitment size
	Proof         [48]byte     // kzg4844.Proof size
	VersionedHash common.Hash
}

BlobCommitment holds blob transaction commitment data.

type BlockSummary

type BlockSummary struct {
	Block     *rpctypes.RawBlockResponse
	Receipts  map[common.Hash]rpctypes.RawTxReceipt
	Latencies map[uint64]time.Duration
}

BlockSummary holds data about a single block's transactions.

type Latency

type Latency struct {
	Min    float64
	Median float64
	Max    float64
}

Latency holds min, median, and max latency values.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner handles the execution of a load test.

func NewRunner

func NewRunner(cfg *config.Config) (*Runner, error)

NewRunner creates a new Runner with the given configuration.

func (*Runner) Close

func (r *Runner) Close()

Close cleans up runner resources.

func (*Runner) GetAccountPool

func (r *Runner) GetAccountPool() *AccountPool

GetAccountPool returns the account pool.

func (*Runner) GetClient

func (r *Runner) GetClient() *ethclient.Client

GetClient returns the ethclient.

func (*Runner) GetConfig

func (r *Runner) GetConfig() *config.Config

GetConfig returns the configuration.

func (*Runner) GetDependencies

func (r *Runner) GetDependencies() *mode.Dependencies

GetDependencies returns the mode dependencies.

func (*Runner) GetResults

func (r *Runner) GetResults() []Sample

GetResults returns all recorded samples.

func (*Runner) Init

func (r *Runner) Init(ctx context.Context) error

Init sets up the runner, including clients and account pool.

func (*Runner) RecordSample

func (r *Runner) RecordSample(goRoutineID, requestID int64, err error, start, end time.Time, nonce uint64)

RecordSample records a load test sample.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run executes the load test.

func (*Runner) SetModes

func (r *Runner) SetModes(m []mode.Runner)

SetModes sets the modes to be used during load testing.

type Sample

type Sample struct {
	GoRoutineID int64
	RequestID   int64
	RequestTime time.Time
	WaitTime    time.Duration
	Receipt     string
	IsError     bool
	Nonce       uint64
}

Sample represents a single load test request/response.

type Summary

type Summary struct {
	BlockNumber uint64
	Time        time.Time
	GasLimit    uint64
	GasUsed     uint64
	NumTx       int
	Utilization float64
	Latencies   Latency
}

Summary holds summary data for a single block.

type SummaryOutput

type SummaryOutput struct {
	Summaries          []Summary
	SuccessfulTx       int64
	TotalTx            int64
	TotalMiningTime    time.Duration
	TotalGasUsed       uint64
	TransactionsPerSec float64
	GasPerSecond       float64
	Latencies          Latency
}

SummaryOutput holds the complete summary output data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL