From 3aff3933ed6db7b910dc3e1f746932fb1bb5b2f9 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 9 Apr 2019 19:01:29 -0400 Subject: [PATCH 1/7] add all invariants --- cmd/gaia/app/sim_test.go | 7 +------ x/crisis/keeper.go | 9 +++++++++ x/simulation/util.go | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index 247cc262a308..8b08e3865124 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -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.PeriodicInvariant(app.crisisKeeper.Invariants(), period, 0) } // Pass this in as an option to use a dbStoreAdapter instead of an IAVLStore for simulation speed. diff --git a/x/crisis/keeper.go b/x/crisis/keeper.go index 8501b08ee072..7c9cbfde0265 100644 --- a/x/crisis/keeper.go +++ b/x/crisis/keeper.go @@ -39,3 +39,12 @@ func (k *Keeper) RegisterRoute(moduleName, route string, invar sdk.Invariant) { func (k Keeper) Routes() []InvarRoute { return k.routes } + +// return all the invariants +func (k Keeper) Invariants() []sdk.Invariant { + var invars []sdk.Invariant + for _, route := range k.routes { + invars = append(invars, route.Invar) + } + return invars +} diff --git a/x/simulation/util.go b/x/simulation/util.go index 3dc75c439044..d66cd7798a7b 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -75,3 +75,18 @@ func PeriodicInvariant(invariant sdk.Invariant, period int, offset int) sdk.Inva return nil } } + +// return an array of PeriodicInvariant +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 +} From 08539995b0804afb2168051e71d58c3e16708706 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 9 Apr 2019 19:04:47 -0400 Subject: [PATCH 2/7] typo --- x/simulation/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/simulation/util.go b/x/simulation/util.go index d66cd7798a7b..480d31e2f675 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -86,7 +86,7 @@ func PeriodicInvariants(invariants []sdk.Invariant, period int, offset int) []sd } return nil } - outInvariants := append(outInvariants, outInvariant) + outInvariants = append(outInvariants, outInvariant) } return outInvariants } From c646867c3110f9b731d0a943c62600c6376dcf6e Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 9 Apr 2019 19:08:46 -0400 Subject: [PATCH 3/7] typox2 --- cmd/gaia/app/sim_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index 8b08e3865124..7c6a2886de46 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -293,7 +293,7 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation { } func invariants(app *GaiaApp) []sdk.Invariant { - return simulation.PeriodicInvariant(app.crisisKeeper.Invariants(), 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. From f5d3ad3a7a1320dcb3e8155ddce4694f5e596a3d Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 9 Apr 2019 20:10:50 -0400 Subject: [PATCH 4/7] changelog --- .pending/improvements/gaia/4080-add-missing-inv | 1 + 1 file changed, 1 insertion(+) create mode 100644 .pending/improvements/gaia/4080-add-missing-inv diff --git a/.pending/improvements/gaia/4080-add-missing-inv b/.pending/improvements/gaia/4080-add-missing-inv new file mode 100644 index 000000000000..48c8172da0a3 --- /dev/null +++ b/.pending/improvements/gaia/4080-add-missing-inv @@ -0,0 +1 @@ +#4080 add missing invariants during simulations \ No newline at end of file From 9fe7adac78d231058274ed764e60f97095c42be2 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 9 Apr 2019 20:51:38 -0400 Subject: [PATCH 5/7] Update x/simulation/util.go --- x/simulation/util.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/simulation/util.go b/x/simulation/util.go index 480d31e2f675..3badf25a9a90 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -76,7 +76,8 @@ func PeriodicInvariant(invariant sdk.Invariant, period int, offset int) sdk.Inva } } -// return an array of PeriodicInvariant +// 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 { From c250b7a91a30feebda4782391c5c25d889665101 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 9 Apr 2019 20:51:47 -0400 Subject: [PATCH 6/7] Update x/crisis/keeper.go --- x/crisis/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/crisis/keeper.go b/x/crisis/keeper.go index 7c9cbfde0265..18eb97215696 100644 --- a/x/crisis/keeper.go +++ b/x/crisis/keeper.go @@ -40,7 +40,7 @@ func (k Keeper) Routes() []InvarRoute { return k.routes } -// return all the invariants +// Invariants returns all the registered Crisis keeper invariants. func (k Keeper) Invariants() []sdk.Invariant { var invars []sdk.Invariant for _, route := range k.routes { From 82796b15e264d35144570b402ba812caccb964c3 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 9 Apr 2019 20:58:19 -0400 Subject: [PATCH 7/7] DONTCOVER x/crisis/keeper.go --- x/crisis/keeper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/crisis/keeper.go b/x/crisis/keeper.go index 7c9cbfde0265..142eccf734c6 100644 --- a/x/crisis/keeper.go +++ b/x/crisis/keeper.go @@ -48,3 +48,5 @@ func (k Keeper) Invariants() []sdk.Invariant { } return invars } + +// DONTCOVER