tester

package module
v0.0.0-...-a67bbdc Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

README

turbo-tester

  1. Install solcjs
npm install -g solc@0.8.19
  1. Compile the contract
rm -rf ./compiled
solcjs --bin --abi ./contracts/TicketGame.sol --base-path ./ --include-path ./node_modules/ --output-dir ./compiled/
  1. Generator code
abigen  --abi ./compiled/contracts_TicketGame_sol_TicketGame.abi --bin ./compiled/contracts_TicketGame_sol_TicketGame.bin --pkg gen --type TicketGame --out ./simple/gen/TicketGame.go
  1. Build
make build
  1. Generate
./build/tester gentx --contract=0x476F62693e194C50141c62D818D6112a9a70826a --output ~/Downloads --url http://localhost:8545 --chain-id 1223 --batch-size 1000 --gas-fee-cap 150000 --gas-tip-cap 50000 --gas-limit 200000  --contract-method-params 0x476F62693e194C50141c62D818D6112a9a70826a --contract-method redeem
  1. Start
./build/tester start --contract=0x476F62693e194C50141c62D818D6112a9a70826a --url http://localhost:8545 --chain-id 1223 --batch-size 1000 --gas-fee-cap 150000 --gas-tip-cap 50000 --gas-limit 200000  --run-total-batch 1000 --run-user-num 10  --contract-method-params 0x476F62693e194C50141c62D818D6112a9a70826a --contract-method redeem

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExit = errors.New("exit")

ErrExit is an error that indicates the generator should exit.

Functions

func SaveToCSV

func SaveToCSV(path string, data interface{}) error

SaveToCSV saves the given data to a CSV file at the specified path.

The function takes two parameters: - path: a string representing the directory path where the CSV file will be saved. - data: an interface{} representing the data that will be saved to the CSV file.

The function returns an error if any error occurs during the file operations.

Types

type BatchResult

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

BatchResult represents the result of a batch of transactions.

type CreateTx

type CreateTx func(opts *bind.TransactOpts) (*types.Transaction, error)

CreateTx is a function type that can create or send transactions.

type Option

type Option func(*TxGenerator) *TxGenerator

Option is a function type that can be used to configure the TxGenerator.

func SetBatchSize

func SetBatchSize(batchSize uint64) Option

SetBatchSize sets the batch size for the TxGenerator.

It takes a batchSize parameter of type uint64 and returns an Option.

func SetConcurrent

func SetConcurrent(concurrent bool) Option

SetConcurrent returns an Option function that sets the concurrent flag of a TxGenerator object.

Parameters:

concurrent - a boolean value indicating whether the TxGenerator should be executed concurrently.

Returns:

An Option function that sets the concurrent flag and returns the modified TxGenerator object.

func SetGasFeeCap

func SetGasFeeCap(gasFeeCap *big.Int) Option

SetGasFeeCap sets the gas fee cap for the TxGenerator.

Parameters: - gasFeeCap: A pointer to a big.Int representing the gas fee cap.

Returns: - An Option function that sets the gas fee cap for the TxGenerator.

func SetGasLimit

func SetGasLimit(gasLimit uint64) Option

SetGasLimit sets the gas limit option for the TxGenerator.

func SetGasTipCap

func SetGasTipCap(gasTipCap *big.Int) Option

SetGasTipCap sets the gas tip cap option for the TxGenerator.

gasTipCap: A pointer to a big.Int representing the gas tip cap. Returns: An Option function that sets the gas tip cap for the TxGenerator.

func SetNonce

func SetNonce(nonce int64) Option

SetNonce sets the nonce value for the TxGenerator.

Parameter: - nonce: the nonce value to set.

Return: - *TxGenerator: the updated TxGenerator.

func SetPrivKey

func SetPrivKey(privKey *ecdsa.PrivateKey) Option

SetPrivKey sets the private key for the TxGenerator.

privKey: the private key string. Returns: the TxGenerator with the updated private key.

type Payload

type Payload struct {
	Tx      *types.Transaction `csv:"-"`
	RawTx   string             `csv:"raw_tx"`
	ChainID string             `csv:"chain_id"`
}

Payload is a struct that contains the raw transaction and the chain ID.

type Pool

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

Pool is a pool of goroutines that can be used to execute tasks.

func NewPool

func NewPool(size int, service string) *Pool

NewPool creates a new pool with the specified size.

Parameters: - size: an integer representing the size of the pool.

