2018-11-15 13:21:42 -08:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2018-12-10 06:27:25 -08:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
2018-12-04 10:17:02 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-11-15 13:21:42 -08:00
|
|
|
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"
|
2018-11-15 13:21:42 -08:00
|
|
|
)
|
|
|
|
|
2019-02-13 15:01:50 -08:00
|
|
|
func (app *GaiaApp) runtimeInvariants() []sdk.Invariant {
|
|
|
|
return []sdk.Invariant{
|
2018-11-15 13:21:42 -08:00
|
|
|
banksim.NonnegativeBalanceInvariant(app.accountKeeper),
|
2019-01-16 13:38:05 -08:00
|
|
|
distrsim.NonNegativeOutstandingInvariant(app.distrKeeper),
|
2019-02-13 15:01:50 -08:00
|
|
|
stakingsim.SupplyInvariants(app.stakingKeeper, app.feeCollectionKeeper, app.distrKeeper, app.accountKeeper),
|
2019-01-11 12:08:01 -08:00
|
|
|
stakingsim.NonNegativePowerInvariant(app.stakingKeeper),
|
2018-11-15 13:21:42 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GaiaApp) assertRuntimeInvariants() {
|
2018-11-29 07:17:10 -08:00
|
|
|
ctx := app.NewContext(false, abci.Header{Height: app.LastBlockHeight() + 1})
|
2018-12-04 10:17:02 -08:00
|
|
|
app.assertRuntimeInvariantsOnContext(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *GaiaApp) assertRuntimeInvariantsOnContext(ctx sdk.Context) {
|
|
|
|
start := time.Now()
|
|
|
|
invariants := app.runtimeInvariants()
|
2018-11-15 13:21:42 -08:00
|
|
|
for _, inv := range invariants {
|
2018-11-29 07:17:10 -08:00
|
|
|
if err := inv(ctx); err != nil {
|
2018-11-15 13:21:42 -08:00
|
|
|
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)
|
2018-11-15 13:21:42 -08:00
|
|
|
}
|