2018-11-07 08:00:24 -08:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
|
|
)
|
|
|
|
|
|
|
|
// An Invariant is a function which tests a particular invariant.
|
|
|
|
// If the invariant has been broken, it should return an error
|
|
|
|
// containing a descriptive message about what happened.
|
|
|
|
// The simulator will then halt and print the logs.
|
|
|
|
type Invariant func(app *baseapp.BaseApp) error
|
|
|
|
|
2018-11-07 20:55:48 -08:00
|
|
|
// group of Invarient
|
|
|
|
type Invariants []Invariant
|
2018-11-07 08:00:24 -08:00
|
|
|
|
2018-11-07 20:55:48 -08:00
|
|
|
// assertAll asserts the all invariants against application state
|
|
|
|
func (invs Invariants) assertAll(t *testing.T, app *baseapp.BaseApp,
|
|
|
|
event string, displayLogs func()) {
|
|
|
|
|
|
|
|
for i := 0; i < len(invs); i++ {
|
|
|
|
if err := invs[i](app); err != nil {
|
|
|
|
fmt.Printf("Invariants broken after %s\n%s\n", event, err.Error())
|
2018-11-07 08:00:24 -08:00
|
|
|
displayLogs()
|
|
|
|
t.Fatal()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|