feat(client/v2): add autocli run + simapp example (#13867)
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julien Robert
parent
02ca843d49
commit
ebfd057716
@@ -10,6 +10,8 @@ import (
|
||||
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||
"cosmossdk.io/client/v2/autocli"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/cast"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@@ -610,6 +612,21 @@ func (app *SimApp) TxConfig() client.TxConfig {
|
||||
return app.txConfig
|
||||
}
|
||||
|
||||
// AutoCliOpts returns the autocli options for the app.
|
||||
func (app *SimApp) AutoCliOpts() autocli.AppOptions {
|
||||
modules := make(map[string]appmodule.AppModule, 0)
|
||||
for _, m := range app.ModuleManager.Modules {
|
||||
if moduleWithName, ok := m.(module.HasName); ok {
|
||||
moduleName := moduleWithName.Name()
|
||||
if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
|
||||
modules[moduleName] = appModule
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return autocli.AppOptions{Modules: modules}
|
||||
}
|
||||
|
||||
// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
|
||||
func (a *SimApp) DefaultGenesis() map[string]json.RawMessage {
|
||||
return ModuleBasics.DefaultGenesis(a.appCodec)
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"cosmossdk.io/core/appconfig"
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||
@@ -62,7 +63,7 @@ var (
|
||||
distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName,
|
||||
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
|
||||
feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
|
||||
vestingtypes.ModuleName, consensustypes.ModuleName,
|
||||
vestingtypes.ModuleName, consensustypes.ModuleName, runtime.ModuleName,
|
||||
}
|
||||
|
||||
// module account permissions
|
||||
@@ -92,7 +93,7 @@ var (
|
||||
AppConfig = appconfig.Compose(&appv1alpha1.Config{
|
||||
Modules: []*appv1alpha1.ModuleConfig{
|
||||
{
|
||||
Name: "runtime",
|
||||
Name: runtime.ModuleName,
|
||||
Config: appconfig.WrapAny(&runtimev1alpha1.Module{
|
||||
AppName: "SimApp",
|
||||
// During begin block slashing happens after distr.BeginBlocker so that
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"cosmossdk.io/client/v2/autocli"
|
||||
"cosmossdk.io/depinject"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
@@ -121,6 +122,7 @@ type SimApp struct {
|
||||
appCodec codec.Codec
|
||||
txConfig client.TxConfig
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
autoCliOpts autocli.AppOptions
|
||||
|
||||
// keepers
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
@@ -221,6 +223,7 @@ func NewSimApp(
|
||||
&app.legacyAmino,
|
||||
&app.txConfig,
|
||||
&app.interfaceRegistry,
|
||||
&app.autoCliOpts,
|
||||
&app.AccountKeeper,
|
||||
&app.BankKeeper,
|
||||
&app.CapabilityKeeper,
|
||||
@@ -317,6 +320,11 @@ func (app *SimApp) TxConfig() client.TxConfig {
|
||||
return app.txConfig
|
||||
}
|
||||
|
||||
// AutoCliOpts returns the autocli options for the app.
|
||||
func (app *SimApp) AutoCliOpts() autocli.AppOptions {
|
||||
return app.autoCliOpts
|
||||
}
|
||||
|
||||
// GetKey returns the KVStoreKey for the provided store key.
|
||||
//
|
||||
// NOTE: This is solely to be used for testing purposes.
|
||||
|
||||
+4
-1
@@ -4,12 +4,13 @@ go 1.19
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.2.6
|
||||
cosmossdk.io/client/v2 v2.0.0-20221207142935-9bf027460bae
|
||||
cosmossdk.io/core v0.4.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.3
|
||||
cosmossdk.io/math v1.0.0-beta.4
|
||||
cosmossdk.io/tools/rosetta v0.2.0
|
||||
github.com/cosmos/cosmos-db v0.0.0-20221226095112-f3c38ecb5e32
|
||||
github.com/cosmos/cosmos-sdk v0.47.0-alpha2
|
||||
github.com/cosmos/cosmos-sdk v0.47.0-alpha2.0.20221219231612-5ed4075ba219
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/spf13/cast v1.5.0
|
||||
github.com/spf13/cobra v1.6.1
|
||||
@@ -175,6 +176,8 @@ require (
|
||||
)
|
||||
|
||||
replace (
|
||||
// todo remove at next tag of client/v2
|
||||
cosmossdk.io/client/v2 => ../client/v2
|
||||
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
|
||||
// Simapp always use the latest version of the cosmos-sdk
|
||||
github.com/cosmos/cosmos-sdk => ../.
|
||||
|
||||
+17
-1
@@ -39,7 +39,9 @@ import (
|
||||
// main function.
|
||||
func NewRootCmd() *cobra.Command {
|
||||
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
|
||||
tempApp := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome))
|
||||
// note, this is not necessary when using app wiring, as depinject can be directly used.
|
||||
// for consistency between app-v1 and app-v2, we do it the same way via methods on simapp
|
||||
tempApp := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir()))
|
||||
encodingConfig := params.EncodingConfig{
|
||||
InterfaceRegistry: tempApp.InterfaceRegistry(),
|
||||
Codec: tempApp.AppCodec(),
|
||||
@@ -88,6 +90,10 @@ func NewRootCmd() *cobra.Command {
|
||||
|
||||
initRootCmd(rootCmd, encodingConfig)
|
||||
|
||||
if err := tempApp.AutoCliOpts().EnhanceRootCommand(rootCmd); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
@@ -307,3 +313,13 @@ func appExport(
|
||||
|
||||
return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
|
||||
}
|
||||
|
||||
var tempDir = func() string {
|
||||
dir, err := os.MkdirTemp("", "simapp")
|
||||
if err != nil {
|
||||
dir = simapp.DefaultNodeHome
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user