cosmos-sdk/cmd/gaia/app/invariants.go

41 lines
1.2 KiB
Go
Raw Normal View History

package app
import (
"fmt"
"time"
2018-12-10 06:27:25 -08:00
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation"
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
2019-01-11 12:08:01 -08:00
stakingsim "github.com/cosmos/cosmos-sdk/x/staking/simulation"
)
func (app *GaiaApp) runtimeInvariants() []sdk.Invariant {
return []sdk.Invariant{
banksim.NonnegativeBalanceInvariant(app.accountKeeper),
2019-01-16 13:38:05 -08:00
distrsim.NonNegativeOutstandingInvariant(app.distrKeeper),
stakingsim.SupplyInvariants(app.stakingKeeper, app.feeCollectionKeeper, app.distrKeeper, app.accountKeeper),
2019-01-11 12:08:01 -08:00
stakingsim.NonNegativePowerInvariant(app.stakingKeeper),
}
}
func (app *GaiaApp) assertRuntimeInvariants() {
ctx := app.NewContext(false, abci.Header{Height: app.LastBlockHeight() + 1})
app.assertRuntimeInvariantsOnContext(ctx)
}
func (app *GaiaApp) assertRuntimeInvariantsOnContext(ctx sdk.Context) {
start := time.Now()
invariants := app.runtimeInvariants()
for _, inv := range invariants {
if err := inv(ctx); err != nil {
panic(fmt.Errorf("invariant broken: %s", err))
}
}
end := time.Now()
diff := end.Sub(start)
2019-02-07 17:52:24 -08:00
app.BaseApp.Logger().With("module", "invariants").Info("Asserted all invariants", "duration", diff)
}