diff --git a/app.go b/app.go index 47611b3f408c..c4f7eeb2018a 100644 --- a/app.go +++ b/app.go @@ -9,9 +9,10 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - bam "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codecstd "github.com/cosmos/cosmos-sdk/codec/std" + "github.com/cosmos/cosmos-sdk/std" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" @@ -95,7 +96,7 @@ var _ App = (*SimApp)(nil) // They are exported for convenience in creating helper functions, as object // capabilities aren't needed for testing. type SimApp struct { - *bam.BaseApp + *baseapp.BaseApp cdc *codec.Codec invCheckPeriod uint @@ -138,19 +139,19 @@ type SimApp struct { // NewSimApp returns a reference to an initialized SimApp. func NewSimApp( logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, - homePath string, invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp), + homePath string, invCheckPeriod uint, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { // TODO: Remove cdc in favor of appCodec once all modules are migrated. cdc := codecstd.MakeCodec(ModuleBasics) appCodec := codecstd.NewAppCodec(cdc) - bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...) + bApp := baseapp.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) keys := sdk.NewKVStoreKeys( - bam.MainStoreKey, auth.StoreKey, bank.StoreKey, staking.StoreKey, + auth.StoreKey, bank.StoreKey, staking.StoreKey, supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey, gov.StoreKey, params.StoreKey, ibc.StoreKey, upgrade.StoreKey, evidence.StoreKey, transfer.StoreKey, capability.StoreKey, @@ -176,7 +177,9 @@ func NewSimApp( app.subspaces[slashing.ModuleName] = app.ParamsKeeper.Subspace(slashing.DefaultParamspace) app.subspaces[gov.ModuleName] = app.ParamsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable()) app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace) - app.subspaces[evidence.ModuleName] = app.ParamsKeeper.Subspace(evidence.DefaultParamspace) + + // set the BaseApp's parameter store + bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(std.ConsensusParamsKeyTable())) // add capability keeper and ScopeToModule for ibc module app.CapabilityKeeper = capability.NewKeeper(appCodec, keys[capability.StoreKey]) @@ -250,7 +253,7 @@ func NewSimApp( // create evidence keeper with router evidenceKeeper := evidence.NewKeeper( - appCodec, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper, + appCodec, keys[evidence.StoreKey], &app.StakingKeeper, app.SlashingKeeper, ) evidenceRouter := evidence.NewRouter(). AddRoute(ibcclient.RouterKey, ibcclient.HandlerClientMisbehaviour(app.IBCKeeper.ClientKeeper)) @@ -330,8 +333,7 @@ func NewSimApp( app.SetEndBlocker(app.EndBlocker) if loadLatest { - err := app.LoadLatestVersion(app.keys[bam.MainStoreKey]) - if err != nil { + if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) } } @@ -370,7 +372,7 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci. // LoadHeight loads a particular height func (app *SimApp) LoadHeight(height int64) error { - return app.LoadVersion(height, app.keys[bam.MainStoreKey]) + return app.LoadVersion(height) } // ModuleAccountAddrs returns all the app's module account addresses. diff --git a/app_test.go b/app_test.go index 17b6b3c28644..1fe5b66065b4 100644 --- a/app_test.go +++ b/app_test.go @@ -32,7 +32,7 @@ func TestSimAppExport(t *testing.T) { // Making a new app object with the db, so that initchain hasn't been called app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) - _, _, err = app2.ExportAppStateAndValidators(false, []string{}) + _, _, _, err = app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } diff --git a/export.go b/export.go index 23a23527921d..84e442fafa2b 100644 --- a/export.go +++ b/export.go @@ -18,7 +18,7 @@ import ( // file. func (app *SimApp) ExportAppStateAndValidators( forZeroHeight bool, jailWhiteList []string, -) (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) { +) (appState json.RawMessage, validators []tmtypes.GenesisValidator, cp *abci.ConsensusParams, err error) { // as if they could withdraw from the start of the next block ctx := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()}) @@ -30,11 +30,11 @@ func (app *SimApp) ExportAppStateAndValidators( genState := app.mm.ExportGenesis(ctx, app.cdc) appState, err = codec.MarshalJSONIndent(app.cdc, genState) if err != nil { - return nil, nil, err + return nil, nil, nil, err } validators = staking.WriteValidators(ctx, app.StakingKeeper) - return appState, validators, nil + return appState, validators, app.BaseApp.GetConsensusParams(ctx), nil } // prepare for fresh start at zero height diff --git a/sim_test.go b/sim_test.go index bcfb64398717..7cec5aa64419 100644 --- a/sim_test.go +++ b/sim_test.go @@ -116,7 +116,7 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("exporting genesis...\n") - appState, _, err := app.ExportAppStateAndValidators(false, []string{}) + appState, _, _, err := app.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err) fmt.Printf("importing genesis...\n") @@ -143,7 +143,6 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("comparing stores...\n") storeKeysPrefixes := []StoreKeysPrefixes{ - {app.keys[baseapp.MainStoreKey], newApp.keys[baseapp.MainStoreKey], [][]byte{}}, {app.keys[auth.StoreKey], newApp.keys[auth.StoreKey], [][]byte{}}, {app.keys[staking.StoreKey], newApp.keys[staking.StoreKey], [][]byte{ @@ -208,7 +207,7 @@ func TestAppSimulationAfterImport(t *testing.T) { fmt.Printf("exporting genesis...\n") - appState, _, err := app.ExportAppStateAndValidators(true, []string{}) + appState, _, _, err := app.ExportAppStateAndValidators(true, []string{}) require.NoError(t, err) fmt.Printf("importing genesis...\n") diff --git a/test_helpers.go b/test_helpers.go index cf6dc8164efc..5caa00f212b4 100644 --- a/test_helpers.go +++ b/test_helpers.go @@ -12,6 +12,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" + tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" bam "github.com/cosmos/cosmos-sdk/baseapp" @@ -24,10 +25,29 @@ import ( "github.com/cosmos/cosmos-sdk/x/supply" ) +// DefaultConsensusParams defines the default Tendermint consensus params used in +// SimApp testing. +var DefaultConsensusParams = &abci.ConsensusParams{ + Block: &abci.BlockParams{ + MaxBytes: 200000, + MaxGas: 2000000, + }, + Evidence: &abci.EvidenceParams{ + MaxAgeNumBlocks: 302400, + MaxAgeDuration: 1814400, + }, + Validator: &abci.ValidatorParams{ + PubKeyTypes: []string{ + tmtypes.ABCIPubKeyTypeEd25519, + tmtypes.ABCIPubKeyTypeSecp256k1, + }, + }, +} + // Setup initializes a new SimApp. A Nop logger is set in SimApp. func Setup(isCheckTx bool) *SimApp { db := dbm.NewMemDB() - app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) + app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5) if !isCheckTx { // init chain must be called to stop deliverState from being nil genesisState := NewDefaultGenesisState() @@ -39,8 +59,9 @@ func Setup(isCheckTx bool) *SimApp { // Initialize the chain app.InitChain( abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - AppStateBytes: stateBytes, + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: DefaultConsensusParams, + AppStateBytes: stateBytes, }, ) } @@ -70,8 +91,9 @@ func SetupWithGenesisAccounts(genAccs []authexported.GenesisAccount, balances .. app.InitChain( abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - AppStateBytes: stateBytes, + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: DefaultConsensusParams, + AppStateBytes: stateBytes, }, ) diff --git a/types.go b/types.go index a3f146f67ceb..64c1fe53f3e7 100644 --- a/types.go +++ b/types.go @@ -36,7 +36,7 @@ type App interface { // Exports the state of the application for a genesis file. ExportAppStateAndValidators( forZeroHeight bool, jailWhiteList []string, - ) (json.RawMessage, []tmtypes.GenesisValidator, error) + ) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) // All the registered module account addreses. ModuleAccountAddrs() map[string]bool diff --git a/utils.go b/utils.go index d023040d753d..8cd3822722e6 100644 --- a/utils.go +++ b/utils.go @@ -76,7 +76,7 @@ func CheckExportSimulation( ) error { if config.ExportStatePath != "" { fmt.Println("exporting app state...") - appState, _, err := app.ExportAppStateAndValidators(false, nil) + appState, _, _, err := app.ExportAppStateAndValidators(false, nil) if err != nil { return err }