Documentation
¶
Overview ¶
Package appdatasim contains utilities for simulating valid streams of app data for testing indexer implementations.
Index ¶
- func DiffAppData(expected, actual view.AppData) string
- type BlockData
- type Options
- type Simulator
- func (a *Simulator) AppState() view.AppState
- func (a *Simulator) BlockDataGen() *rapid.Generator[BlockData]
- func (a *Simulator) BlockDataGenN(minUpdatesPerBlock, maxUpdatesPerBlock int) *rapid.Generator[BlockData]
- func (a *Simulator) BlockNum() (uint64, error)
- func (a *Simulator) ProcessBlockData(data BlockData) error
- func (a *Simulator) ProcessPacket(packet appdata.Packet) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffAppData ¶
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 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 ¶
NewSimulator creates a new app data simulator with the given options and runs its initialization methods.
func (*Simulator) BlockDataGen ¶
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) ProcessBlockData ¶
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.