Genesis state

This commit is contained in:
Christopher Goes 2018-07-17 20:33:53 +02:00
parent d171dbf913
commit cbc9d7d1da
2 changed files with 25 additions and 10 deletions

View File

@ -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{},

View File

@ -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)
}