diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e4b82b50c37..6579ea3c70a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### CLI Breaking Changes +* [\#9827](https://github.com/cosmos/cosmos-sdk/pull/9827) Ensure input parity of validator public key input between `tx staking create-validator` and `gentx`. * [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) Removed the CLI flag `--setup-config-only` from the `testnet` command and added the subcommand `init-files`. * [\#9371](https://github.com/cosmos/cosmos-sdk/pull/9371) Non-zero default fees/Server will error if there's an empty value for min-gas-price in app.toml diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index db00129a0733..e8d736b2485d 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -77,10 +77,9 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o } // read --pubkey, if empty take it from priv_validator.json - if val, _ := cmd.Flags().GetString(cli.FlagPubKey); val != "" { - err = clientCtx.Codec.UnmarshalJSON([]byte(val), valPubKey) - if err != nil { - return errors.Wrap(err, "failed to unmarshal consensus node public key") + if pkStr, _ := cmd.Flags().GetString(cli.FlagPubKey); pkStr != "" { + if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(pkStr), &valPubKey); err != nil { + return errors.Wrap(err, "failed to unmarshal validator public key") } } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index fd8427988edf..b51f528bf94f 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -46,8 +46,7 @@ func TestInitCmd(t *testing.T) { } }, shouldErr: false, - - err: nil, + err: nil, }, } diff --git a/x/genutil/client/testutil/suite.go b/x/genutil/client/testutil/suite.go index 3a624f28eb38..41aeed9444f8 100644 --- a/x/genutil/client/testutil/suite.go +++ b/x/genutil/client/testutil/suite.go @@ -17,6 +17,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -89,6 +90,44 @@ func (s *IntegrationTestSuite) TestGenTxCmd() { s.Require().Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(msgs[0])) s.Require().Equal([]string{val.Address.String()}, msgs[0].GetSigners()) s.Require().Equal(amount, msgs[0].(*types.MsgCreateValidator).Value) - err = tx.ValidateBasic() - s.Require().NoError(err) + s.Require().NoError(tx.ValidateBasic()) +} + +func (s *IntegrationTestSuite) TestGenTxCmdPubkey() { + val := s.network.Validators[0] + dir := s.T().TempDir() + + cmd := cli.GenTxCmd( + simapp.ModuleBasics, + val.ClientCtx.TxConfig, + banktypes.GenesisBalancesIterator{}, + val.ClientCtx.HomeDir, + ) + + _, out := testutil.ApplyMockIO(cmd) + clientCtx := val.ClientCtx.WithOutput(out) + + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + + amount := sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(12)) + genTxFile := filepath.Join(dir, "myTx") + + cmd.SetArgs([]string{ + fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID), + fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, genTxFile), + fmt.Sprintf("--%s={\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey), + val.Moniker, + amount.String(), + }) + s.Require().Error(cmd.ExecuteContext(ctx)) + + cmd.SetArgs([]string{ + fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID), + fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, genTxFile), + fmt.Sprintf("--%s={\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey), + val.Moniker, + amount.String(), + }) + s.Require().NoError(cmd.ExecuteContext(ctx)) } diff --git a/x/staking/client/cli/flags.go b/x/staking/client/cli/flags.go index 094de343df90..d6725e8c1da4 100644 --- a/x/staking/client/cli/flags.go +++ b/x/staking/client/cli/flags.go @@ -75,7 +75,7 @@ func FlagSetAmount() *flag.FlagSet { // FlagSetPublicKey Returns the flagset for Public Key related operations. func FlagSetPublicKey() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) - fs.String(FlagPubKey, "", "The Bech32 encoded PubKey of the validator") + fs.String(FlagPubKey, "", "The validator's Protobuf JSON encoded public key") return fs }