Skip to content

Commit 787bd94

Browse files
author
Alessio Treglia
authored
Sync up with SDK's latest changes (#24)
1 parent ce9f584 commit 787bd94

File tree

8 files changed

+138
-69
lines changed

8 files changed

+138
-69
lines changed

app/sim_test.go

+48-31
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
lean bool
5050
commit bool
5151
period int
52+
onOperation bool // TODO Remove in favor of binary search for invariant violation
5253
)
5354

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

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

7173
return tb, w, app.BaseApp, appStateFn, seed,
72-
testAndRunTxs(app), invariants(app), numBlocks, blockSize, commit, lean
74+
testAndRunTxs(app), invariants(app), numBlocks, blockSize, commit, lean, onOperation
7375
}
7476

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

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

168-
genaccsGenesis := genaccounts.NewGenesisState(genesisAccounts)
169-
genesisState[genaccounts.ModuleName] = cdc.MustMarshalJSON(genaccsGenesis)
170+
genesisState[genaccounts.ModuleName] = cdc.MustMarshalJSON(genesisAccounts)
170171

171172
authGenesis := auth.NewGenesisState(
172173
nil,
@@ -301,8 +302,8 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
301302
{50, distrsim.SimulateMsgWithdrawDelegatorReward(app.accountKeeper, app.distrKeeper)},
302303
{50, distrsim.SimulateMsgWithdrawValidatorCommission(app.accountKeeper, app.distrKeeper)},
303304
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, govsim.SimulateTextProposalContent)},
304-
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, paramsim.SimulateParamChangeProposalContent)},
305305
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, distrsim.SimulateCommunityPoolSpendProposalContent(app.distrKeeper))},
306+
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, paramsim.SimulateParamChangeProposalContent)},
306307
{100, govsim.SimulateMsgDeposit(app.govKeeper)},
307308
{100, stakingsim.SimulateMsgCreateValidator(app.accountKeeper, app.stakingKeeper)},
308309
{5, stakingsim.SimulateMsgEditValidator(app.stakingKeeper)},
@@ -323,13 +324,12 @@ func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
323324
}
324325

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

331331
var db dbm.DB
332-
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
332+
dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
333333
db, _ = sdk.NewLevelDB("Simulation", dir)
334334
defer func() {
335335
db.Close()
@@ -351,25 +351,28 @@ func BenchmarkFullGaiaSimulation(b *testing.B) {
351351
}
352352
}
353353

354-
func TestFullGaiaSimulation(t *testing.T) {
354+
func TestFullAppSimulation(t *testing.T) {
355355
if !enabled {
356-
t.Skip("Skipping Gaia simulation")
356+
t.Skip("Skipping application simulation")
357357
}
358358

359-
// Setup Gaia application
360359
var logger log.Logger
360+
361361
if verbose {
362362
logger = log.TestingLogger()
363363
} else {
364364
logger = log.NewNopLogger()
365365
}
366+
366367
var db dbm.DB
367-
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
368+
dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
368369
db, _ = sdk.NewLevelDB("Simulation", dir)
370+
369371
defer func() {
370372
db.Close()
371373
os.RemoveAll(dir)
372374
}()
375+
373376
app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt)
374377
require.Equal(t, "GaiaApp", app.Name())
375378

@@ -382,28 +385,31 @@ func TestFullGaiaSimulation(t *testing.T) {
382385
fmt.Println(db.Stats()["leveldb.stats"])
383386
fmt.Println("GoLevelDB cached block size", db.Stats()["leveldb.cachedblock"])
384387
}
388+
385389
require.Nil(t, err)
386390
}
387391

388-
func TestGaiaImportExport(t *testing.T) {
392+
func TestAppImportExport(t *testing.T) {
389393
if !enabled {
390-
t.Skip("Skipping Gaia import/export simulation")
394+
t.Skip("Skipping application import/export simulation")
391395
}
392396

393-
// Setup Gaia application
394397
var logger log.Logger
395398
if verbose {
396399
logger = log.TestingLogger()
397400
} else {
398401
logger = log.NewNopLogger()
399402
}
403+
400404
var db dbm.DB
401-
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
405+
dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
402406
db, _ = sdk.NewLevelDB("Simulation", dir)
407+
403408
defer func() {
404409
db.Close()
405410
os.RemoveAll(dir)
406411
}()
412+
407413
app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt)
408414
require.Equal(t, "GaiaApp", app.Name())
409415

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

427+
require.Nil(t, err)
422428
fmt.Printf("Exporting genesis...\n")
423429

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

428-
newDir, _ := ioutil.TempDir("", "goleveldb-gaia-sim-2")
434+
newDir, _ := ioutil.TempDir("", "goleveldb-app-sim-2")
429435
newDB, _ := sdk.NewLevelDB("Simulation-2", dir)
436+
430437
defer func() {
431438
newDB.Close()
432439
os.RemoveAll(newDir)
433440
}()
441+
434442
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt)
435443
require.Equal(t, "GaiaApp", newApp.Name())
444+
436445
var genesisState GenesisState
437446
err = app.cdc.UnmarshalJSON(appState, &genesisState)
438447
if err != nil {
439448
panic(err)
440449
}
450+
441451
ctxB := newApp.NewContext(true, abci.Header{})
442452
newApp.mm.InitGenesis(ctxB, genesisState)
443453

