refactor: move simapp.App to runtime.AppI (#13378)

* refactor: move `simapp.App` to `runtime.AppI`

* add changelog

* `go mod tidy`

* fix app legacy build
This commit is contained in:
Julien Robert 2022-09-24 13:49:11 +02:00 committed by GitHub
parent af816057f2
commit b76f338511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 11 deletions

View File

@ -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`.

View File

@ -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.

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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

View File

@ -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)
)

View File

@ -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)
)

View File

@ -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...")