Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync up with SDK's latest changes #24

Merged
merged 3 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 48 additions & 31 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
lean bool
commit bool
period int
onOperation bool // TODO Remove in favor of binary search for invariant violation
)

func init() {
Expand All @@ -61,15 +62,16 @@ func init() {
flag.BoolVar(&lean, "SimulationLean", false, "lean simulation log output")
flag.BoolVar(&commit, "SimulationCommit", false, "have the simulation commit")
flag.IntVar(&period, "SimulationPeriod", 1, "run slow invariants only once every period assertions")
flag.BoolVar(&onOperation, "SimulateEveryOperation", false, "run slow invariants every operation")
}

// helper function for populating input for SimulateFromSeed
func getSimulateFromSeedInput(tb testing.TB, w io.Writer, app *GaiaApp) (
testing.TB, io.Writer, *baseapp.BaseApp, simulation.AppStateFn, int64,
simulation.WeightedOperations, sdk.Invariants, int, int, bool, bool) {
simulation.WeightedOperations, sdk.Invariants, int, int, bool, bool, bool) {

return tb, w, app.BaseApp, appStateFn, seed,
testAndRunTxs(app), invariants(app), numBlocks, blockSize, commit, lean
testAndRunTxs(app), invariants(app), numBlocks, blockSize, commit, lean, onOperation
}

func appStateFromGenesisFileFn(r *rand.Rand, accs []simulation.Account, genesisTimestamp time.Time,
Expand All @@ -84,7 +86,7 @@ func appStateFromGenesisFileFn(r *rand.Rand, accs []simulation.Account, genesisT
cdc.MustUnmarshalJSON(bytes, &genesis)
var appState GenesisState
cdc.MustUnmarshalJSON(genesis.AppState, &appState)
accounts := genaccounts.GetGenesisStateFromAppState(cdc, appState).Accounts
accounts := genaccounts.GetGenesisStateFromAppState(cdc, appState)

var newAccs []simulation.Account
for _, acc := range accounts {
Expand Down Expand Up @@ -165,8 +167,7 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
genesisAccounts = append(genesisAccounts, gacc)
}

genaccsGenesis := genaccounts.NewGenesisState(genesisAccounts)
genesisState[genaccounts.ModuleName] = cdc.MustMarshalJSON(genaccsGenesis)
genesisState[genaccounts.ModuleName] = cdc.MustMarshalJSON(genesisAccounts)

authGenesis := auth.NewGenesisState(
nil,
Expand Down Expand Up @@ -301,8 +302,8 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
{50, distrsim.SimulateMsgWithdrawDelegatorReward(app.accountKeeper, app.distrKeeper)},
{50, distrsim.SimulateMsgWithdrawValidatorCommission(app.accountKeeper, app.distrKeeper)},
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, govsim.SimulateTextProposalContent)},
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, paramsim.SimulateParamChangeProposalContent)},
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, distrsim.SimulateCommunityPoolSpendProposalContent(app.distrKeeper))},
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, paramsim.SimulateParamChangeProposalContent)},
{100, govsim.SimulateMsgDeposit(app.govKeeper)},
{100, stakingsim.SimulateMsgCreateValidator(app.accountKeeper, app.stakingKeeper)},
{5, stakingsim.SimulateMsgEditValidator(app.stakingKeeper)},
Expand All @@ -323,13 +324,12 @@ func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
}

