Run missing invariants during simulations (#4080)
This commit is contained in:
parent
2cd2289a11
commit
02a0e393c5
1
.pending/improvements/gaia/4080-add-missing-inv
Normal file
1
.pending/improvements/gaia/4080-add-missing-inv
Normal file
@ -0,0 +1 @@
|
||||
#4080 add missing invariants during simulations
|
||||
@ -293,12 +293,7 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
|
||||
}
|
||||
|
||||
func invariants(app *GaiaApp) []sdk.Invariant {
|
||||
return []sdk.Invariant{
|
||||
simulation.PeriodicInvariant(bank.NonnegativeBalanceInvariant(app.accountKeeper), period, 0),
|
||||
simulation.PeriodicInvariant(distr.AllInvariants(app.distrKeeper, app.stakingKeeper), period, 0),
|
||||
simulation.PeriodicInvariant(staking.AllInvariants(app.stakingKeeper, app.feeCollectionKeeper,
|
||||
app.distrKeeper, app.accountKeeper), period, 0),
|
||||
}
|
||||
return simulation.PeriodicInvariants(app.crisisKeeper.Invariants(), period, 0)
|
||||
}
|
||||
|
||||
// Pass this in as an option to use a dbStoreAdapter instead of an IAVLStore for simulation speed.
|
||||
|
||||
@ -39,3 +39,14 @@ func (k *Keeper) RegisterRoute(moduleName, route string, invar sdk.Invariant) {
|
||||
func (k Keeper) Routes() []InvarRoute {
|
||||
return k.routes
|
||||
}
|
||||
|
||||
// Invariants returns all the registered Crisis keeper invariants.
|
||||
func (k Keeper) Invariants() []sdk.Invariant {
|
||||
var invars []sdk.Invariant
|
||||
for _, route := range k.routes {
|
||||
invars = append(invars, route.Invar)
|
||||
}
|
||||
return invars
|
||||
}
|
||||
|
||||
// DONTCOVER
|
||||
|
||||
@ -75,3 +75,19 @@ func PeriodicInvariant(invariant sdk.Invariant, period int, offset int) sdk.Inva
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// PeriodicInvariants returns an array of wrapped Invariants. Where each
|
||||
// invariant function is only executed periodically defined by period and offset.
|
||||
func PeriodicInvariants(invariants []sdk.Invariant, period int, offset int) []sdk.Invariant {
|
||||
var outInvariants []sdk.Invariant
|
||||
for _, invariant := range invariants {
|
||||
outInvariant := func(ctx sdk.Context) error {
|
||||
if int(ctx.BlockHeight())%period == offset {
|
||||
return invariant(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
outInvariants = append(outInvariants, outInvariant)
|
||||
}
|
||||
return outInvariants
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user