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

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

Merged
merged 7 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
return errors.Wrap(err, "failed to unmarshal validator public key")
}
}

Expand Down
3 changes: 1 addition & 2 deletions x/genutil/client/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func TestInitCmd(t *testing.T) {
}
},
shouldErr: false,

err: nil,
err: nil,
},
}

Expand Down
43 changes: 41 additions & 2 deletions x/genutil/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion x/staking/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down