scenario

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoClients = errors.New("no clients available")
	ErrNoWallet  = errors.New("no wallet available")
)
View Source
var GlobalSlotDuration time.Duration = 12 * time.Second

GlobalSlotDuration is the global setting for slot/block duration used in rate limiting. This can be set via CLI flag (--slot-duration) and applies to all scenarios. For L1 chains, this is typically 12s. For L2s like Arbitrum, it can be 250ms or less.

Functions

func GetScenarioValidFields added in v1.1.7

func GetScenarioValidFields(descriptor *Descriptor) map[string]FieldInfo

GetScenarioValidFields returns the valid fields for a scenario by extracting them from the scenario descriptor

func ParseAndValidateConfig added in v1.1.7

func ParseAndValidateConfig(descriptor *Descriptor, configYAML string, target interface{}, logger logrus.FieldLogger) error

ParseAndValidateConfig is a generalized helper that validates and parses YAML config for any scenario

func RunTransactionScenario

func RunTransactionScenario(ctx context.Context, options TransactionScenarioOptions) error

RunTransactionScenario executes a controlled transaction scenario with rate limiting and concurrency management. It processes transactions according to the specified options until either context cancellation or reaching TotalCount (if > 0).

Features: - Rate-limited execution based on Throughput - Optional dynamic throughput increases - Concurrency control via MaxPending - Sequential logging via transaction chaining

Returns an error only if the scenario cannot be started. Transaction failures should be handled within ProcessNextTxFn.

func ValidateScenarioConfig added in v1.1.7

func ValidateScenarioConfig(descriptor *Descriptor, configYAML string, logger logrus.FieldLogger) error

ValidateScenarioConfig validates configuration for a scenario using reflection-based field extraction

Types

type Category added in v1.1.16

type Category struct {
	Name        string
	Description string
	Descriptors []*Descriptor
	Children    []*Category
}

Category describes the category of a scenario.

type ConfigValidator added in v1.1.7

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

ConfigValidator provides validation for scenario configurations

func NewConfigValidator added in v1.1.7

func NewConfigValidator(scenarioName string, validFields map[string]FieldInfo, logger logrus.FieldLogger) *ConfigValidator

NewConfigValidator creates a new configuration validator for a specific scenario

func (*ConfigValidator) ValidateConfig added in v1.1.7

func (cv *ConfigValidator) ValidateConfig(configYAML string) *ValidationResult

ValidateConfig validates a YAML configuration against the scenario's valid fields

type Descriptor

type Descriptor struct {
	Name           string
	Aliases        []string
	Description    string
	DefaultOptions any
	NewScenario    func(logger logrus.FieldLogger) Scenario
}

Descriptor describes a scenario.

type FieldInfo added in v1.1.7

type FieldInfo struct {
	Type         reflect.Type
	DefaultValue interface{}
	Description  string
}

FieldInfo contains metadata about a valid configuration field

type Options

type Options struct {
	WalletPool *spamoor.WalletPool
	Config     string
	GlobalCfg  map[string]any
	PluginPath string // Path to plugin resources (empty for native scenarios)
}

Options contains the options for the scenario initialization.

type PluginDescriptor added in v1.2.0

type PluginDescriptor struct {
	Name        string
	Description string
	Categories  []*Category
}

PluginDescriptor describes a plugin.

func (*PluginDescriptor) GetAllScenarios added in v1.2.0

func (p *PluginDescriptor) GetAllScenarios() []*Descriptor

GetAllScenarios returns all scenario descriptors from all categories (flattened).

type ProcessNextTxParams added in v1.1.10

type ProcessNextTxParams struct {
	TxIdx           uint64
	OrderedLogCb    func(logFunc func()) // Optional callback to log transaction results in order
	NotifySubmitted func()               // Optional callback to notify that the transaction has been submitted
}

type ReceiptChan added in v1.1.10

type ReceiptChan chan *types.Receipt

func (ReceiptChan) Wait added in v1.1.10

func (rc ReceiptChan) Wait(ctx context.Context) (*types.Receipt, error)

