From b1ba6a44552273605fa77edb84a4ee033751de97 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Fri, 9 Nov 2018 10:31:56 -0500 Subject: [PATCH] add back in PeriodicInvariant --- x/mock/simulation/util.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/x/mock/simulation/util.go b/x/mock/simulation/util.go index f10364aaaa..df2b6dae44 100644 --- a/x/mock/simulation/util.go +++ b/x/mock/simulation/util.go @@ -7,6 +7,8 @@ import ( "strings" "testing" "time" + + "github.com/cosmos/cosmos-sdk/baseapp" ) func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) { @@ -102,3 +104,19 @@ func getBlockSize(r *rand.Rand, params Params, } return state, blocksize } + +// PeriodicInvariant returns an Invariant function closure that asserts a given +// invariant if the mock application's last block modulo the given period is +// congruent to the given offset. +// +// NOTE this function is intended to be used manually used while running +// computationally heavy simulations. +// TODO reference this function in the codebase probably through use of a switch +func PeriodicInvariant(invariant Invariant, period int, offset int) Invariant { + return func(app *baseapp.BaseApp) error { + if int(app.LastBlockHeight())%period == offset { + return invariant(app) + } + return nil + } +}