From ea7a5ea1a85e4c477d76184b8c3419fa567fcba1 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Wed, 7 Nov 2018 11:57:53 -0500 Subject: [PATCH] reorganize more --- x/mock/simulation/params.go | 21 +++++++++++++++++++++ x/mock/simulation/simulate.go | 11 ----------- x/mock/simulation/types.go | 25 +++++++++++-------------- x/mock/simulation/util.go | 29 +++++++++++------------------ 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/x/mock/simulation/params.go b/x/mock/simulation/params.go index 8499e6c118..9c4398c88c 100644 --- a/x/mock/simulation/params.go +++ b/x/mock/simulation/params.go @@ -44,6 +44,27 @@ type Params struct { BlockSizeTransitionMatrix TransitionMatrix } +// getBlockSize returns a block size as determined from the transition matrix. +// It targets making average block size the provided parameter. The three +// states it moves between are: +// - "over stuffed" blocks with average size of 2 * avgblocksize, +// - normal sized blocks, hitting avgBlocksize on average, +// - and empty blocks, with no txs / only txs scheduled from the past. +func getBlockSize(r *rand.Rand, params Params, + lastBlockSizeState, avgBlockSize int) (state, blocksize int) { + // TODO: Make default blocksize transition matrix actually make the average + // blocksize equal to avgBlockSize. + state = params.BlockSizeTransitionMatrix.NextState(r, lastBlockSizeState) + if state == 0 { + blocksize = r.Intn(avgBlockSize * 4) + } else if state == 1 { + blocksize = r.Intn(avgBlockSize * 2) + } else { + blocksize = 0 + } + return state, blocksize +} + // Return default simulation parameters func DefaultParams() Params { return Params{ diff --git a/x/mock/simulation/simulate.go b/x/mock/simulation/simulate.go index 7342a91c15..68e4f8b7b2 100644 --- a/x/mock/simulation/simulate.go +++ b/x/mock/simulation/simulate.go @@ -278,17 +278,6 @@ func createBlockSimulator(testingMode bool, tb testing.TB, t *testing.T, params } } -func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) { - testingMode = false - if _t, ok := tb.(*testing.T); ok { - t = _t - testingMode = true - } else { - b = tb.(*testing.B) - } - return -} - // getBlockSize returns a block size as determined from the transition matrix. // It targets making average block size the provided parameter. The three // states it moves between are: diff --git a/x/mock/simulation/types.go b/x/mock/simulation/types.go index 1014042a71..2789ca6994 100644 --- a/x/mock/simulation/types.go +++ b/x/mock/simulation/types.go @@ -8,13 +8,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// Operation runs a state machine transition, -// and ensures the transition happened as expected. -// The operation could be running and testing a fuzzed transaction, -// or doing the same for a message. +// RandSetup performs the random setup the mock module needs. +type RandSetup func(r *rand.Rand, accounts []Account) + +// Operation runs a state machine transition, and ensures the transition +// happened as expected. The operation could be running and testing a fuzzed +// transaction, or doing the same for a message. // -// For ease of debugging, -// an operation returns a descriptive message "action", +// For ease of debugging, an operation returns a descriptive message "action", // which details what this fuzzed state machine transition actually did. // // Operations can optionally provide a list of "FutureOperations" to run later @@ -23,14 +24,10 @@ type Operation func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []Account, event func(string)) ( action string, futureOperations []FutureOperation, err error) -// RandSetup performs the random setup the mock module needs. -type RandSetup func(r *rand.Rand, accounts []Account) - -// FutureOperation is an operation which will be ran at the -// beginning of the provided BlockHeight. -// If both a BlockHeight and BlockTime are specified, it will use the BlockHeight. -// In the (likely) event that multiple operations are queued at the same -// block height, they will execute in a FIFO pattern. +// FutureOperation is an operation which will be ran at the beginning of the +// provided BlockHeight. If both a BlockHeight and BlockTime are specified, it +// will use the BlockHeight. In the (likely) event that multiple operations +// are queued at the same block height, they will execute in a FIFO pattern. type FutureOperation struct { BlockHeight int BlockTime time.Time diff --git a/x/mock/simulation/util.go b/x/mock/simulation/util.go index 10ed6b3b0b..e115cde249 100644 --- a/x/mock/simulation/util.go +++ b/x/mock/simulation/util.go @@ -7,10 +7,19 @@ import ( "strings" "testing" "time" - - "github.com/cosmos/cosmos-sdk/baseapp" ) +func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) { + testingMode = false + if _t, ok := tb.(*testing.T); ok { + t = _t + testingMode = true + } else { + b = tb.(*testing.B) + } + return +} + // Pretty-print events as a table func DisplayEvents(events map[string]uint) { var keys []string @@ -36,22 +45,6 @@ func addLogMessage(testingmode bool, blockLogBuilders []*strings.Builder, height return func(x string) {} } -// assertAllInvariants asserts a list of provided invariants against -// application state -func assertAllInvariants(t *testing.T, app *baseapp.BaseApp, - invariants []Invariant, where string, displayLogs func()) { - - for i := 0; i < len(invariants); i++ { - err := invariants[i](app) - if err != nil { - fmt.Printf("Invariants broken after %s\n", where) - fmt.Println(err.Error()) - displayLogs() - t.Fatal() - } - } -} - // Creates a function to print out the logs func logPrinter(testingmode bool, logs []*strings.Builder) func() { if testingmode {