type Registry added in v1.2.0

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

Registry manages scenario registration with protection for native scenarios.

func NewRegistry added in v1.2.0

func NewRegistry(nativeDescriptors []*Descriptor) *Registry

NewRegistry creates a new Registry with the given native scenario descriptors.

func (*Registry) Get added in v1.2.0

func (r *Registry) Get(name string) *ScenarioEntry

Get retrieves a scenario entry by name or alias.

func (*Registry) GetAll added in v1.2.0

func (r *Registry) GetAll() []*Descriptor

GetAll returns all registered scenario descriptors.

func (*Registry) GetDescriptor added in v1.2.0

func (r *Registry) GetDescriptor(name string) *Descriptor

GetDescriptor retrieves just the scenario descriptor by name or alias.

func (*Registry) GetNames added in v1.2.0

func (r *Registry) GetNames() []string

GetNames returns all registered scenario names.

func (*Registry) GetPluginScenarios added in v1.2.0

func (r *Registry) GetPluginScenarios() []*ScenarioEntry

GetPluginScenarios returns all scenario entries that are from plugins.

func (*Registry) IsNative added in v1.2.0

func (r *Registry) IsNative(name string) bool

IsNative returns true if the scenario name is a native (built-in) scenario.

func (*Registry) Register added in v1.2.0

func (r *Registry) Register(entry *ScenarioEntry) (*ScenarioEntry, error)

Register adds or replaces a scenario in the registry. Returns an error if attempting to override a native scenario. Returns the old entry if one was replaced.

func (*Registry) Remove added in v1.2.0

func (r *Registry) Remove(name string) (*ScenarioEntry, error)

Remove removes a scenario from the registry and returns the old entry. Returns an error if attempting to remove a native scenario.

type Scenario

type Scenario interface {
	// Flags registers the scenario's flags with the given flag set.
	Flags(flags *pflag.FlagSet) error
	// Init initializes the scenario with the given options.
	Init(options *Options) error
	// Run runs the scenario.
	Run(ctx context.Context) error
}

type ScenarioEntry added in v1.2.0

type ScenarioEntry struct {
	Descriptor *Descriptor
	Source     ScenarioSource
	Plugin     ScenarioPlugin // nil for native scenarios
}

ScenarioEntry wraps a scenario descriptor with metadata about its source.

type ScenarioPlugin added in v1.2.0

type ScenarioPlugin interface {
	GetName() string
	GetDescription() string
	AddRunning()
	RemoveRunning()
}

ScenarioPlugin represents the minimal interface needed to track plugin state. This interface is implemented by plugin.LoadedPlugin to avoid circular dependencies.

type ScenarioSource added in v1.2.0

type ScenarioSource int

ScenarioSource indicates whether a scenario is native or from a plugin.

const (
	// ScenarioSourceNative indicates a built-in scenario.
	ScenarioSourceNative ScenarioSource = iota
	// ScenarioSourcePlugin indicates a scenario loaded from a plugin.
	ScenarioSourcePlugin
)

type TransactionScenarioOptions

type TransactionScenarioOptions struct {
	TotalCount                  uint64
	Throughput                  uint64
	MaxPending                  uint64
	ThroughputIncrementInterval uint64
	Timeout                     time.Duration // Maximum duration for scenario execution (0 = no timeout)
	WalletPool                  *spamoor.WalletPool
	NoAwaitTransactions         bool // If true, the scenario will not wait for transactions to be included in a block

	// Logger for scenario execution information
	Logger *logrus.Entry

	// ProcessNextTxFn handles transaction execution with the given index
	// It should return:
	// - A callback function to log transaction results (can be nil)
	// - An error if transaction creation failed
	ProcessNextTxFn func(ctx context.Context, params *ProcessNextTxParams) error
}

TransactionScenarioOptions configures how the transaction scenario is executed.

type ValidationResult added in v1.1.7

type ValidationResult struct {
	Valid    bool
	Errors   []string
	Warnings []string
}

ValidationResult contains the results of configuration validation

Jump to

Keyboard shortcuts

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