Skip to content

Commit

Permalink
add back in PeriodicInvariant
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Nov 9, 2018
1 parent 8a58fdf commit b1ba6a4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions x/mock/simulation/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}

0 comments on commit b1ba6a4

Please sign in to comment.