Skip to content

Commit

Permalink
bug: fix tx, query commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Dec 4, 2023
1 parent 547ac13 commit 1d48007
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
23 changes: 23 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
tmos "github.com/cometbft/cometbft/libs/os"

"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
"cosmossdk.io/simapp"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -874,6 +876,27 @@ func (app *EthermintApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// AutoCliOpts returns the autocli options for the app.
func (app *EthermintApp) AutoCliOpts() autocli.AppOptions {
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range app.mm.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,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.mm.Modules),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
24 changes: 22 additions & 2 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

// rosettaCmd "github.com/cosmos/rosetta/cmd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/evmos/ethermint/app"
ethermintclient "github.com/evmos/ethermint/client"
Expand All @@ -71,6 +73,17 @@ const EnvPrefix = "ETHERMINT"
// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
tempApp := app.NewEthermintApp(
log.NewNopLogger(),
dbm.NewMemDB(),
nil,
true,
map[int64]bool{},
app.DefaultNodeHome,
0,
encoding.MakeConfig(app.ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(app.DefaultNodeHome),
)
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
Expand Down Expand Up @@ -177,6 +190,15 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
ethermintclient.KeyCommands(app.DefaultNodeHome),
)

autoCliOpts := tempApp.AutoCliOpts()
initClientCtx, _ = config.ReadFromClientConfig(initClientCtx)
autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring)
autoCliOpts.ClientCtx = initClientCtx

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}

rootCmd, err := srvflags.AddTxFlags(rootCmd)
if err != nil {
panic(err)
Expand Down Expand Up @@ -210,7 +232,6 @@ func queryCommand() *cobra.Command {
sdkserver.QueryBlockResultsCmd(),
)

app.ModuleBasics.AddQueryCommands(cmd)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

return cmd
Expand All @@ -237,7 +258,6 @@ func txCommand() *cobra.Command {
authcmd.GetSimulateCmd(),
)

// app.ModuleBasics.AddTxCommands(cmd) // <-
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

return cmd
Expand Down
4 changes: 3 additions & 1 deletion tests/importer/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ func (suite *ImporterTestSuite) TestImportBlocks() {
accumulateRewards(chainConfig, vmdb, header, block.Uncles())

// simulate BaseApp EndBlocker commitment
suite.app.EndBlocker(ctx.WithBlockHeight(tmheader.Height))
suite.app.FinalizeBlock(&types.RequestFinalizeBlock{
Height: tmheader.Height,
})
suite.app.Commit()

// block debugging output
Expand Down

0 comments on commit 1d48007

Please sign in to comment.