desmos
desmos copied to clipboard
Improve simulation tests
Currently all the simulation tests are returning functions that implement the simtypes.Operation type:
// 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",
// which details what this fuzzed state machine transition actually did.
//
// Operations can optionally provide a list of "FutureOperations" to run later
// These will be ran at the beginning of the corresponding block.
type Operation func(r *rand.Rand, app *baseapp.BaseApp,
ctx sdk.Context, accounts []Account, chainID string) (
OperationMsg OperationMsg, futureOps []FutureOperation, err error)
Even thought this type works properly the amount of parameters that requires is extremely large and causes the sim tests to look ugly and hard to maintain in the case some other data should be passed there instead. In order to solve this, I think we can encapsulate those values into a new Context type that can later be passed as the single parameter to the Operation type:
type Context struct {
R *rand.Rand
App *baseapp.BaseApp
Ctx sdk.Context
Accounts []Account
ChainID string
}
type Operation func(ctx Context) (OperationMsg OperationMsg, futureOps []FutureOperation, err error)
This can be implemented directly inside the Cosmos SDK so that everyone can benefit from this