/
invariants.go
41 lines (33 loc) · 1.04 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
36
37
38
39
40
41
package keeper
// DONTCOVER
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/irisnet/irismod/modules/mt/types"
)
// RegisterInvariants registers all supply invariants
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) {
ir.RegisterRoute(types.ModuleName, "supply", SupplyInvariant(k))
}
// AllInvariants runs all invariants of the MT module.
func AllInvariants(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
return SupplyInvariant(k)(ctx)
}
}
// SupplyInvariant checks that the total amount of MTs on collections matches the total amount owned by addresses
func SupplyInvariant(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
err := types.ValidateGenesis(*k.ExportGenesisState(ctx))
if err != nil {
return sdk.FormatInvariant(
types.ModuleName, "supply",
fmt.Sprintf("MT supply invariants check failed, %s", err.Error()),
), true
}
return sdk.FormatInvariant(
types.ModuleName, "supply",
"MT supply invariants check passed",
), false
}
}