Returns: - a pointer to a Pool object.

func (*Pool) Close

func (p *Pool) Close()

Close stops the goroutines in the Pool and waits for them to finish.

No parameters. No return types.

func (*Pool) Finish

func (p *Pool) Finish()

Finish waits until all goroutines have finished.

No parameters. No return types.

func (*Pool) Stat

func (p *Pool) Stat() Stat

Stat returns the statistics of the Pool.

It returns a stat struct containing the number of running, waiting, free, and maximum capacity of the Pool, as well as the name of the service associated with the Pool.

func (*Pool) Submit

func (p *Pool) Submit(task func())

Submit submits a task to the pool.

The task parameter is a function that will be executed by the pool. It does not take any parameters and does not return any values.

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue is a wrapper of github.com/eapache/queue/v2.Queue

func NewQueue

func NewQueue[T any]() *Queue[T]

NewQueue creates a new Queue instance.

This function does not take any parameters. It returns a pointer to a Queue[T] object.

func (*Queue[T]) Add

func (q *Queue[T]) Add(v T)

Add adds the given value to the queue.

It takes a single parameter: - v: the value to be added to the queue.

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

func (*Queue[T]) Iterate

func (q *Queue[T]) Iterate(f func(T) bool)

Iterate iterates over the elements of the queue and applies a function to each element.

f: The function to apply to each element of the queue. It takes an element as a parameter and returns a boolean value.

If the function returns true, the element will be removed from the queue. If the function returns false,
the element will not be removed from the queue.

func (*Queue[T]) IterateParallel

func (q *Queue[T]) IterateParallel(f func(T) bool)

IterateParallel iterates over the elements in the queue in parallel and applies a function to each element.

The function `f` is applied to each element in the queue. If the function returns `true`, the element is removed from the queue. The function does not guarantee the order in which the elements are processed.

func (*Queue[T]) Length

func (q *Queue[T]) Length() int

type Result

type Result struct {
	Batch              int64
	TotalFailedTxCount int64
	TotalTxCount       atomic.Int64
	StartTime          time.Time
	EndTime            time.Time
	MinResponseTime    int64
	MaxResponseTime    int64
}

Result represents the result of a transaction.

type SendMode

type SendMode string

SendMode represents the mode of sending transactions.

const (
	// OneByOne represents sending transactions one by one.
	OneByOne SendMode = "oneByOne"
	// Parallel represents sending transactions in parallel.
	Parallel SendMode = "parallel"
	// Segment represents sending transactions in segments.
	Segment SendMode = "segment"
	// Batch represents sending transactions in batches.
	Batch SendMode = "batch"
)

func ParseSendMode

func ParseSendMode(mode string) (SendMode, error)

ParseSendMode parses the input string and returns the corresponding SendMode constant if it matches one of the defined modes. Otherwise, it returns an error.

Parameters: - mode: The input string to be parsed.

Return types: - SendMode: The corresponding SendMode constant. - error: An error if the input string does not match any defined modes.

type Stat

type Stat struct {
	Running int
	Waiting int
	Free    int
	Cap     int
	Name    string
}

Stat is the statistics of the Pool.

type Transactor

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

Transactor is a struct that can be used to send transactions.

func NewTransactor

func NewTransactor(eth *ethclient.Client, maxConcurrentNum int, gen *TxGenerator, enable bool, opts ...TransactorOpts) *Transactor

NewTransactor creates a new Transactor instance.

It takes in an ethclient.Client pointer, a Pool pointer, and a TxGenerator pointer as parameters. It returns a pointer to a Transactor.

func (*Transactor) Exit

func (t *Transactor) Exit()

Exit closes the batch and tallyCh channels, closes the pool, and prints the result.

No parameters. No return type.

func (*Transactor) Run

func (t *Transactor) Run()

Run runs the Transactor.

It starts the producer and consumer goroutines to handle transaction processing. The function waits for a signal on the exit channel. If the signal is received, it prints statistics about the transaction processing, closes the transaction pool, and returns.

func (*Transactor) Stop

func (t *Transactor) Stop()

Stop stops the Transactor.

No parameters. No return types.

type TransactorOpts

type TransactorOpts func(*Transactor) *Transactor

TransactorOpts is a function that takes in a pointer to a Transactor object

func SetEndTime

func SetEndTime(endTime time.Time) TransactorOpts

SetEndTime sets the end time for a TransactorOpts function.

