From b76f338511fa37f0b8f6aa4820f66760945811a2 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 24 Sep 2022 13:49:11 +0200 Subject: [PATCH] refactor: move `simapp.App` to `runtime.AppI` (#13378) * refactor: move `simapp.App` to `runtime.AppI` * add changelog * `go mod tidy` * fix app legacy build --- CHANGELOG.md | 1 + UPGRADING.md | 6 ++++-- go.mod | 1 - go.sum | 2 -- {simapp => runtime}/types.go | 4 ++-- simapp/app.go | 5 ++++- simapp/app_legacy.go | 6 +++++- simapp/utils.go | 5 +++-- 8 files changed, 19 insertions(+), 11 deletions(-) rename {simapp => runtime}/types.go (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38e7d8c1e2..dcc738b535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#13378](https://github.com/cosmos/cosmos-sdk/pull/13378) Move `simapp.App` to `runtime.AppI`. `simapp.App` is now an alias of `runtime.AppI`. * (tx) [#12659](https://github.com/cosmos/cosmos-sdk/pull/12659) Remove broadcast mode `block`. * (db) [#13370](https://github.com/cosmos/cosmos-sdk/pull/13370) remove storev2alpha1, see also https://github.com/cosmos/cosmos-sdk/pull/13371 * (context) [#13063](https://github.com/cosmos/cosmos-sdk/pull/13063) Update `Context#CacheContext` to automatically emit all events on the parent context's `EventManager`. diff --git a/UPGRADING.md b/UPGRADING.md index 6d364475b7..ea8346c4a5 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -14,15 +14,17 @@ Remove `Querier`, `Route` and `LegacyQuerier` from the app module interface. Thi ### SimApp -SimApp's `app.go` is using App Wiring, the dependency injection framework of the Cosmos SDK. +SimApp's `app.go` is now using [App Wiring](https://docs.cosmos.network/main/building-chain/depinject.html), the dependency injection framework of the Cosmos SDK. This means that modules are injected directly into SimApp thanks to a [configuration file](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_config.go). -The old behavior is preserved and still can be used, without the dependency injection framework, as shows [`app_legacy.go`](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_legacy.go). +The old behavior is preserved and can still be used, without the dependency injection framework, as shows [`app_legacy.go`](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_legacy.go). The constructor, `NewSimApp` has been simplified: * `NewSimApp` does not take encoding parameters (`encodingConfig`) as input, instead the encoding parameters are injected (when using app wiring), or directly created in the constructor. Instead, we can instantiate `SimApp` for getting the encoding configuration. * `NewSimApp` now uses `AppOptions` for getting the home path (`homePath`) and the invariant checks period (`invCheckPeriod`). These were unnecessary given as arguments as they were already present in the `AppOptions`. +SimApp should not be imported in your own app. Instead, you should import the `runtime.AppI` interface, that defines an `App`, and use the [`simtestutil` package](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/testutil/sims) for application testing. + ### Encoding `simapp.MakeTestEncodingConfig()` was deprecated and has been removed. Instead you can use the `TestEncodingConfig` from the `types/module/testutil` package. diff --git a/go.mod b/go.mod index 09aee0044c..defdc4b8c9 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,6 @@ require ( github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 github.com/improbable-eng/grpc-web v0.15.0 github.com/jhump/protoreflect v1.12.1-0.20220721211354-060cc04fc18b - github.com/lazyledger/smt v0.2.1-0.20210709230900-03ea40719554 github.com/magiconair/properties v1.8.6 github.com/manifoldco/promptui v0.9.0 github.com/mattn/go-isatty v0.0.16 diff --git a/go.sum b/go.sum index 3ae9f2139c..b34c7f26a2 100644 --- a/go.sum +++ b/go.sum @@ -549,8 +549,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/lazyledger/smt v0.2.1-0.20210709230900-03ea40719554 h1:nDOkLO7klmnEw1s4AyKt1Arvpgyh33uj1JmkYlJaDsk= -github.com/lazyledger/smt v0.2.1-0.20210709230900-03ea40719554/go.mod h1:9+Pb2/tg1PvEgW7aFx4bFhDE4bvbI03zuJ8kb7nJ9Jc= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs= diff --git a/simapp/types.go b/runtime/types.go similarity index 96% rename from simapp/types.go rename to runtime/types.go index 1b434ea671..b5abc22059 100644 --- a/simapp/types.go +++ b/runtime/types.go @@ -1,4 +1,4 @@ -package simapp +package runtime import ( abci "github.com/tendermint/tendermint/abci/types" @@ -11,7 +11,7 @@ import ( // App implements the common methods for a Cosmos SDK-based application // specific blockchain. -type App interface { +type AppI interface { // The assigned name of the app. Name() string diff --git a/simapp/app.go b/simapp/app.go index 5c8e3a4f89..e6e3d3a874 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -89,6 +89,9 @@ import ( ) var ( + // App is deprecated, use runtime.AppI instead + App runtime.AppI + // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -124,7 +127,7 @@ var ( ) var ( - _ App = (*SimApp)(nil) + _ runtime.AppI = (*SimApp)(nil) _ servertypes.Application = (*SimApp)(nil) ) diff --git a/simapp/app_legacy.go b/simapp/app_legacy.go index 0ec41fc412..ba664d41f2 100644 --- a/simapp/app_legacy.go +++ b/simapp/app_legacy.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" @@ -99,6 +100,9 @@ import ( const appName = "SimApp" var ( + // App is deprecated, use runtime.AppI instead + App runtime.AppI + // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -145,7 +149,7 @@ var ( ) var ( - _ App = (*SimApp)(nil) + _ runtime.AppI = (*SimApp)(nil) _ servertypes.Application = (*SimApp)(nil) ) diff --git a/simapp/utils.go b/simapp/utils.go index b18ff77dbe..4c2e7de0f4 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -9,6 +9,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -49,7 +50,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, // SimulationOperations retrieves the simulation params from the provided file path // and returns all the modules weighted operations -func SimulationOperations(app App, cdc codec.JSONCodec, config simtypes.Config) []simtypes.WeightedOperation { +func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes.Config) []simtypes.WeightedOperation { simState := module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, @@ -74,7 +75,7 @@ func SimulationOperations(app App, cdc codec.JSONCodec, config simtypes.Config) // CheckExportSimulation exports the app state and simulation parameters to JSON // if the export paths are defined. func CheckExportSimulation( - app App, config simtypes.Config, params simtypes.Params, + app runtime.AppI, config simtypes.Config, params simtypes.Params, ) error { if config.ExportStatePath != "" { fmt.Println("exporting app state...")