Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions x/bank/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

// RegisterInvariants registers the bank module invariants
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) {
ir.RegisterRoute(types.ModuleName, "nonnegative-outstanding", NonnegativeBalanceInvariant(k))
ir.RegisterRoute(types.ModuleName, "total-supply", TotalSupply(k))
}

// AllInvariants runs all invariants of the X/bank module.
func AllInvariants(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
return TotalSupply(k)(ctx)
}
}

// NonnegativeBalanceInvariant checks that all accounts in the application have non-negative balances
func NonnegativeBalanceInvariant(k ViewKeeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
var (
msg string
count int
)

k.IterateAllBalances(ctx, func(addr sdk.AccAddress, balance sdk.Coin) bool {
if balance.IsNegative() {
count++
msg += fmt.Sprintf("\t%s has a negative balance of %s\n", addr, balance)
}

return false
})
k.IterateAllWeiBalances(ctx, func(addr sdk.AccAddress, balance sdk.Int) bool {
if balance.IsNegative() {
count++
msg += fmt.Sprintf("\t%s has a negative wei balance of %s\n", addr, balance)
}

return false
})

broken := count != 0

return sdk.FormatInvariant(
types.ModuleName, "nonnegative-outstanding",
fmt.Sprintf("amount of negative balances found %d\n%s", count, msg),
), broken
}
}

// TotalSupply checks that the total supply reflects all the coins held in accounts
func TotalSupply(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
Expand Down
4 changes: 1 addition & 3 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.Acc
func (AppModule) Name() string { return types.ModuleName }

// RegisterInvariants registers the bank module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
keeper.RegisterInvariants(ir, am.keeper)
}
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}

// Route returns the message routing key for the bank module.
func (am AppModule) Route() sdk.Route {
Expand Down
162 changes: 0 additions & 162 deletions x/distribution/keeper/invariants.go

This file was deleted.

4 changes: 1 addition & 3 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ func (AppModule) Name() string {
}

// RegisterInvariants registers the distribution module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
keeper.RegisterInvariants(ir, am.keeper)
}
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}

// Route returns the message routing key for the distribution module.
func (am AppModule) Route() sdk.Route {
Expand Down
4 changes: 1 addition & 3 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ func (AppModule) Name() string {
}

// RegisterInvariants registers module invariants
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
keeper.RegisterInvariants(ir, am.keeper, am.bankKeeper)
}
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}

// Route returns the message routing key for the gov module.
func (am AppModule) Route() sdk.Route {
Expand Down
Loading
Loading