2019-02-13 15:01:50 -08:00
|
|
|
package types
|
|
|
|
|
2019-07-11 03:56:43 -07:00
|
|
|
import "fmt"
|
|
|
|
|
2019-02-13 15:01:50 -08:00
|
|
|
// An Invariant is a function which tests a particular invariant.
|
2019-07-15 09:56:38 -07:00
|
|
|
// The invariant returns a descriptive message about what happened
|
|
|
|
// and a boolean indicating whether the invariant has been broken.
|
2019-02-13 15:01:50 -08:00
|
|
|
// The simulator will then halt and print the logs.
|
2019-07-11 03:56:43 -07:00
|
|
|
type Invariant func(ctx Context) (string, bool)
|
2019-02-13 15:01:50 -08:00
|
|
|
|
2019-04-12 15:52:16 -07:00
|
|
|
// Invariants defines a group of invariants
|
2019-02-13 15:01:50 -08:00
|
|
|
type Invariants []Invariant
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-06-06 13:32:38 -07:00
|
|
|
// expected interface for registering invariants
|
|
|
|
type InvariantRegistry interface {
|
2019-05-16 08:25:32 -07:00
|
|
|
RegisterRoute(moduleName, route string, invar Invariant)
|
|
|
|
}
|
2019-07-11 03:56:43 -07:00
|
|
|
|
2019-08-05 11:21:44 -07:00
|
|
|
// FormatInvariant returns a standardized invariant message.
|
|
|
|
func FormatInvariant(module, name, msg string) string {
|
|
|
|
return fmt.Sprintf("%s: %s invariant\n%s\n", module, name, msg)
|
2019-07-11 03:56:43 -07:00
|
|
|
}
|