-
Notifications
You must be signed in to change notification settings - Fork 0
/
invariants.go
35 lines (29 loc) · 1.08 KB
/
invariants.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gridironOne/gstake-native/v2/x/lscosmos/types"
)
// RegisterInvariants registers the lscosmos module invariants
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) {
ir.RegisterRoute(types.ModuleName, "c-value-range", CValueRangeInvariant(k))
}
// CValueRangeInvariant checks that if CValue is within module safety range
func CValueRangeInvariant(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
if !k.GetModuleState(ctx) {
return "Module is disabled, cannot check invariant", false
}
cValue := k.GetCValue(ctx)
if !cValue.IsPositive() || cValue.GT(types.MaxCValue) {
return sdk.FormatInvariant(
types.ModuleName, "C-value out of range",
fmt.Sprintf("cValue is expected between %s\n%s, currently is %s", sdk.ZeroDec(), types.MaxCValue, cValue),
), true
}
return sdk.FormatInvariant(
types.ModuleName, "C-value is in range",
fmt.Sprintf("cValue is expected between %s\n%s, currently is %s", sdk.ZeroDec(), types.MaxCValue, cValue),
), false
}
}