endTime: the end time to be set (int64). Returns: a function that sets the end time for a Transactor (TransactorOpts).

func SetSendMode

func SetSendMode(sendMode SendMode) TransactorOpts

SetSendMode sets the send mode for the TransactorOpts.

Parameters: - sendMode: the send mode to be set.

Returns: - a function that sets the send mode and returns the Transactor.

func SetTotalBatch

func SetTotalBatch(totalBatch int64) TransactorOpts

SetTotalBatch sets the total batch value for the TransactorOpts.

totalBatch: The total batch value to be set. Returns: The modified TransactorOpts.

type TxGenerator

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

TxGenerator generates transactions for the TicketGame contract.

func NewTxGenerator

func NewTxGenerator(
	chainID *big.Int,
	createTx CreateTx,
	pool *Pool,
	options ...Option,
) *TxGenerator

NewTxGenerator initializes a new instance of the TxGenerator struct.

It takes the chainID, createOrSendTx, and pool as parameters. The chainID is a pointer to a big.Int type, representing the chain ID. The createOrSendTx is a function type that can be used to create or send transactions. The pool is a pointer to the Pool struct, representing a transaction pool.

It returns a pointer to the TxGenerator struct.

func (*TxGenerator) BatchGenTxs

func (tg *TxGenerator) BatchGenTxs(sender *ecdsa.PrivateKey, senderNonce *big.Int) ([]*Payload, error)

BatchGenTxs generates a batch of transactions using the given sender's private key, sender's nonce, batch size, and player address.

Parameters: - sender: The sender's private key for signing the transactions. - senderNonce: The nonce value of the sender's account. - batchSize: The number of transactions to generate in the batch. - player: The address of the player to include in the transactions.

Return: - []string: The generated transactions as a slice of strings.

func (*TxGenerator) GenTx

func (tg *TxGenerator) GenTx(sender *ecdsa.PrivateKey, senderNonce *big.Int) (*Payload, error)

GenTx generates a transaction using the provided sender's private key, sender nonce, and player address.

Parameters: - sender: The private key of the sender. - senderNonce: The nonce of the sender. - player: The address of the player.

Returns: - The hexadecimal representation of the generated transaction.

func (*TxGenerator) RandomBatchGenTxs

func (tg *TxGenerator) RandomBatchGenTxs() ([]*Payload, error)

RandomBatchGenTxs generates a batch of random transactions.

It takes in the batchSize parameter, which specifies the number of transactions to generate in the batch. The player parameter is used to specify the address of the player associated with the transactions.

The function returns a slice of strings, which represents the generated transactions.

func (*TxGenerator) RandomGenTx

func (tg *TxGenerator) RandomGenTx() (*Payload, error)

RandomGenTx generates a random transaction for the given player address.

player: the address of the player. Returns: the hex string representation of the generated transaction.

func (*TxGenerator) Run

func (tg *TxGenerator) Run() ([]*Payload, bool, error)

Run runs the TxGenerator.

It generates a batch of transactions based on the TxGenerator's configuration. If the TxGenerator is concurrent, it calls the RandomBatchGenTxs method to generate the transactions. If the TxGenerator has a private key, it calls the BatchGenTxs method to generate the transactions using the private key. If neither of the above conditions are met, it generates a new private key and calls the BatchGenTxs method to generate the transactions. It returns the generated transactions and any error that occurred.

type Verifier

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

Verifier is a struct that verifies the hashes in the queue.

func NewVerifier

func NewVerifier(enable bool, eth *ethclient.Client) *Verifier

NewVerifier creates a new Verifier instance.

enable: a boolean indicating whether the Verifier is enabled. eth: an instance of ethclient.Client used for interacting with the Ethereum blockchain. Returns a pointer to the newly created Verifier instance.

func (*Verifier) Add

func (v *Verifier) Add(hash common.Hash)

Add adds a hash to the Verifier.

The parameter `hash` is the hash to be added to the Verifier.

func (*Verifier) Finish

func (v *Verifier) Finish(total int64) bool

Finish checks if the Verifier has finished processing.

It returns true if the Verifier is not enabled or if the queue length is zero, otherwise it returns false.

func (*Verifier) Start

func (v *Verifier) Start(parallelable bool)

Start verifies the Verifier.

parallelable is a boolean indicating whether the verification is parallelizable. It does not return anything.

Directories

Path Synopsis
cmd
data
db
gen

Jump to

Keyboard shortcuts

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