From ab63b71abd83679658067b5dc61face492960b69 Mon Sep 17 00:00:00 2001 From: billy rennekamp Date: Wed, 14 Jul 2021 19:03:28 +0200 Subject: [PATCH] Merge pull request #907: add back the config command * fix: add back the config command and run linting * test: increase code coverage --- CHANGELOG.md | 1 + app/app.go | 8 +++++--- app/encoding.go | 3 ++- app/migrate.go | 9 +++++---- app/pubkey_replacement.go | 7 ++++--- cmd/gaiad/cmd/root.go | 25 ++++++++++++++++++------- cmd/gaiad/cmd/root_test.go | 23 +++++++++++++++++++++++ 7 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 cmd/gaiad/cmd/root_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index c74d72c7c9d..6c1103aa9f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] +* (gaia) Configure gaiad command to add back `config` capabilities. ## [v5.0.0] - 2021-06-28 diff --git a/app/app.go b/app/app.go index 243d629ed57..e3ae7c1d085 100644 --- a/app/app.go +++ b/app/app.go @@ -7,11 +7,12 @@ import ( "os" "path/filepath" + "github.com/gorilla/mux" + "github.com/rakyll/statik/fs" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/gorilla/mux" - "github.com/rakyll/statik/fs" "github.com/gravity-devs/liquidity/x/liquidity" liquiditykeeper "github.com/gravity-devs/liquidity/x/liquidity/keeper" @@ -23,6 +24,8 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" + gaiaappparams "github.com/cosmos/gaia/v5/app/params" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/client/rpc" @@ -89,7 +92,6 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - gaiaappparams "github.com/cosmos/gaia/v5/app/params" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" diff --git a/app/encoding.go b/app/encoding.go index 466176d40d9..5e7fbea79c4 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -1,8 +1,9 @@ package gaia import ( - "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/gaia/v5/app/params" + + "github.com/cosmos/cosmos-sdk/std" ) // MakeEncodingConfig creates an EncodingConfig for testing diff --git a/app/migrate.go b/app/migrate.go index 65196902d17..70bf8c2cc50 100644 --- a/app/migrate.go +++ b/app/migrate.go @@ -9,6 +9,11 @@ import ( "io/ioutil" "time" + "github.com/pkg/errors" + "github.com/spf13/cobra" + tmjson "github.com/tendermint/tendermint/libs/json" + tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,10 +28,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" ibccoretypes "github.com/cosmos/cosmos-sdk/x/ibc/core/types" staking "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/pkg/errors" - "github.com/spf13/cobra" - tmjson "github.com/tendermint/tendermint/libs/json" - tmtypes "github.com/tendermint/tendermint/types" ) const ( diff --git a/app/pubkey_replacement.go b/app/pubkey_replacement.go index a3460e9382e..774303a5f8b 100644 --- a/app/pubkey_replacement.go +++ b/app/pubkey_replacement.go @@ -6,15 +6,16 @@ import ( "io/ioutil" "log" + "github.com/pkg/errors" + cryptocodec "github.com/tendermint/tendermint/crypto/encoding" + tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/genutil/types" slashing "github.com/cosmos/cosmos-sdk/x/slashing/types" staking "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/pkg/errors" - cryptocodec "github.com/tendermint/tendermint/crypto/encoding" - tmtypes "github.com/tendermint/tendermint/types" ) type replacementConfigs []replacementConfig diff --git a/cmd/gaiad/cmd/root.go b/cmd/gaiad/cmd/root.go index e0d53fcc2bb..5f7b99b27d6 100644 --- a/cmd/gaiad/cmd/root.go +++ b/cmd/gaiad/cmd/root.go @@ -5,8 +5,15 @@ import ( "os" "path/filepath" + "github.com/spf13/cast" + "github.com/spf13/cobra" + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" @@ -23,11 +30,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - "github.com/spf13/cast" - "github.com/spf13/cobra" - tmcli "github.com/tendermint/tendermint/libs/cli" - "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" gaia "github.com/cosmos/gaia/v5/app" "github.com/cosmos/gaia/v5/app/params" @@ -44,13 +46,21 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { WithLegacyAmino(encodingConfig.Amino). WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). - WithHomeDir(gaia.DefaultNodeHome) + WithHomeDir(gaia.DefaultNodeHome). + WithViper("") rootCmd := &cobra.Command{ Use: "gaiad", Short: "Stargate Cosmos Hub App", PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { - if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { + initClientCtx = client.ReadHomeFlag(initClientCtx, cmd) + + initClientCtx, err := config.ReadFromClientConfig(initClientCtx) + if err != nil { + return err + } + + if err = client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } @@ -79,6 +89,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { tmcli.NewCompletionCmd(rootCmd, true), testnetCmd(gaia.ModuleBasics, banktypes.GenesisBalancesIterator{}), debug.Cmd(), + config.Cmd(), ) server.AddCommands(rootCmd, gaia.DefaultNodeHome, newApp, createSimappAndExport, addModuleInitFlags) diff --git a/cmd/gaiad/cmd/root_test.go b/cmd/gaiad/cmd/root_test.go new file mode 100644 index 00000000000..6961661c9f5 --- /dev/null +++ b/cmd/gaiad/cmd/root_test.go @@ -0,0 +1,23 @@ +package cmd_test + +import ( + "testing" + + svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + + app "github.com/cosmos/gaia/v5/app" + "github.com/cosmos/gaia/v5/cmd/gaiad/cmd" + "github.com/stretchr/testify/require" +) + +func TestRootCmdConfig(t *testing.T) { + + rootCmd, _ := cmd.NewRootCmd() + rootCmd.SetArgs([]string{ + "config", // Test the config cmd + "keyring-backend", // key + "test", // value + }) + + require.NoError(t, svrcmd.Execute(rootCmd, app.DefaultNodeHome)) +}