444454
fmt.Printf("Comparing stores...\n")
445455
ctxA := app.NewContext(true, abci.Header{})
456+
446457
type StoreKeysPrefixes struct {
447458
A sdk.StoreKey
448459
B sdk.StoreKey
449460
Prefixes [][]byte
450461
}
462+
451463
storeKeysPrefixes := []StoreKeysPrefixes{
452464
{app.keyMain, newApp.keyMain, [][]byte{}},
453465
{app.keyAccount, newApp.keyAccount, [][]byte{}},
@@ -460,6 +472,7 @@ func TestGaiaImportExport(t *testing.T) {
460472
{app.keyParams, newApp.keyParams, [][]byte{}},
461473
{app.keyGov, newApp.keyGov, [][]byte{}},
462474
}
475+
463476
for _, storeKeysPrefix := range storeKeysPrefixes {
464477
storeKeyA := storeKeysPrefix.A
465478
storeKeyB := storeKeysPrefix.B
@@ -476,24 +489,26 @@ func TestGaiaImportExport(t *testing.T) {
476489

477490
}
478491

479-
func TestGaiaSimulationAfterImport(t *testing.T) {
492+
func TestAppSimulationAfterImport(t *testing.T) {
480493
if !enabled {
481-
t.Skip("Skipping Gaia simulation after import")
494+
t.Skip("Skipping application simulation after import")
482495
}
483496

484-
// Setup Gaia application
485497
var logger log.Logger
486498
if verbose {
487499
logger = log.TestingLogger()
488500
} else {
489501
logger = log.NewNopLogger()
490502
}
491-
dir, _ := ioutil.TempDir("", "goleveldb-gaia-sim")
503+
504+
dir, _ := ioutil.TempDir("", "goleveldb-app-sim")
492505
db, _ := sdk.NewLevelDB("Simulation", dir)
506+
493507
defer func() {
494508
db.Close()
495509
os.RemoveAll(dir)
496510
}()
511+
497512
app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt)
498513
require.Equal(t, "GaiaApp", app.Name())
499514

@@ -507,6 +522,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
507522
fmt.Println(db.Stats()["leveldb.stats"])
508523
fmt.Println("GoLevelDB cached block size", db.Stats()["leveldb.cachedblock"])
509524
}
525+
510526
require.Nil(t, err)
511527

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

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

527-
newDir, _ := ioutil.TempDir("", "goleveldb-gaia-sim-2")
543+
newDir, _ := ioutil.TempDir("", "goleveldb-app-sim-2")
528544
newDB, _ := sdk.NewLevelDB("Simulation-2", dir)
545+
529546
defer func() {
530547
newDB.Close()
531548
os.RemoveAll(newDir)
532549
}()
550+
533551
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt)
534552
require.Equal(t, "GaiaApp", newApp.Name())
535553
newApp.InitChain(abci.RequestInitChain{
@@ -539,14 +557,13 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
539557
// Run randomized simulation on imported app
540558
_, err = simulation.SimulateFromSeed(getSimulateFromSeedInput(t, os.Stdout, newApp))
541559
require.Nil(t, err)
542-
543560
}
544561

545562
// TODO: Make another test for the fuzzer itself, which just has noOp txs
546-
// and doesn't depend on gaia
563+
// and doesn't depend on the application.
547564
func TestAppStateDeterminism(t *testing.T) {
548565
if !enabled {
549-
t.Skip("Skipping Gaia simulation")
566+
t.Skip("Skipping application simulation")
550567
}
551568

552569
numSeeds := 3
@@ -569,6 +586,7 @@ func TestAppStateDeterminism(t *testing.T) {
569586
100,
570587
true,
571588
false,
589+
false,
572590
)
573591
appHash := app.LastCommitID().Hash
574592
appHashList[j] = appHash
@@ -580,9 +598,8 @@ func TestAppStateDeterminism(t *testing.T) {
580598
}
581599

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

588605
defer func() {
@@ -595,7 +612,7 @@ func BenchmarkInvariants(b *testing.B) {
595612
// 2. Run parameterized simulation (w/o invariants)
596613
_, err := simulation.SimulateFromSeed(
597614
b, ioutil.Discard, app.BaseApp, appStateFn, seed, testAndRunTxs(app),
598-
[]sdk.Invariant{}, numBlocks, blockSize, commit, lean,
615+
[]sdk.Invariant{}, numBlocks, blockSize, commit, lean, onOperation,
599616
)
600617
if err != nil {
601618
fmt.Println(err)

cli_test/cli_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ func TestGaiadAddGenesisAccount(t *testing.T) {
12881288
genesisState := f.GenesisState()
12891289

12901290
cdc := app.MakeCodec()
1291-
accounts := genaccounts.GetGenesisStateFromAppState(cdc, genesisState).Accounts
1291+
accounts := genaccounts.GetGenesisStateFromAppState(cdc, genesisState)
12921292

12931293
require.Equal(t, accounts[0].Address, f.KeyAddress(keyFoo))
12941294
require.Equal(t, accounts[1].Address, f.KeyAddress(keyBar))

cmd/gaiacli/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ func txCmd(cdc *amino.Codec, mc []sdk.ModuleClient) *cobra.Command {
169169
// NOTE: If making updates here you also need to update the test helper in client/lcd/test_helper.go
170170
func registerRoutes(rs *lcd.RestServer) {
171171
registerSwaggerUI(rs)
172-
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
173-
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
172+
rpc.RegisterRPCRoutes(rs.CliCtx, rs.Mux)
173+
tx.RegisterTxRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
174174
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, at.StoreKey)
175175
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
176176
dist.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distcmd.StoreKey)

cmd/gaiad/main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
2424
genaccscli "github.com/cosmos/cosmos-sdk/x/auth/genaccounts/client/cli"
2525
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
26+
"github.com/cosmos/cosmos-sdk/x/staking"
2627
)
2728

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

5051
rootCmd.AddCommand(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome))
5152
rootCmd.AddCommand(genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, app.DefaultNodeHome))
52-
rootCmd.AddCommand(genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome))
53+
rootCmd.AddCommand(genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{},
54+
genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome))
5355
rootCmd.AddCommand(genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics))
5456
rootCmd.AddCommand(genaccscli.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome))
5557
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))

