simulation

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAllInvariants

func AssertAllInvariants(t *testing.T, app *baseapp.BaseApp, tests []Invariant, log string)

AssertAllInvariants asserts a list of provided invariants against application state

func DisplayEvents

func DisplayEvents(events map[string]uint)

Pretty-print events as a table

func GetMemberOfInitialState

func GetMemberOfInitialState(r *rand.Rand, weights []int) int

GetMemberOfInitialState takes an initial array of weights, of size n. It returns a weighted random number in [0,n).

func RandStringOfLength

func RandStringOfLength(r *rand.Rand, n int) string

Generate a random string of a particular length

func RandomAmount

func RandomAmount(r *rand.Rand, max sdk.Int) sdk.Int

Generate a random amount

func RandomKey

func RandomKey(r *rand.Rand, keys []crypto.PrivKey) crypto.PrivKey

Pick a random key from an array

func RandomRequestBeginBlock

func RandomRequestBeginBlock(t *testing.T, r *rand.Rand, validators map[string]mockValidator, livenessTransitions TransitionMatrix, evidenceFraction float64,
	pastTimes []time.Time, event func(string), header abci.Header, log string) abci.RequestBeginBlock

RandomRequestBeginBlock generates a list of signing validators according to the provided list of validators, signing fraction, and evidence fraction

func Simulate

func Simulate(
	t *testing.T, app *baseapp.BaseApp, appStateFn func(r *rand.Rand, keys []crypto.PrivKey, accs []sdk.AccAddress) json.RawMessage, ops []TestAndRunTx, setups []RandSetup,
	invariants []Invariant, numBlocks int, blockSize int, commit bool,
)

Simulate tests application by sending random messages.

func SimulateFromSeed

func SimulateFromSeed(
	t *testing.T, app *baseapp.BaseApp, appStateFn func(r *rand.Rand, keys []crypto.PrivKey, accs []sdk.AccAddress) json.RawMessage, seed int64, ops []TestAndRunTx, setups []RandSetup,
	invariants []Invariant, numBlocks int, blockSize int, commit bool,
)

SimulateFromSeed tests an application by running the provided operations, testing the provided invariants, but using the provided seed.

Types

type Invariant

type Invariant func(t *testing.T, app *baseapp.BaseApp, log string)

An Invariant is a function which tests a particular invariant. If the invariant has been broken, the function should halt the test and output the log.

func PeriodicInvariant

func PeriodicInvariant(invariant Invariant, period int, offset int) Invariant

PeriodicInvariant returns an Invariant function closure that asserts a given invariant if the mock application's last block modulo the given period is congruent to the given offset.

type RandSetup

type RandSetup func(r *rand.Rand, privKeys []crypto.PrivKey)

RandSetup performs the random setup the mock module needs.

type TestAndRunTx

type TestAndRunTx func(
	t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
	privKeys []crypto.PrivKey, log string, event func(string),
) (action string, err sdk.Error)

TestAndRunTx produces a fuzzed transaction, and ensures the state transition was as expected. It returns a descriptive message "action" about what this fuzzed tx actually did, for ease of debugging.

type TransitionMatrix

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

TransitionMatrix is _almost_ a left stochastic matrix. It is technically not one due to not normalizing the column values. In the future, if we want to find the steady state distribution, it will be quite easy to normalize these values to get a stochastic matrix. Floats aren't currently used as the default due to non-determinism across architectures

func CreateTransitionMatrix

func CreateTransitionMatrix(weights [][]int) (TransitionMatrix, error)

CreateTransitionMatrix creates a transition matrix from the provided weights. TODO: Provide example usage

func (TransitionMatrix) NextState

func (t TransitionMatrix) NextState(r *rand.Rand, i int) int

NextState returns the next state randomly chosen using r, and the weightings provided in the transition matrix.

Jump to

Keyboard shortcuts

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