2018-07-16 18:25:15 -07:00
|
|
|
package simulation
|
2018-07-06 13:19:11 -07:00
|
|
|
|
|
|
|
import (
|
2018-07-17 11:33:53 -07:00
|
|
|
"encoding/json"
|
2018-07-06 13:19:11 -07:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2018-08-29 23:02:15 -07:00
|
|
|
"os"
|
2018-09-08 01:29:24 -07:00
|
|
|
"os/signal"
|
2018-09-11 02:18:58 -07:00
|
|
|
"runtime/debug"
|
2018-09-09 08:34:09 -07:00
|
|
|
"strings"
|
2018-09-08 01:29:24 -07:00
|
|
|
"syscall"
|
2018-07-06 13:19:11 -07:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-08-16 08:36:15 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
2018-07-16 18:15:50 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2018-07-17 15:04:10 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-07-06 13:19:11 -07:00
|
|
|
)
|
|
|
|
|
2019-01-29 14:53:42 -08:00
|
|
|
// AppStateFn returns the app state json bytes, the genesis accounts, and the chain identifier
|
|
|
|
type AppStateFn func(r *rand.Rand, accs []Account, genesisTimestamp time.Time) (appState json.RawMessage, accounts []Account, chainId string)
|
2018-11-07 21:54:12 -08:00
|
|
|
|
2018-07-17 11:33:53 -07:00
|
|
|
// Simulate tests application by sending random messages.
|
2018-09-12 21:53:55 -07:00
|
|
|
func Simulate(t *testing.T, app *baseapp.BaseApp,
|
2018-11-29 07:17:10 -08:00
|
|
|
appStateFn AppStateFn, ops WeightedOperations,
|
2018-11-26 04:21:23 -08:00
|
|
|
invariants Invariants, numBlocks int, blockSize int, commit bool) (bool, error) {
|
2018-09-12 21:53:55 -07:00
|
|
|
|
2018-07-06 13:19:11 -07:00
|
|
|
time := time.Now().UnixNano()
|
2018-11-07 20:26:02 -08:00
|
|
|
return SimulateFromSeed(t, app, appStateFn, time, ops,
|
2018-11-29 07:17:10 -08:00
|
|
|
invariants, numBlocks, blockSize, commit)
|
2018-07-06 13:19:11 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 20:26:02 -08:00
|
|
|
// initialize the chain for the simulation
|
2019-01-17 08:15:13 -08:00
|
|
|
func initChain(
|
|
|
|
r *rand.Rand, params Params, accounts []Account,
|
|
|
|
app *baseapp.BaseApp, appStateFn AppStateFn, genesisTimestamp time.Time,
|
2019-01-29 14:53:42 -08:00
|
|
|
) (mockValidators, []Account) {
|
|
|
|
|
|
|
|
appState, accounts, chainID := appStateFn(r, accounts, genesisTimestamp)
|
2018-11-07 20:26:02 -08:00
|
|
|
|
|
|
|
req := abci.RequestInitChain{
|
2019-01-29 14:53:42 -08:00
|
|
|
AppStateBytes: appState,
|
|
|
|
ChainId: chainID,
|
2018-08-29 23:02:15 -07:00
|
|
|
}
|
2018-11-07 20:26:02 -08:00
|
|
|
res := app.InitChain(req)
|
2018-11-07 22:57:37 -08:00
|
|
|
validators := newMockValidators(r, res.Validators, params)
|
2018-08-29 23:02:15 -07:00
|
|
|
|
2019-01-29 14:53:42 -08:00
|
|
|
return validators, accounts
|
2018-08-29 23:02:15 -07:00
|
|
|
}
|
|
|
|
|
2018-07-17 11:33:53 -07:00
|
|
|
// SimulateFromSeed tests an application by running the provided
|
2018-07-06 13:19:11 -07:00
|
|
|
// operations, testing the provided invariants, but using the provided seed.
|
2018-11-07 21:54:12 -08:00
|
|
|
// TODO split this monster function up
|
2018-09-12 21:53:55 -07:00
|
|
|
func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
|
2018-11-07 21:54:12 -08:00
|
|
|
appStateFn AppStateFn, seed int64, ops WeightedOperations,
|
2018-11-29 07:17:10 -08:00
|
|
|
invariants Invariants,
|
2018-11-26 04:21:23 -08:00
|
|
|
numBlocks int, blockSize int, commit bool) (stopEarly bool, simError error) {
|
2018-09-12 21:53:55 -07:00
|
|
|
|
2018-09-11 02:18:58 -07:00
|
|
|
// in case we have to end early, don't os.Exit so that we can run cleanup code.
|
2018-09-01 12:32:24 -07:00
|
|
|
testingMode, t, b := getTestingMode(tb)
|
2018-11-07 21:12:51 -08:00
|
|
|
fmt.Printf("Starting SimulateFromSeed with randomness "+
|
|
|
|
"created with seed %d\n", int(seed))
|
|
|
|
|
2018-07-06 13:19:11 -07:00
|
|
|
r := rand.New(rand.NewSource(seed))
|
2018-11-04 22:11:03 -08:00
|
|
|
params := RandomParams(r) // := DefaultParams()
|
2018-11-04 20:44:43 -08:00
|
|
|
fmt.Printf("Randomized simulation params: %+v\n", params)
|
2018-11-07 21:12:51 -08:00
|
|
|
|
2019-01-17 08:15:13 -08:00
|
|
|
genesisTimestamp := RandTimestamp(r)
|
2018-11-07 09:19:58 -08:00
|
|
|
fmt.Printf("Starting the simulation from time %v, unixtime %v\n",
|
2019-01-17 08:15:13 -08:00
|
|
|
genesisTimestamp.UTC().Format(time.UnixDate), genesisTimestamp.Unix())
|
2018-11-07 21:12:51 -08:00
|
|
|
|
2018-08-26 18:04:52 -07:00
|
|
|
timeDiff := maxTimePerBlock - minTimePerBlock
|
2018-11-04 20:44:43 -08:00
|
|
|
accs := RandomAccounts(r, params.NumKeys)
|
2018-11-07 21:54:12 -08:00
|
|
|
eventStats := newEventStats()
|
2018-11-07 09:19:58 -08:00
|
|
|
|
2018-11-07 21:54:12 -08:00
|
|
|
// Second variable to keep pending validator set (delayed one block since
|
|
|
|
// TM 0.24) Initially this is the same as the initial validator set
|
2019-01-29 14:53:42 -08:00
|
|
|
validators, accs := initChain(r, params, accs, app, appStateFn, genesisTimestamp)
|
|
|
|
if len(accs) == 0 {
|
|
|
|
return true, fmt.Errorf("must have greater than zero genesis accounts")
|
|
|
|
}
|
|
|
|
|
2018-11-07 22:57:37 -08:00
|
|
|
nextValidators := validators
|
2018-07-06 13:19:11 -07:00
|
|
|
|
2018-11-07 09:19:58 -08:00
|
|
|
header := abci.Header{
|
|
|
|
Height: 1,
|
2019-01-17 08:15:13 -08:00
|
|
|
Time: genesisTimestamp,
|
2018-11-07 22:57:37 -08:00
|
|
|
ProposerAddress: validators.randomProposer(r),
|
2018-11-07 09:19:58 -08:00
|
|
|
}
|
2018-08-16 08:36:15 -07:00
|
|
|
opCount := 0
|
|
|
|
|
2018-09-08 01:29:24 -07:00
|
|
|
// Setup code to catch SIGTERM's
|
|
|
|
c := make(chan os.Signal)
|
2018-09-11 02:18:58 -07:00
|
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
|
2018-09-08 01:29:24 -07:00
|
|
|
go func() {
|
2018-09-11 02:18:58 -07:00
|
|
|
receivedSignal := <-c
|
2018-11-07 09:19:58 -08:00
|
|
|
fmt.Printf("\nExiting early due to %s, on block %d, operation %d\n",
|
|
|
|
receivedSignal, header.Height, opCount)
|
2018-09-11 02:18:58 -07:00
|
|
|
simError = fmt.Errorf("Exited due to %s", receivedSignal)
|
|
|
|
stopEarly = true
|
2018-09-08 01:29:24 -07:00
|
|
|
}()
|
|
|
|
|
2018-09-01 12:32:24 -07:00
|
|
|
var pastTimes []time.Time
|
2018-10-03 08:48:23 -07:00
|
|
|
var pastVoteInfos [][]abci.VoteInfo
|
2018-08-31 17:01:23 -07:00
|
|
|
|
2018-11-07 09:19:58 -08:00
|
|
|
request := RandomRequestBeginBlock(r, params,
|
2018-11-07 21:54:12 -08:00
|
|
|
validators, pastTimes, pastVoteInfos, eventStats.tally, header)
|
2018-11-07 07:28:18 -08:00
|
|
|
|
2018-08-27 14:27:00 -07:00
|
|
|
// These are operations which have been queued by previous operations
|
2018-11-07 21:54:12 -08:00
|
|
|
operationQueue := newOperationQueue()
|
2018-09-18 19:47:54 -07:00
|
|
|
timeOperationQueue := []FutureOperation{}
|
2018-09-09 08:34:09 -07:00
|
|
|
var blockLogBuilders []*strings.Builder
|
2018-07-06 13:19:11 -07:00
|
|
|
|
2018-09-11 02:18:58 -07:00
|
|
|
if testingMode {
|
2018-09-09 08:34:09 -07:00
|
|
|
blockLogBuilders = make([]*strings.Builder, numBlocks)
|
2018-08-30 00:13:31 -07:00
|
|
|
}
|
2018-09-09 08:34:09 -07:00
|
|
|
displayLogs := logPrinter(testingMode, blockLogBuilders)
|
2018-11-07 07:28:18 -08:00
|
|
|
blockSimulator := createBlockSimulator(
|
2018-11-07 21:54:12 -08:00
|
|
|
testingMode, tb, t, params, eventStats.tally, invariants,
|
2018-11-07 07:28:18 -08:00
|
|
|
ops, operationQueue, timeOperationQueue,
|
|
|
|
numBlocks, blockSize, displayLogs)
|
|
|
|
|
2018-09-11 02:18:58 -07:00
|
|
|
if !testingMode {
|
|
|
|
b.ResetTimer()
|
|
|
|
} else {
|
|
|
|
// Recover logs in case of panic
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
fmt.Println("Panic with err\n", r)
|
|
|
|
stackTrace := string(debug.Stack())
|
|
|
|
fmt.Println(stackTrace)
|
|
|
|
displayLogs()
|
2018-11-07 09:19:58 -08:00
|
|
|
simError = fmt.Errorf(
|
|
|
|
"Simulation halted due to panic on block %d",
|
|
|
|
header.Height)
|
2018-09-11 02:18:58 -07:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2018-08-30 00:13:31 -07:00
|
|
|
|
2018-11-07 09:19:58 -08:00
|
|
|
// TODO split up the contents of this for loop into new functions
|
2018-09-11 02:18:58 -07:00
|
|
|
for i := 0; i < numBlocks && !stopEarly; i++ {
|
2018-11-07 21:54:12 -08:00
|
|
|
|
2018-09-01 12:32:24 -07:00
|
|
|
// Log the header time for future lookup
|
|
|
|
pastTimes = append(pastTimes, header.Time)
|
2018-10-03 08:48:23 -07:00
|
|
|
pastVoteInfos = append(pastVoteInfos, request.LastCommitInfo.Votes)
|
2018-09-01 12:32:24 -07:00
|
|
|
|
2018-10-18 18:55:14 -07:00
|
|
|
// Construct log writer
|
|
|
|
logWriter := addLogMessage(testingMode, blockLogBuilders, i)
|
|
|
|
|
2018-08-16 08:36:15 -07:00
|
|
|
// Run the BeginBlock handler
|
2018-10-18 18:55:14 -07:00
|
|
|
logWriter("BeginBlock")
|
2018-08-16 08:36:15 -07:00
|
|
|
app.BeginBlock(request)
|
|
|
|
|
2018-09-01 12:32:24 -07:00
|
|
|
if testingMode {
|
2018-11-07 20:55:48 -08:00
|
|
|
invariants.assertAll(t, app, "BeginBlock", displayLogs)
|
2018-08-30 00:13:31 -07:00
|
|
|
}
|
2018-07-06 13:19:11 -07:00
|
|
|
|
|
|
|
ctx := app.NewContext(false, header)
|
2018-08-29 23:02:15 -07:00
|
|
|
|
2018-08-27 14:27:00 -07:00
|
|
|
// Run queued operations. Ignores blocksize if blocksize is too small
|
2018-10-18 18:55:14 -07:00
|
|
|
logWriter("Queued operations")
|
2018-11-07 07:28:18 -08:00
|
|
|
numQueuedOpsRan := runQueuedOperations(
|
|
|
|
operationQueue, int(header.Height),
|
|
|
|
tb, r, app, ctx, accs, logWriter,
|
2018-11-07 21:54:12 -08:00
|
|
|
displayLogs, eventStats.tally)
|
|
|
|
|
2018-11-07 07:28:18 -08:00
|
|
|
numQueuedTimeOpsRan := runQueuedTimeOperations(
|
|
|
|
timeOperationQueue, header.Time,
|
|
|
|
tb, r, app, ctx, accs,
|
2018-11-07 21:54:12 -08:00
|
|
|
logWriter, displayLogs, eventStats.tally)
|
|
|
|
|
2018-10-18 18:55:14 -07:00
|
|
|
if testingMode && onOperation {
|
2018-11-07 20:55:48 -08:00
|
|
|
invariants.assertAll(t, app, "QueuedOperations", displayLogs)
|
2018-10-18 18:55:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
logWriter("Standard operations")
|
2018-10-28 21:37:19 -07:00
|
|
|
operations := blockSimulator(r, app, ctx, accs, header, logWriter)
|
2018-09-18 19:47:54 -07:00
|
|
|
opCount += operations + numQueuedOpsRan + numQueuedTimeOpsRan
|
2018-10-18 18:55:14 -07:00
|
|
|
if testingMode {
|
2018-11-07 20:55:48 -08:00
|
|
|
invariants.assertAll(t, app, "StandardOperations", displayLogs)
|
2018-10-18 18:55:14 -07:00
|
|
|
}
|
2018-07-06 13:19:11 -07:00
|
|
|
|
2018-08-16 08:36:15 -07:00
|
|
|
res := app.EndBlock(abci.RequestEndBlock{})
|
2018-07-06 13:19:11 -07:00
|
|
|
header.Height++
|
2018-11-07 07:28:18 -08:00
|
|
|
header.Time = header.Time.Add(
|
|
|
|
time.Duration(minTimePerBlock) * time.Second)
|
|
|
|
header.Time = header.Time.Add(
|
|
|
|
time.Duration(int64(r.Intn(int(timeDiff)))) * time.Second)
|
2018-11-07 22:57:37 -08:00
|
|
|
header.ProposerAddress = validators.randomProposer(r)
|
2018-09-09 08:34:09 -07:00
|
|
|
logWriter("EndBlock")
|
2018-08-16 08:36:15 -07:00
|
|
|
|
2018-09-01 12:32:24 -07:00
|
|
|
if testingMode {
|
2018-11-07 20:55:48 -08:00
|
|
|
invariants.assertAll(t, app, "EndBlock", displayLogs)
|
2018-08-30 00:13:31 -07:00
|
|
|
}
|
2018-08-17 07:19:33 -07:00
|
|
|
if commit {
|
|
|
|
app.Commit()
|
|
|
|
}
|
2018-10-22 20:55:49 -07:00
|
|
|
|
|
|
|
if header.ProposerAddress == nil {
|
2018-11-07 08:00:24 -08:00
|
|
|
fmt.Printf("\nSimulation stopped early as all validators " +
|
|
|
|
"have been unbonded, there is nobody left propose a block!\n")
|
2018-10-22 20:55:49 -07:00
|
|
|
stopEarly = true
|
|
|
|
break
|
|
|
|
}
|
2018-08-17 07:19:33 -07:00
|
|
|
|
2018-11-07 21:54:12 -08:00
|
|
|
// Generate a random RequestBeginBlock with the current validator set
|
|
|
|
// for the next block
|
2018-11-07 09:19:58 -08:00
|
|
|
request = RandomRequestBeginBlock(r, params, validators,
|
2018-11-07 21:54:12 -08:00
|
|
|
pastTimes, pastVoteInfos, eventStats.tally, header)
|
2018-08-16 08:36:15 -07:00
|
|
|
|
2018-11-07 21:54:12 -08:00
|
|
|
// Update the validator set, which will be reflected in the application
|
|
|
|
// on the next block
|
2018-10-04 09:22:51 -07:00
|
|
|
validators = nextValidators
|
2018-11-07 09:19:58 -08:00
|
|
|
nextValidators = updateValidators(tb, r, params,
|
2018-11-07 21:54:12 -08:00
|
|
|
validators, res.ValidatorUpdates, eventStats.tally)
|
2018-07-06 13:19:11 -07:00
|
|
|
}
|
2018-11-07 21:54:12 -08:00
|
|
|
|
2018-09-11 02:18:58 -07:00
|
|
|
if stopEarly {
|
2018-11-07 21:54:12 -08:00
|
|
|
eventStats.Print()
|
2018-11-26 04:21:23 -08:00
|
|
|
return true, simError
|
2018-09-11 02:18:58 -07:00
|
|
|
}
|
2018-11-07 08:00:24 -08:00
|
|
|
fmt.Printf("\nSimulation complete. Final height (blocks): %d, "+
|
|
|
|
"final time (seconds), : %v, operations ran %d\n",
|
|
|
|
header.Height, header.Time, opCount)
|
|
|
|
|
2018-11-07 21:54:12 -08:00
|
|
|
eventStats.Print()
|
2018-11-26 04:21:23 -08:00
|
|
|
return false, nil
|
2018-08-30 11:43:56 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 08:00:24 -08:00
|
|
|
//______________________________________________________________________________
|
|
|
|
|
2018-11-07 07:28:18 -08:00
|
|
|
type blockSimFn func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
|
|
|
|
accounts []Account, header abci.Header, logWriter func(string)) (opCount int)
|
2018-10-31 10:11:41 -07:00
|
|
|
|
2018-11-07 20:26:02 -08:00
|
|
|
// Returns a function to simulate blocks. Written like this to avoid constant
|
2018-11-07 21:12:51 -08:00
|
|
|
// parameters being passed everytime, to minimize memory overhead.
|
2018-11-04 20:44:43 -08:00
|
|
|
func createBlockSimulator(testingMode bool, tb testing.TB, t *testing.T, params Params,
|
2018-11-07 20:55:48 -08:00
|
|
|
event func(string), invariants Invariants, ops WeightedOperations,
|
2018-11-07 21:12:51 -08:00
|
|
|
operationQueue OperationQueue, timeOperationQueue []FutureOperation,
|
2018-10-31 09:37:50 -07:00
|
|
|
totalNumBlocks int, avgBlockSize int, displayLogs func()) blockSimFn {
|
|
|
|
|
2018-11-07 09:19:58 -08:00
|
|
|
var lastBlocksizeState = 0 // state for [4 * uniform distribution]
|
|
|
|
var blocksize int
|
2018-11-07 20:26:02 -08:00
|
|
|
selectOp := ops.getSelectOpFn()
|
2018-10-28 21:37:19 -07:00
|
|
|
|
|
|
|
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
|
2018-09-22 20:20:53 -07:00
|
|
|
accounts []Account, header abci.Header, logWriter func(string)) (opCount int) {
|
2018-11-07 07:28:18 -08:00
|
|
|
|
|
|
|
fmt.Printf("\rSimulating... block %d/%d, operation %d/%d. ",
|
|
|
|
header.Height, totalNumBlocks, opCount, blocksize)
|
2018-11-04 20:44:43 -08:00
|
|
|
lastBlocksizeState, blocksize = getBlockSize(r, params, lastBlocksizeState, avgBlockSize)
|
2018-11-07 07:28:18 -08:00
|
|
|
|
2018-11-27 00:14:22 -08:00
|
|
|
type opAndR struct {
|
|
|
|
op Operation
|
|
|
|
rand *rand.Rand
|
|
|
|
}
|
|
|
|
opAndRz := make([]opAndR, 0, blocksize)
|
|
|
|
// Predetermine the blocksize slice so that we can do things like block
|
|
|
|
// out certain operations without changing the ops that follow.
|
2018-11-07 21:54:12 -08:00
|
|
|
for i := 0; i < blocksize; i++ {
|
2018-11-27 00:14:22 -08:00
|
|
|
opAndRz = append(opAndRz, opAndR{
|
|
|
|
op: selectOp(r),
|
|
|
|
rand: DeriveRand(r),
|
|
|
|
})
|
|
|
|
}
|
2018-11-07 21:54:12 -08:00
|
|
|
|
2018-11-27 00:14:22 -08:00
|
|
|
for i := 0; i < blocksize; i++ {
|
|
|
|
// NOTE: the Rand 'r' should not be used here.
|
|
|
|
opAndR := opAndRz[i]
|
|
|
|
op, r2 := opAndR.op, opAndR.rand
|
|
|
|
logUpdate, futureOps, err := op(r2, app, ctx, accounts, event)
|
2018-10-31 04:04:46 -07:00
|
|
|
logWriter(logUpdate)
|
2018-08-30 11:43:56 -07:00
|
|
|
if err != nil {
|
2018-09-09 08:34:09 -07:00
|
|
|
displayLogs()
|
2018-11-07 07:28:18 -08:00
|
|
|
tb.Fatalf("error on operation %d within block %d, %v",
|
|
|
|
header.Height, opCount, err)
|
2018-08-30 11:43:56 -07:00
|
|
|
}
|
|
|
|
|
2018-09-18 19:47:54 -07:00
|
|
|
queueOperations(operationQueue, timeOperationQueue, futureOps)
|
2018-09-01 12:32:24 -07:00
|
|
|
if testingMode {
|
2018-08-30 11:43:56 -07:00
|
|
|
if onOperation {
|
2018-11-07 20:55:48 -08:00
|
|
|
eventStr := fmt.Sprintf("operation: %v", logUpdate)
|
|
|
|
invariants.assertAll(t, app, eventStr, displayLogs)
|
2018-08-30 11:43:56 -07:00
|
|
|
}
|
|
|
|
if opCount%50 == 0 {
|
2018-11-07 07:28:18 -08:00
|
|
|
fmt.Printf("\rSimulating... block %d/%d, operation %d/%d. ",
|
|
|
|
header.Height, totalNumBlocks, opCount, blocksize)
|
2018-08-30 11:43:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
opCount++
|
|
|
|
}
|
2018-09-09 08:34:09 -07:00
|
|
|
return opCount
|
2018-08-30 11:43:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-03 09:47:24 -07:00
|
|
|
// nolint: errcheck
|
2018-11-07 09:00:13 -08:00
|
|
|
func runQueuedOperations(queueOps map[int][]Operation,
|
2018-11-07 21:54:12 -08:00
|
|
|
height int, tb testing.TB, r *rand.Rand, app *baseapp.BaseApp,
|
|
|
|
ctx sdk.Context, accounts []Account, logWriter func(string),
|
|
|
|
displayLogs func(), tallyEvent func(string)) (numOpsRan int) {
|
2018-11-07 07:28:18 -08:00
|
|
|
|
2018-11-07 09:19:58 -08:00
|
|
|
queuedOp, ok := queueOps[height]
|
|
|
|
if !ok {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-11-07 20:55:48 -08:00
|
|
|
numOpsRan = len(queuedOp)
|
|
|
|
for i := 0; i < numOpsRan; i++ {
|
2018-11-07 21:54:12 -08:00
|
|
|
|
2018-11-07 09:19:58 -08:00
|
|
|
// For now, queued operations cannot queue more operations.
|
|
|
|
// If a need arises for us to support queued messages to queue more messages, this can
|
|
|
|
// be changed.
|
2018-11-07 21:54:12 -08:00
|
|
|
logUpdate, _, err := queuedOp[i](r, app, ctx, accounts, tallyEvent)
|
2018-11-07 09:19:58 -08:00
|
|
|
logWriter(logUpdate)
|
|
|
|
if err != nil {
|
|
|
|
displayLogs()
|
|
|
|
tb.FailNow()
|
2018-08-27 14:27:00 -07:00
|
|
|
}
|
|
|
|
}
|
2018-11-07 09:19:58 -08:00
|
|
|
delete(queueOps, height)
|
2018-11-07 20:55:48 -08:00
|
|
|
return numOpsRan
|
2018-08-27 14:27:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 09:00:13 -08:00
|
|
|
func runQueuedTimeOperations(queueOps []FutureOperation,
|
2018-11-07 07:28:18 -08:00
|
|
|
currentTime time.Time, tb testing.TB, r *rand.Rand,
|
|
|
|
app *baseapp.BaseApp, ctx sdk.Context, accounts []Account,
|
2018-11-07 21:54:12 -08:00
|
|
|
logWriter func(string), displayLogs func(), tallyEvent func(string)) (numOpsRan int) {
|
2018-09-18 19:47:54 -07:00
|
|
|
|
|
|
|
numOpsRan = 0
|
2018-11-07 09:00:13 -08:00
|
|
|
for len(queueOps) > 0 && currentTime.After(queueOps[0].BlockTime) {
|
2018-11-07 21:54:12 -08:00
|
|
|
|
2018-09-18 19:47:54 -07:00
|
|
|
// For now, queued operations cannot queue more operations.
|
|
|
|
// If a need arises for us to support queued messages to queue more messages, this can
|
|
|
|
// be changed.
|
2018-11-07 21:54:12 -08:00
|
|
|
logUpdate, _, err := queueOps[0].Op(r, app, ctx, accounts, tallyEvent)
|
2018-09-18 19:47:54 -07:00
|
|
|
logWriter(logUpdate)
|
|
|
|
if err != nil {
|
|
|
|
displayLogs()
|
|
|
|
tb.FailNow()
|
|
|
|
}
|
2018-11-07 21:54:12 -08:00
|
|
|
|
2018-11-07 09:00:13 -08:00
|
|
|
queueOps = queueOps[1:]
|
2018-09-18 19:47:54 -07:00
|
|
|
numOpsRan++
|
|
|
|
}
|
|
|
|
return numOpsRan
|
|
|
|
}
|