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

application interfaces for simulation #5378

Merged
merged 20 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove baseapp getter
  • Loading branch information
fedekunze committed Dec 9, 2019
commit 68024d3ab33337b80c2cf820ba4a338cd5b785c7
3 changes: 0 additions & 3 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@ func NewSimApp(
// Name returns the name of the App
func (app *SimApp) Name() string { return app.BaseApp.Name() }

// GetBaseApp returns the application's BaseApp
func (app *SimApp) GetBaseApp() *bam.BaseApp { return app.BaseApp }

// BeginBlocker application updates every begin block
func (app *SimApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
Expand Down
4 changes: 2 additions & 2 deletions simapp/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
logger := log.NewNopLogger()
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, interBlockCacheOpt())

err = RunSimulation(b, os.Stdout, db, app, config)
err = RunSimulation(b, os.Stdout, db, app, app.BaseApp, config)
if err != nil {
fmt.Println(err)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
b.FailNow()
Expand Down Expand Up @@ -59,7 +59,7 @@ func BenchmarkInvariants(b *testing.B) {
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, interBlockCacheOpt())

// 2. Run parameterized simulation (w/o invariants)
err = RunSimulation(b, os.Stdout, db, app, config)
err = RunSimulation(b, os.Stdout, db, app, app.BaseApp, config)
if err != nil {
fmt.Println(err)
b.FailNow()
Expand Down
10 changes: 5 additions & 5 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestFullAppSimulation(t *testing.T) {
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name())

err = RunSimulation(t, os.Stdout, db, app, config)
err = RunSimulation(t, os.Stdout, db, app, app.BaseApp, config)
require.NoError(t, err)
}

Expand All @@ -77,7 +77,7 @@ func TestAppImportExport(t *testing.T) {
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name())

err = RunSimulation(t, os.Stdout, db, app, config)
err = RunSimulation(t, os.Stdout, db, app, app.BaseApp, config)
require.NoError(t, err)

fmt.Printf("exporting genesis...\n")
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name())

err = RunSimulation(t, os.Stdout, db, app, config)
err = RunSimulation(t, os.Stdout, db, app, app.BaseApp, config)
require.NoError(t, err)

fmt.Printf("exporting genesis...\n")
Expand All @@ -184,7 +184,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
AppStateBytes: appState,
})

err = RunSimulation(t, os.Stdout, db, newApp, config)
err = RunSimulation(t, os.Stdout, db, newApp, newApp.BaseApp, config)
require.NoError(t, err)
}

Expand Down Expand Up @@ -227,7 +227,7 @@ func TestAppStateDeterminism(t *testing.T) {
config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
)

err := RunSimulation(t, os.Stdout, db, app, config)
err := RunSimulation(t, os.Stdout, db, app, app.BaseApp, config)
require.NoError(t, err)

appHash := app.LastCommitID().Hash
Expand Down
2 changes: 1 addition & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func AddTestAddrs(app *SimApp, ctx sdk.Context, accNum int, accAmt sdk.Int) []sd

// CheckBalance checks the balance of an account.
func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, exp sdk.Coins) {
ctxCheck := app.GetBaseApp().NewContext(true, abci.Header{})
ctxCheck := app.BaseApp.NewContext(true, abci.Header{})
res := app.AccountKeeper.GetAccount(ctxCheck, addr)

require.Equal(t, exp, res.GetCoins())
Expand Down
7 changes: 0 additions & 7 deletions simapp/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,16 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/params"
)

// App implements the common methods for a Cosmos SDK-based application
// specific blockchain.
type App interface {
GetBaseApp() *baseapp.BaseApp

Name() string
Codec() *codec.Codec
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
GetKey(storeKey string) *sdk.KVStoreKey
GetTKey(storeKey string) *sdk.TransientStoreKey
GetSubspace(moduleName string) params.Subspace

BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock
EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock
Expand Down
6 changes: 4 additions & 2 deletions simapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
"github.com/cosmos/cosmos-sdk/simapp/types"
Expand Down Expand Up @@ -194,11 +195,12 @@ func SetupSimulation(dirPrefix, dbName string) (simulation.Config, dbm.DB, strin
// RunSimulation runs a randomized simulation from the operations defined in an
// app. It also exports the state and params and prints the DB stats.
func RunSimulation(
tb testing.TB, w io.Writer, db dbm.DB, app types.App, config simulation.Config,
tb testing.TB, w io.Writer, db dbm.DB, app types.App, bapp *baseapp.BaseApp,
config simulation.Config,
) error {
// run randomized simulation
stopEarly, simParams, simErr := simulation.SimulateFromSeed(
tb, w, app.GetBaseApp(), AppStateFn(app.Codec(), app.SimulationManager()),
tb, w, bapp, AppStateFn(app.Codec(), app.SimulationManager()),
SimulationOperations(app, app.Codec(), config),
app.ModuleAccountAddrs(), config,
)
Expand Down