fix!: update gentx val pub key input parsing (#9827)

This commit is contained in:
Aleksandr Bezobchuk 2021-08-02 11:06:24 -04:00 committed by GitHub
parent 56589f1cc8
commit cbac7fc248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 9 deletions

View File

@ -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

View File

@ -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")
}
}

View File

@ -46,8 +46,7 @@ func TestInitCmd(t *testing.T) {
}
},
shouldErr: false,
err: nil,
err: nil,
},
}

View File

@ -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))
}

View File

@ -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
}