cmd/gaiad/testnet.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ func initGenFiles(cdc *codec.Codec, mbm sdk.ModuleBasicManager, chainID string,
263263
appGenState := mbm.DefaultGenesis()
264264

265265
// set the accounts in the genesis state
266-
appGenState = genaccounts.SetGenesisStateInAppState(cdc, appGenState,
267-
genaccounts.NewGenesisState(accs))
266+
appGenState = genaccounts.SetGenesisStateInAppState(cdc, appGenState, accs)
268267

269268
appGenStateJSON, err := codec.MarshalJSONIndent(cdc, appGenState)
270269
if err != nil {

go.mod

+10-13
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,34 @@ module github.com/cosmos/gaia
33
go 1.12
44

55
require (
6-
github.com/btcsuite/btcd v0.0.0-20190427004231-96897255fd17 // indirect
7-
github.com/cosmos/cosmos-sdk v0.28.2-0.20190521100210-dd89c329516e
6+
github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c // indirect
7+
github.com/cosmos/cosmos-sdk v0.28.2-0.20190528084404-73e5ef7c13c4
88
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
9-
github.com/gogo/protobuf v1.2.1 // indirect
109
github.com/google/gofuzz v1.0.0 // indirect
1110
github.com/gorilla/mux v1.7.2 // indirect
12-
github.com/kr/pretty v0.1.0 // indirect
1311
github.com/magiconair/properties v1.8.1 // indirect
14-
github.com/mattn/go-isatty v0.0.7 // indirect
12+
github.com/mattn/go-isatty v0.0.8 // indirect
1513
github.com/onsi/ginkgo v1.8.0 // indirect
1614
github.com/onsi/gomega v1.5.0 // indirect
1715
github.com/otiai10/copy v1.0.1
1816
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 // indirect
1917
github.com/pelletier/go-toml v1.4.0 // indirect
20-
github.com/prometheus/client_golang v0.9.3 // indirect
21-
github.com/prometheus/procfs v0.0.0-20190516194456-169873baca24 // indirect
18+
github.com/prometheus/common v0.4.1 // indirect
19+
github.com/prometheus/procfs v0.0.0-20190523193104-a7aeb8df3389 // indirect
2220
github.com/rakyll/statik v0.1.6
2321
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect
2422
github.com/spf13/afero v1.2.2 // indirect
25-
github.com/spf13/cobra v0.0.3
26-
github.com/spf13/viper v1.3.2
23+
github.com/spf13/cobra v0.0.4
24+
github.com/spf13/viper v1.4.0
2725
github.com/stretchr/testify v1.3.0
2826
github.com/syndtr/goleveldb v1.0.0 // indirect
2927
github.com/tendermint/go-amino v0.15.0
3028
github.com/tendermint/tendermint v0.31.5
3129
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
32-
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
33-
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb // indirect
30+
golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e // indirect
3431
golang.org/x/text v0.3.2 // indirect
35-
google.golang.org/grpc v1.19.1 // indirect
36-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
32+
google.golang.org/appengine v1.4.0 // indirect
33+
google.golang.org/genproto v0.0.0-20190522204451-c2c4e71fbf69 // indirect
3734
)
3835

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

0 commit comments

Comments
 (0)