From cbc9d7d1da92ff671fdddd54ba8361ee91871e67 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 17 Jul 2018 20:33:53 +0200 Subject: [PATCH] Genesis state --- cmd/gaia/simulation/sim_test.go | 18 ++++++++++++++++-- x/mock/simulation/random_simulate_blocks.go | 17 +++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cmd/gaia/simulation/sim_test.go b/cmd/gaia/simulation/sim_test.go index b1382deb0..2d36e0fa2 100644 --- a/cmd/gaia/simulation/sim_test.go +++ b/cmd/gaia/simulation/sim_test.go @@ -10,6 +10,7 @@ import ( gaia "github.com/cosmos/cosmos-sdk/cmd/gaia/app" "github.com/cosmos/cosmos-sdk/x/mock/simulation" + stake "github.com/cosmos/cosmos-sdk/x/stake" ) const ( @@ -19,15 +20,28 @@ const ( ) func TestFullGaiaSimulation(t *testing.T) { + // Setup Gaia application logger := log.NewNopLogger() db := dbm.NewMemDB() app := gaia.NewGaiaApp(logger, db, nil) require.Equal(t, "GaiaApp", app.Name()) + // Default genesis state + genesis := gaia.GenesisState{ + Accounts: []gaia.GenesisAccount{}, + StakeData: stake.DefaultGenesisState(), + } + + // Marshal genesis + appState, err := gaia.MakeCodec().MarshalJSON(genesis) + if err != nil { + panic(err) + } + // Run randomized simulation - simulation.RandomizedTesting( - t, app.BaseApp, + simulation.Simulate( + t, app.BaseApp, appState, []simulation.TestAndRunTx{}, []simulation.RandSetup{}, []simulation.Invariant{}, diff --git a/x/mock/simulation/random_simulate_blocks.go b/x/mock/simulation/random_simulate_blocks.go index d66373258..fdb1c9d42 100644 --- a/x/mock/simulation/random_simulate_blocks.go +++ b/x/mock/simulation/random_simulate_blocks.go @@ -1,6 +1,7 @@ package simulation import ( + "encoding/json" "fmt" "math/rand" "testing" @@ -12,19 +13,19 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -// RandomizedTesting tests application by sending random messages. -func RandomizedTesting( - t *testing.T, app *baseapp.BaseApp, ops []TestAndRunTx, setups []RandSetup, +// Simulate tests application by sending random messages. +func Simulate( + t *testing.T, app *baseapp.BaseApp, appState json.RawMessage, ops []TestAndRunTx, setups []RandSetup, invariants []Invariant, numKeys int, numBlocks int, blockSize int, ) { time := time.Now().UnixNano() - RandomizedTestingFromSeed(t, app, time, ops, setups, invariants, numKeys, numBlocks, blockSize) + SimulateFromSeed(t, app, appState, time, ops, setups, invariants, numKeys, numBlocks, blockSize) } -// RandomizedTestingFromSeed tests an application by running the provided +// SimulateFromSeed tests an application by running the provided // operations, testing the provided invariants, but using the provided seed. -func RandomizedTestingFromSeed( - t *testing.T, app *baseapp.BaseApp, seed int64, ops []TestAndRunTx, setups []RandSetup, +func SimulateFromSeed( + t *testing.T, app *baseapp.BaseApp, appState json.RawMessage, seed int64, ops []TestAndRunTx, setups []RandSetup, invariants []Invariant, numKeys int, numBlocks int, blockSize int, ) { log := fmt.Sprintf("Starting SingleModuleTest with randomness created with seed %d", int(seed)) @@ -33,7 +34,7 @@ func RandomizedTestingFromSeed( // XXX TODO // RandomSetGenesis(r, app, addrs, []string{"foocoin"}) - app.InitChain(abci.RequestInitChain{}) + app.InitChain(abci.RequestInitChain{AppStateBytes: appState}) for i := 0; i < len(setups); i++ { setups[i](r, keys) }