github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/simulation/util.go (about) 1 package simulation 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "math/rand" 7 "testing" 8 ) 9 10 func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) { 11 testingMode = false 12 if _t, ok := tb.(*testing.T); ok { 13 t = _t 14 testingMode = true 15 } else { 16 b = tb.(*testing.B) 17 } 18 return testingMode, t, b 19 } 20 21 // getBlockSize returns a block size as determined from the transition matrix. 22 // It targets making average block size the provided parameter. The three 23 // states it moves between are: 24 // - "over stuffed" blocks with average size of 2 * avgblocksize, 25 // - normal sized blocks, hitting avgBlocksize on average, 26 // - and empty blocks, with no txs / only txs scheduled from the past. 27 func getBlockSize(r *rand.Rand, params Params, lastBlockSizeState, avgBlockSize int) (state, blockSize int) { 28 // TODO: Make default blocksize transition matrix actually make the average 29 // blocksize equal to avgBlockSize. 30 state = params.BlockSizeTransitionMatrix.NextState(r, lastBlockSizeState) 31 32 switch state { 33 case 0: 34 blockSize = r.Intn(avgBlockSize * 4) 35 36 case 1: 37 blockSize = r.Intn(avgBlockSize * 2) 38 39 default: 40 blockSize = 0 41 } 42 43 return state, blockSize 44 } 45 46 func mustMarshalJSONIndent(o interface{}) []byte { 47 bz, err := json.MarshalIndent(o, "", " ") 48 if err != nil { 49 panic(fmt.Sprintf("failed to JSON encode: %s", err)) 50 } 51 52 return bz 53 }