2018-07-16 18:25:15 -07:00
|
|
|
package simulation
|
2018-07-06 13:19:11 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
2018-07-16 18:15:50 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2018-07-06 13:19:11 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-08-16 08:36:15 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-07-06 13:19:11 -07:00
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// 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.
|
|
|
|
TestAndRunTx func(
|
2018-07-16 18:15:50 -07:00
|
|
|
t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
|
2018-07-17 16:27:51 -07:00
|
|
|
privKeys []crypto.PrivKey, log string, event func(string),
|
2018-07-06 13:19:11 -07:00
|
|
|
) (action string, err sdk.Error)
|
|
|
|
|
|
|
|
// RandSetup performs the random setup the mock module needs.
|
|
|
|
RandSetup func(r *rand.Rand, privKeys []crypto.PrivKey)
|
|
|
|
|
|
|
|
// 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.
|
2018-07-16 18:15:50 -07:00
|
|
|
Invariant func(t *testing.T, app *baseapp.BaseApp, log string)
|
2018-08-16 08:36:15 -07:00
|
|
|
|
|
|
|
mockValidator struct {
|
|
|
|
val abci.Validator
|
|
|
|
livenessState int
|
|
|
|
}
|
2018-07-06 13:19:11 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func PeriodicInvariant(invariant Invariant, period int, offset int) Invariant {
|
2018-07-16 18:15:50 -07:00
|
|
|
return func(t *testing.T, app *baseapp.BaseApp, log string) {
|
2018-07-06 13:19:11 -07:00
|
|
|
if int(app.LastBlockHeight())%period == offset {
|
|
|
|
invariant(t, app, log)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|