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: added key when dry-run is true #9480

Merged
merged 6 commits into from
Jun 25, 2021
Merged

Conversation

ryanchristo
Copy link
Contributor

@ryanchristo ryanchristo commented Jun 8, 2021

Description

Closes: #9475

This pull request ensures a key is not added after running keys add with --dry-run. This pull request also adds consistent output information for each key (previously multisig and pubkey did not print info).


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change - n/a
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules - n/a
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code - n/a
  • updated the relevant documentation or specification - n/a
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@github-actions github-actions bot added C:CLI C:Keys Keybase, KMS and HSMs labels Jun 8, 2021
@codecov
Copy link

codecov bot commented Jun 8, 2021

Codecov Report

Merging #9480 (ed64981) into master (3fd376b) will increase coverage by 0.03%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9480      +/-   ##
==========================================
+ Coverage   60.66%   60.70%   +0.03%     
==========================================
  Files         588      588              
  Lines       37273    37277       +4     
==========================================
+ Hits        22612    22628      +16     
+ Misses      12715    12699      -16     
- Partials     1946     1950       +4     
Impacted Files Coverage Δ
crypto/keyring/keyring.go 59.11% <0.00%> (ø)
client/keys/add.go 70.34% <76.92%> (+7.84%) ⬆️

@ryanchristo ryanchristo changed the title fix: delete added key when dry-run is true fix: added key when dry-run is true Jun 8, 2021
@ryanchristo ryanchristo force-pushed the ryan/9475-add-key-dry-run branch 2 times, most recently from 13e19b1 to 206c0bf Compare June 8, 2021 19:26
@@ -100,10 +100,11 @@ input
output
- armor encrypted private key (saved to file)
*/
func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *bufio.Reader) error {
func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *bufio.Reader) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not not sure why this was public before.

@RiccardoM
Copy link
Contributor

I think it would be worth to add a regression test to make sure this does not happen again in the future as it might break a lot of things

}

return printCreate(cmd, info, false, "", outputFormat)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print info for multisig as we do for other keys.

}
}

return printCreate(cmd, info, false, "", outputFormat)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print info for pubkey as we do for other keys.

@ryanchristo ryanchristo force-pushed the ryan/9475-add-key-dry-run branch 3 times, most recently from 5ba63d4 to 9e3edfe Compare June 11, 2021 17:24
@ryanchristo ryanchristo marked this pull request as ready for review June 11, 2021 17:43
@cyberbono3 cyberbono3 self-requested a review June 15, 2021 12:42

multisigKeys, _ := cmd.Flags().GetStringSlice(flagMultisig)
if len(multisigKeys) != 0 {
var pks []cryptotypes.PubKey
Copy link
Contributor

@cyberbono3 cyberbono3 Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better efficiency, I would define pks as slice with finite cap like that pks := make([]cryptotypes.PubKey, len(multisigKeys))

Copy link
Contributor Author

@ryanchristo ryanchristo Jun 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This causes a panic on line 162 with sorting. Maybe we can optimize in a separate pull request?

Copy link
Contributor

@cyberbono3 cyberbono3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I manual tested :

./build/simd keys add jack
./build/simd keys add jack --dry-run
override the existing name jack [y/N]: y
Error: override not available with --dry-run

should I perform more manual testing?

@RiccardoM
Copy link
Contributor

RiccardoM commented Jun 15, 2021

LGTM
I manual tested :

./build/simd keys add jack
./build/simd keys add jack --dry-run
override the existing name jack [y/N]: y
Error: override not available with --dry-run

should I perform more manual testing?

What? It asks you if you want to override?! Shouldn't --dry-run simply output the address and other values without asking you anything, as it used to do?

@ryanchristo
Copy link
Contributor Author

ryanchristo commented Jun 15, 2021

should I perform more manual testing?

Yes, please. I manually tested the --dry-run flag with the four options defined in the tests:

./build/simd keys add jack1 --dry-run
./build/simd keys add jack1
./build/simd keys add jack2 --multisig <KEYNAME> --dry-run
./build/simd keys add jack2 --multisig <KEYNAME>
./build/simd keys add jack3 --pubkey <PUBKEY> --dry-run
./build/simd keys add jack3 --pubkey <PUBKEY>
./build/simd keys add jack4 --ledger --dry-run
./build/simd keys add jack4 --ledger

What? It asks you if you want to override?! Shouldn't --dry-run simply output the address and other values without asking you anything, as it used to do?

--dry-run will output the address and other values. If you provide a key name that already exists, it will ask you if you want to override that key name, simulating the prompt but not allowing you to proceed if --dry-run is enabled. Previously using dry run did not simulate this step and it did not work for adding a multisig account. It also did not print out the information for multisg and pubkey. This pull request fixes these issues and ensures the added account is cleaned up if dry-run is enabled.

@RiccardoM
Copy link
Contributor

I manually tested the --dry-run flag with the four options defined in the tests:

What if you first add a key and the use --dry-run? Does it work? Cause it used to:

simd keys add jack
simd keys add jack --dry-run

Before this bug, --dry-run didn't care if the key name was already present. It simply created a new account and displayed the option without storing in memory. IMO, this is the behavior that developers are used to and should be preserved, without the prompt of overriding the key or similar.

@ryanchristo ryanchristo marked this pull request as draft June 15, 2021 17:03
@ryanchristo
Copy link
Contributor Author

@RiccardoM Thanks for clarifying the issue and providing feedback. I will take another look.

@ryanchristo ryanchristo force-pushed the ryan/9475-add-key-dry-run branch 2 times, most recently from b7d47e7 to c2a6c76 Compare June 19, 2021 03:48
@ryanchristo ryanchristo marked this pull request as ready for review June 19, 2021 04:19
Copy link
Contributor

@blushi blushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@@ -136,7 +141,6 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
}
}

multisigKeys, _ := cmd.Flags().GetStringSlice(flagMultisig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why moving it out of the else scope? seems like it's only used here

client/keys/add.go Outdated Show resolved Hide resolved
client/keys/add.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cyberbono3 cyberbono3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@amaury1093
Copy link
Contributor

@RiccardoM does this PR look good to you? Should we put automerge?

@RiccardoM
Copy link
Contributor

@RiccardoM does this PR look good to you? Should we put automerge?

tACK, implementations looks great 👍

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 25, 2021
@mergify mergify bot merged commit 7679820 into master Jun 25, 2021
@mergify mergify bot deleted the ryan/9475-add-key-dry-run branch June 25, 2021 11:55
RiccardoM added a commit to desmos-labs/cosmos-sdk that referenced this pull request Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:CLI C:Keys Keybase, KMS and HSMs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keys add returns error with --dry-run
5 participants