25 lines
808 B
Go
25 lines
808 B
Go
package types
|
|
|
|
import "fmt"
|
|
|
|
// 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(ctx Context) (string, bool)
|
|
|
|
// Invariants defines a group of invariants
|
|
type Invariants []Invariant
|
|
|
|
// expected interface for registering invariants
|
|
type InvariantRegistry interface {
|
|
RegisterRoute(moduleName, route string, invar Invariant)
|
|
}
|
|
|
|
// FormatInvariant returns a standardized invariant message along with
|
|
// broken boolean.
|
|
func FormatInvariant(module, name, msg string, broken bool) (string, bool) {
|
|
return fmt.Sprintf("%s: %s invariant\n%s\nInvariant Broken: %v\n",
|
|
module, name, msg, broken), broken
|
|
}
|