Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R] Require moniker on gaiad init #2773

Merged
merged 7 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ IMPROVEMENTS
* [\#2749](https://github.com/cosmos/cosmos-sdk/pull/2749) Add --chain-id flag to gaiad testnet

* Gaia
* Require moniker to be provided on `gaiad init`.
- #2672 [Makefile] Updated for better Windows compatibility and ledger support logic, get_tools was rewritten as a cross-compatible Makefile.

* SDK
Expand Down
10 changes: 7 additions & 3 deletions cmd/gaia/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,27 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
RunE: func(_ *cobra.Command, _ []string) error {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))

chainID := viper.GetString(client.FlagChainID)
if chainID == "" {
chainID = fmt.Sprintf("test-chain-%v", common.RandStr(6))
}

nodeID, _, err := InitializeNodeValidatorFiles(config)
if err != nil {
return err
}

if viper.GetString(flagMoniker) != "" {
config.Moniker = viper.GetString(flagMoniker)
}
config.Moniker = viper.GetString(flagMoniker)

var appState json.RawMessage
genFile := config.GenesisFile()

if appState, err = initializeEmptyGenesis(cdc, genFile, chainID,
viper.GetBool(flagOverwrite)); err != nil {
return err
}

if err = ExportGenesisFile(genFile, chainID, nil, appState); err != nil {
return err
}
Expand All @@ -87,9 +89,11 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
},
}

cmd.MarkFlagRequired(flagMoniker)
cmd.Flags().String(cli.HomeFlag, app.DefaultNodeHome, "node's home directory")
cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().String(client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(flagMoniker, "", "set the validator's moniker")

return cmd
}
17 changes: 14 additions & 3 deletions cmd/gaia/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package init

import (
"bytes"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/tendermint/tendermint/libs/cli"
"io"
"io/ioutil"
"os"
"testing"
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/mock"
"github.com/stretchr/testify/require"
Expand All @@ -28,12 +29,16 @@ func TestInitCmd(t *testing.T) {
logger := log.NewNopLogger()
cfg, err := tcmd.ParseConfig()
require.Nil(t, err)

ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenState,
}
cmd := InitCmd(ctx, cdc, appInit)

viper.Set(flagMoniker, "gaianode-test")

err = cmd.RunE(nil, nil)
require.NoError(t, err)
}
Expand All @@ -53,14 +58,19 @@ func setupClientHome(t *testing.T) func() {
func TestEmptyState(t *testing.T) {
defer server.SetupViper(t)()
defer setupClientHome(t)()

logger := log.NewNopLogger()
cfg, err := tcmd.ParseConfig()
require.Nil(t, err)

ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenStateEmpty,
}

viper.Set(flagMoniker, "gaianode-test")

cmd := InitCmd(ctx, cdc, appInit)
err = cmd.RunE(nil, nil)
require.NoError(t, err)
Expand All @@ -69,6 +79,7 @@ func TestEmptyState(t *testing.T) {
r, w, _ := os.Pipe()
os.Stdout = w
cmd = server.ExportCmd(ctx, cdc, nil)

err = cmd.RunE(nil, nil)
require.NoError(t, err)

Expand Down