Merge PR #6750: Revert to allow to set DefaultNodeHome as a param in genutil CLI cmds

This commit is contained in:
Jonathan Gimeno 2020-07-17 16:20:31 +02:00 committed by GitHub
parent d3056a9d64
commit cdcb51a922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 21 deletions

View File

@ -50,7 +50,8 @@ var (
WithCodec(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)).
WithBroadcastMode(flags.BroadcastBlock)
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(simapp.DefaultNodeHome)
)
// Execute executes the root command.
@ -74,9 +75,9 @@ func init() {
rootCmd.AddCommand(
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
genutilcli.GenTxCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(simapp.ModuleBasics),
AddGenesisAccountCmd(),
cli.NewCompletionCmd(rootCmd, true),

View File

@ -16,7 +16,7 @@ import (
// Returns the directory path and a cleanup function.
// nolint: errcheck
func NewTestCaseDir(t testing.TB) (string, func()) {
dir, err := ioutil.TempDir("", t.Name()+"_")
dir, err := ioutil.TempDir("", strings.ReplaceAll(t.Name(), "/", "_")+"_")
require.NoError(t, err)
return dir, func() { os.RemoveAll(dir) }
}

View File

@ -18,7 +18,7 @@ import (
const flagGenTxDir = "gentx-dir"
// CollectGenTxsCmd - return the cobra command to collect genesis transactions
func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator) *cobra.Command {
func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "collect-gentxs",
Short: "Collect genesis txs and output a genesis.json file",
@ -61,7 +61,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator) *cobra.Comma
},
}
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flagGenTxDir, "", "override default \"gentx\" directory from which collect and execute genesis transactions; default [--home]/config/gentx/")
return cmd

View File

@ -31,7 +31,7 @@ import (
)
// GenTxCmd builds the application's gentx command.
func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesIterator) *cobra.Command {
func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command {
ipDefault, _ := server.ExternalIP()
fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault)
@ -189,7 +189,7 @@ $ %s gentx my-key-name --home=/path/to/home/dir --keyring-backend=os --chain-id=
},
}
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flags.FlagOutputDocument, "", "Write the genesis transaction JSON document to the given file instead of the default location")
cmd.Flags().String(flags.FlagChainID, "", "The network chain ID")
cmd.Flags().AddFlagSet(fsCreateValidator)

View File

@ -42,24 +42,56 @@ func createDefaultTendermintConfig(rootDir string) (*tmcfg.Config, error) {
}
func TestInitCmd(t *testing.T) {
home, cleanup := testutil.NewTestCaseDir(t)
t.Cleanup(cleanup)
tests := []struct {
name string
flags func(dir string) []string
shouldErr bool
err error
}{
{
name: "happy path",
flags: func(dir string) []string {
return []string{
"appnode-test",
}
},
shouldErr: false,
logger := log.NewNopLogger()
cfg, err := createDefaultTendermintConfig(home)
require.NoError(t, err)
err: nil,
},
}
serverCtx := server.NewContext(viper.New(), cfg, logger)
clientCtx := client.Context{}.WithJSONMarshaler(makeCodec()).WithHomeDir(home)
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
home, cleanup := testutil.NewTestCaseDir(t)
defer cleanup()
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)
logger := log.NewNopLogger()
cfg, err := createDefaultTendermintConfig(home)
require.NoError(t, err)
cmd := InitCmd(testMbm, home)
cmd.SetArgs([]string{"appnode-test"})
serverCtx := server.NewContext(viper.New(), cfg, logger)
clientCtx := client.Context{}.WithJSONMarshaler(makeCodec()).WithHomeDir(home)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)
cmd := InitCmd(testMbm, home)
cmd.SetArgs(
tt.flags(home),
)
if tt.shouldErr {
err := cmd.ExecuteContext(ctx)
require.EqualError(t, err, tt.err.Error())
} else {
require.NoError(t, cmd.ExecuteContext(ctx))
}
})
}
require.NoError(t, cmd.ExecuteContext(ctx))
}
func setupClientHome(t *testing.T) func() {