reorganize more

This commit is contained in:
rigelrozanski 2018-11-07 11:57:53 -05:00
parent 78c3430bb3
commit ea7a5ea1a8
4 changed files with 43 additions and 43 deletions

View File

@ -44,6 +44,27 @@ type Params struct {
BlockSizeTransitionMatrix TransitionMatrix 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 // Return default simulation parameters
func DefaultParams() Params { func DefaultParams() Params {
return Params{ return Params{

View File

@ -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. // getBlockSize returns a block size as determined from the transition matrix.
// It targets making average block size the provided parameter. The three // It targets making average block size the provided parameter. The three
// states it moves between are: // states it moves between are:

View File

@ -8,13 +8,14 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
) )
// Operation runs a state machine transition, // RandSetup performs the random setup the mock module needs.
// and ensures the transition happened as expected. type RandSetup func(r *rand.Rand, accounts []Account)
// The operation could be running and testing a fuzzed transaction,
// or doing the same for a message. // 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, // For ease of debugging, an operation returns a descriptive message "action",
// an operation returns a descriptive message "action",
// which details what this fuzzed state machine transition actually did. // which details what this fuzzed state machine transition actually did.
// //
// Operations can optionally provide a list of "FutureOperations" to run later // 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)) ( accounts []Account, event func(string)) (
action string, futureOperations []FutureOperation, err error) action string, futureOperations []FutureOperation, err error)
// RandSetup performs the random setup the mock module needs. // FutureOperation is an operation which will be ran at the beginning of the
type RandSetup func(r *rand.Rand, accounts []Account) // provided BlockHeight. If both a BlockHeight and BlockTime are specified, it
// will use the BlockHeight. In the (likely) event that multiple operations
// FutureOperation is an operation which will be ran at the // are queued at the same block height, they will execute in a FIFO pattern.
// 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 { type FutureOperation struct {
BlockHeight int BlockHeight int
BlockTime time.Time BlockTime time.Time

View File

@ -7,10 +7,19 @@ import (
"strings" "strings"
"testing" "testing"
"time" "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 // Pretty-print events as a table
func DisplayEvents(events map[string]uint) { func DisplayEvents(events map[string]uint) {
var keys []string var keys []string
@ -36,22 +45,6 @@ func addLogMessage(testingmode bool, blockLogBuilders []*strings.Builder, height
return func(x string) {} 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 // Creates a function to print out the logs
func logPrinter(testingmode bool, logs []*strings.Builder) func() { func logPrinter(testingmode bool, logs []*strings.Builder) func() {
if testingmode { if testingmode {