appdatasim

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package appdatasim contains utilities for simulating valid streams of app data for testing indexer implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiffAppData

func DiffAppData(expected, actual view.AppData) string

DiffAppData compares the app data of two objects that implement HasAppData. This can be used by indexer to compare their state with the Simulator state if the indexer implements HasAppData. It returns a human-readable diff if the app data differs and the empty string if they are the same.

Types

type BlockData

type BlockData = []appdata.Packet

BlockData represents the app data packets in a block.

type Options

type Options struct {
	// AppSchema is the schema to use. If it is nil, then schematesting.ExampleAppSchema
	// will be used.
	AppSchema map[string]schema.ModuleSchema

	// Listener is the listener to output appdata updates to.
	Listener appdata.Listener

	// StateSimOptions are the options to pass to the statesim.App instance used under
	// the hood.
	StateSimOptions statesim.Options
}

Options are the options for creating an app data simulator.

type Simulator

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

Simulator simulates a stream of app data. Currently, it only simulates InitializeModuleData, OnObjectUpdate, StartBlock and Commit callbacks but others will be added in the future.

func NewSimulator

func NewSimulator(options Options) (*Simulator, error)

NewSimulator creates a new app data simulator with the given options and runs its initialization methods.

func (*Simulator) AppState

func (a *Simulator) AppState() view.AppState

AppState returns the current app state backing the simulator.

func (*Simulator) BlockDataGen

func (a *Simulator) BlockDataGen() *rapid.Generator[BlockData]

BlockDataGen generates random block data. It is expected that generated data is passed to ProcessBlockData to simulate the app data stream and advance app state based on the object updates in the block. The first packet in the block data will be a StartBlockData packet with the height set to the next block height.

func (*Simulator) BlockDataGenN

func (a *Simulator) BlockDataGenN(minUpdatesPerBlock, maxUpdatesPerBlock int) *rapid.Generator[BlockData]

BlockDataGenN creates a block data generator which allows specifying the maximum number of updates per block.

func (*Simulator) BlockNum

func (a *Simulator) BlockNum() (uint64, error)

BlockNum returns the current block number of the simulator.

func (*Simulator) ProcessBlockData

func (a *Simulator) ProcessBlockData(data BlockData) error

ProcessBlockData processes the given block data, advancing the app state based on the object updates in the block and forwarding all packets to the attached listener. It is expected that the data passed came from BlockDataGen, however, other data can be passed as long as any StartBlockData packet has the height set to the current height + 1.

func (*Simulator) ProcessPacket

func (a *Simulator) ProcessPacket(packet appdata.Packet) error

ProcessPacket processes a single packet, advancing the app state based on the data in the packet, and forwarding the packet to any listener.

Jump to

Keyboard shortcuts

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