// Profile with:
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/gaia/app -bench ^BenchmarkFullGaiaSimulation$ -SimulationCommit=true -cpuprofile cpu.out
func BenchmarkFullGaiaSimulation(b *testing.B) {
// Setup Gaia application
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/GaiaApp -bench ^BenchmarkFullAppSimulation$ -SimulationCommit=true -cpuprofile cpu.out
func BenchmarkFullAppSimulation(b *testing.B) {
logger := log.NewNopLogger()

var db dbm.DB
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
db, _ = sdk.NewLevelDB("Simulation", dir)
defer func() {
db.Close()
Expand All @@ -351,25 +351,28 @@ func BenchmarkFullGaiaSimulation(b *testing.B) {
}
}

func TestFullGaiaSimulation(t *testing.T) {
func TestFullAppSimulation(t *testing.T) {
if !enabled {
t.Skip("Skipping Gaia simulation")
t.Skip("Skipping application simulation")
}

// Setup Gaia application
var logger log.Logger

if verbose {
logger = log.TestingLogger()
} else {
logger = log.NewNopLogger()
}

var db dbm.DB
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
db, _ = sdk.NewLevelDB("Simulation", dir)

defer func() {
db.Close()
os.RemoveAll(dir)
}()

app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt)
require.Equal(t, "GaiaApp", app.Name())

Expand All @@ -382,28 +385,31 @@ func TestFullGaiaSimulation(t *testing.T) {
fmt.Println(db.Stats()["leveldb.stats"])
fmt.Println("GoLevelDB cached block size", db.Stats()["leveldb.cachedblock"])
}

require.Nil(t, err)
}

func TestGaiaImportExport(t *testing.T) {
func TestAppImportExport(t *testing.T) {
if !enabled {
t.Skip("Skipping Gaia import/export simulation")
t.Skip("Skipping application import/export simulation")
}

// Setup Gaia application
var logger log.Logger
if verbose {
logger = log.TestingLogger()
} else {
logger = log.NewNopLogger()
}

var db dbm.DB
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
db, _ = sdk.NewLevelDB("Simulation", dir)

defer func() {
db.Close()
os.RemoveAll(dir)
}()

app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt)
require.Equal(t, "GaiaApp", app.Name())

Expand All @@ -417,37 +423,43 @@ func TestGaiaImportExport(t *testing.T) {
fmt.Println(db.Stats()["leveldb.stats"])
fmt.Println("GoLevelDB cached block size", db.Stats()["leveldb.cachedblock"])
}
require.Nil(t, err)

require.Nil(t, err)
fmt.Printf("Exporting genesis...\n")

appState, _, err := app.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err)
fmt.Printf("Importing genesis...\n")

newDir, _ := ioutil.TempDir("", "goleveldb-gaia-sim-2")
newDir, _ := ioutil.TempDir("", "goleveldb-app-sim-2")
newDB, _ := sdk.NewLevelDB("Simulation-2", dir)

defer func() {
newDB.Close()
os.RemoveAll(newDir)
}()

newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt)
require.Equal(t, "GaiaApp", newApp.Name())

var genesisState GenesisState
err = app.cdc.UnmarshalJSON(appState, &genesisState)
if err != nil {
panic(err)
}

ctxB := newApp.NewContext(true, abci.Header{})
newApp.mm.InitGenesis(ctxB, genesisState)

fmt.Printf("Comparing stores...\n")
ctxA := app.NewContext(true, abci.Header{})

type StoreKeysPrefixes struct {
A sdk.StoreKey
B sdk.StoreKey
Prefixes [][]byte
}

storeKeysPrefixes := []StoreKeysPrefixes{
{app.keyMain, newApp.keyMain, [][]byte{}},
{app.keyAccount, newApp.keyAccount, [][]byte{}},
Expand All @@ -460,6 +472,7 @@ func TestGaiaImportExport(t *testing.T) {
{app.keyParams, newApp.keyParams, [][]byte{}},
{app.keyGov, newApp.keyGov, [][]byte{}},
}

for _, storeKeysPrefix := range storeKeysPrefixes {
storeKeyA := storeKeysPrefix.A
storeKeyB := storeKeysPrefix.B
Expand All @@ -476,24 +489,26 @@ func TestGaiaImportExport(t *testing.T) {

}

func TestGaiaSimulationAfterImport(t *testing.T) {
func TestAppSimulationAfterImport(t *testing.T) {
if !enabled {
t.Skip("Skipping Gaia simulation after import")
t.Skip("Skipping application simulation after import")
}

// Setup Gaia application
var logger log.Logger
if verbose {
logger = log.TestingLogger()
} else {
logger = log.NewNopLogger()
}
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")

dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
db, _ := sdk.NewLevelDB("Simulation", dir)

defer func() {
db.Close()
os.RemoveAll(dir)
}()

app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt)
require.Equal(t, "GaiaApp", app.Name())

Expand All @@ -507,6 +522,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
fmt.Println(db.Stats()["leveldb.stats"])
fmt.Println("GoLevelDB cached block size", db.Stats()["leveldb.cachedblock"])
}

require.Nil(t, err)

if stopEarly {
Expand All @@ -524,12 +540,14 @@ func TestGaiaSimulationAfterImport(t *testing.T) {

fmt.Printf("Importing genesis...\n")

newDir, _ := ioutil.TempDir("", "goleveldb-gaia-sim-2")
newDir, _ := ioutil.TempDir("", "goleveldb-app-sim-2")
newDB, _ := sdk.NewLevelDB("Simulation-2", dir)

defer func() {
newDB.Close()
os.RemoveAll(newDir)
}()

newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt)
require.Equal(t, "GaiaApp", newApp.Name())
newApp.InitChain(abci.RequestInitChain{
Expand All @@ -539,14 +557,13 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
// Run randomized simulation on imported app
_, err = simulation.SimulateFromSeed(getSimulateFromSeedInput(t, os.Stdout, newApp))
require.Nil(t, err)

}

// TODO: Make another test for the fuzzer itself, which just has noOp txs
// and doesn't depend on gaia
// and doesn't depend on the application.
func TestAppStateDeterminism(t *testing.T) {
if !enabled {
t.Skip("Skipping Gaia simulation")
t.Skip("Skipping application simulation")
}

numSeeds := 3
Expand All @@ -569,6 +586,7 @@ func TestAppStateDeterminism(t *testing.T) {
100,
true,
false,
false,
)
appHash := app.LastCommitID().Hash
appHashList[j] = appHash
Expand All @@ -580,9 +598,8 @@ func TestAppStateDeterminism(t *testing.T) {
}

func BenchmarkInvariants(b *testing.B) {
// 1. Setup a simulated Gaia application
logger := log.NewNopLogger()
dir, _ := ioutil.TempDir("", "goleveldb-gaia-invariant-bench")
dir, _ := ioutil.TempDir("", "goleveldb-app-invariant-bench")
db, _ := sdk.NewLevelDB("simulation", dir)

defer func() {
Expand All @@ -595,7 +612,7 @@ func BenchmarkInvariants(b *testing.B) {
// 2. Run parameterized simulation (w/o invariants)
_, err := simulation.SimulateFromSeed(
b, ioutil.Discard, app.BaseApp, appStateFn, seed, testAndRunTxs(app),
[]sdk.Invariant{}, numBlocks, blockSize, commit, lean,
[]sdk.Invariant{}, numBlocks, blockSize, commit, lean, onOperation,
)
if err != nil {
fmt.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ func TestGaiadAddGenesisAccount(t *testing.T) {
genesisState := f.GenesisState()

cdc := app.MakeCodec()
accounts := genaccounts.GetGenesisStateFromAppState(cdc, genesisState).Accounts
accounts := genaccounts.GetGenesisStateFromAppState(cdc, genesisState)

require.Equal(t, accounts[0].Address, f.KeyAddress(keyFoo))
require.Equal(t, accounts[1].Address, f.KeyAddress(keyBar))
Expand Down
4 changes: 2 additions & 2 deletions cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func txCmd(cdc *amino.Codec, mc []sdk.ModuleClient) *cobra.Command {
// NOTE: If making updates here you also need to update the test helper in client/lcd/test_helper.go
func registerRoutes(rs *lcd.RestServer) {
registerSwaggerUI(rs)
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
rpc.RegisterRPCRoutes(rs.CliCtx, rs.Mux)
tx.RegisterTxRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, at.StoreKey)
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
dist.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distcmd.StoreKey)
Expand Down
4 changes: 3 additions & 1 deletion cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
genaccscli "github.com/cosmos/cosmos-sdk/x/auth/genaccounts/client/cli"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking"
)

// gaiad custom flags
Expand All @@ -49,7 +50,8 @@ func main() {

rootCmd.AddCommand(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome))
rootCmd.AddCommand(genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, app.DefaultNodeHome))
rootCmd.AddCommand(genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{},
genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics))
rootCmd.AddCommand(genaccscli.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
Expand Down
3 changes: 1 addition & 2 deletions cmd/gaiad/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ func initGenFiles(cdc *codec.Codec, mbm sdk.ModuleBasicManager, chainID string,
appGenState := mbm.DefaultGenesis()

// set the accounts in the genesis state
appGenState = genaccounts.SetGenesisStateInAppState(cdc, appGenState,
genaccounts.NewGenesisState(accs))
appGenState = genaccounts.SetGenesisStateInAppState(cdc, appGenState, accs)

appGenStateJSON, err := codec.MarshalJSONIndent(cdc, appGenState)
if err != nil {
Expand Down
23 changes: 10 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,34 @@ module github.com/cosmos/gaia
go 1.12

require (
github.com/btcsuite/btcd v0.0.0-20190427004231-96897255fd17 // indirect
github.com/cosmos/cosmos-sdk v0.28.2-0.20190521100210-dd89c329516e
github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c // indirect
github.com/cosmos/cosmos-sdk v0.28.2-0.20190528084404-73e5ef7c13c4
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/google/gofuzz v1.0.0 // indirect
github.com/gorilla/mux v1.7.2 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/otiai10/copy v1.0.1
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 // indirect
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/prometheus/client_golang v0.9.3 // indirect
github.com/prometheus/procfs v0.0.0-20190516194456-169873baca24 // indirect
github.com/prometheus/common v0.4.1 // indirect
github.com/prometheus/procfs v0.0.0-20190523193104-a7aeb8df3389 // indirect
github.com/rakyll/statik v0.1.6
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.2
github.com/spf13/cobra v0.0.4
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.3.0
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tendermint/go-amino v0.15.0
github.com/tendermint/tendermint v0.31.5
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb // indirect
golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/grpc v1.19.1 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20190522204451-c2c4e71fbf69 // indirect
)

replace golang.org/x/crypto => github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5
Loading