diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d3be5733e..54f1ee8c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly. * [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter. * [\#9639](https://github.com/cosmos/cosmos-sdk/pull/9639) Check store keys length before accessing them by making sure that `key` is of length `m+1` (for `key[n:m]`) * (types) [\#9627](https://github.com/cosmos/cosmos-sdk/pull/9627) Fix nil pointer panic on `NewBigIntFromInt` diff --git a/client/cmd.go b/client/cmd.go index 2a8dd498c5..c2e3ff8a47 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -249,12 +249,8 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err return clientCtx, nil } -// ReadHomeFlag checks if home flag is changed. -// If this is a case, we update HomeDir field of Client Context -/* Discovered a bug with Cory -./build/simd init andrei --home ./test -cd test/config there is no client.toml configuration file -*/ +// ReadHomeFlag checks if home flag is changed. If this is a case, we update +// HomeDir field of Client Context. func ReadHomeFlag(clientCtx Context, cmd *cobra.Command) Context { if cmd.Flags().Changed(flags.FlagHome) { rootDir, _ := cmd.Flags().GetString(flags.FlagHome) diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 87d1223f80..df5b20c006 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" + "github.com/cosmos/go-bip39" "github.com/pkg/errors" "github.com/spf13/cobra" cfg "github.com/tendermint/tendermint/config" @@ -23,7 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/go-bip39" ) const ( @@ -81,6 +81,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config + clientCtx = client.ReadHomeFlag(clientCtx, cmd) config.SetRoot(clientCtx.HomeDir) chainID, _ := cmd.Flags().GetString(flags.FlagChainID) @@ -117,7 +118,6 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { genFile := config.GenesisFile() overwrite, _ := cmd.Flags().GetBool(FlagOverwrite) - stakingBondDenom, _ := cmd.Flags().GetString(FlagStakingBondDenom) if !overwrite && tmos.FileExists(genFile) { @@ -127,17 +127,20 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { appGenState := mbm.DefaultGenesis(cdc) if stakingBondDenom != "" { - stakingRaw := appGenState[stakingtypes.ModuleName] var stakingGenesis stakingtypes.GenesisState + + stakingRaw := appGenState[stakingtypes.ModuleName] err := clientCtx.Codec.UnmarshalJSON(stakingRaw, &stakingGenesis) if err != nil { return err } + stakingGenesis.Params.BondDenom = stakingBondDenom modifiedStakingStr, err := clientCtx.Codec.MarshalJSON(&stakingGenesis) if err != nil { return err } + appGenState[stakingtypes.ModuleName] = modifiedStakingStr } @@ -161,6 +164,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { genDoc.ChainID = chainID genDoc.Validators = nil genDoc.AppState = appState + if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil { return errors.Wrap(err, "Failed to export gensis file") } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index b51f528bf9..d5004d960d 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -27,9 +27,13 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" + "github.com/cosmos/cosmos-sdk/x/staking" ) -var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}) +var testMbm = module.NewBasicManager( + staking.AppModuleBasic{}, + genutil.AppModuleBasic{}, +) func TestInitCmd(t *testing.T) { tests := []struct { @@ -137,7 +141,11 @@ func TestInitStakingBondDenom(t *testing.T) { cmd := genutilcli.InitCmd(testMbm, home) - cmd.SetArgs([]string{"appnode-test", fmt.Sprintf("--%s=%s --%s=testtoken", cli.HomeFlag, home, genutilcli.FlagStakingBondDenom)}) + cmd.SetArgs([]string{ + "appnode-test", + fmt.Sprintf("--%s=%s", cli.HomeFlag, home), + fmt.Sprintf("--%s=testtoken", genutilcli.FlagStakingBondDenom), + }) require.NoError(t, cmd.ExecuteContext(ctx)) }