mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
CLEANUP: validator exit prompt (#13057)
* removing check special phrase in url from validator exit * fixing missed tests * fixing unit test and addressing preston/sammy's comments * fixing test * sammy's comments * deepsource recommendation * Update validator/accounts/accounts_helper.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * sammy's review --------- Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
4809da62cc
commit
71fa70ce40
@ -90,7 +90,7 @@ func TestExitAccountsCli_OK(t *testing.T) {
|
||||
|
||||
// Prepare user input for final confirmation step
|
||||
var stdin bytes.Buffer
|
||||
stdin.Write([]byte(accounts.ExitPassphrase))
|
||||
stdin.Write([]byte("Y"))
|
||||
rawPubKeys, formattedPubKeys, err := accounts.FilterExitAccountsFromUserInput(
|
||||
cliCtx, &stdin, validatingPublicKeys, false,
|
||||
)
|
||||
@ -190,7 +190,7 @@ func TestExitAccountsCli_OK_AllPublicKeys(t *testing.T) {
|
||||
|
||||
// Prepare user input for final confirmation step
|
||||
var stdin bytes.Buffer
|
||||
stdin.Write([]byte(accounts.ExitPassphrase))
|
||||
stdin.Write([]byte("Y"))
|
||||
rawPubKeys, formattedPubKeys, err := accounts.FilterExitAccountsFromUserInput(
|
||||
cliCtx, &stdin, validatingPublicKeys, false,
|
||||
)
|
||||
|
@ -79,10 +79,12 @@ func ValidatePasswordInput(input string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidatePhrase checks whether the user input is equal to the wanted phrase. The verification is case sensitive.
|
||||
func ValidatePhrase(input, wantedPhrase string) error {
|
||||
if strings.TrimSpace(input) != wantedPhrase {
|
||||
return errIncorrectPhrase
|
||||
// ValidatePhrase checks whether the user input is equal to the wanted phrase(s).
|
||||
func ValidatePhrase(input string, wantedPhrases ...string) error {
|
||||
for _, wantedPhrase := range wantedPhrases {
|
||||
if strings.EqualFold(strings.TrimSpace(input), wantedPhrase) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return errIncorrectPhrase
|
||||
}
|
||||
|
@ -153,9 +153,7 @@ func TestValidatePhrase(t *testing.T) {
|
||||
assert.NotNil(t, err)
|
||||
assert.ErrorContains(t, errIncorrectPhrase.Error(), err)
|
||||
})
|
||||
t.Run("wrong letter case", func(t *testing.T) {
|
||||
err := ValidatePhrase("Wanted Phrase", wantedPhrase)
|
||||
assert.NotNil(t, err)
|
||||
assert.ErrorContains(t, errIncorrectPhrase.Error(), err)
|
||||
t.Run("any letter case", func(t *testing.T) {
|
||||
assert.NoError(t, ValidatePhrase("Wanted Phrase", wantedPhrase))
|
||||
})
|
||||
}
|
||||
|
@ -33,9 +33,6 @@ type PerformExitCfg struct {
|
||||
OutputDirectory string
|
||||
}
|
||||
|
||||
// ExitPassphrase exported for use in test.
|
||||
const ExitPassphrase = "Exit my validator"
|
||||
|
||||
// Exit performs a voluntary exit on one or more accounts.
|
||||
func (acm *AccountsCLIManager) Exit(ctx context.Context) error {
|
||||
// User decided to cancel the voluntary exit.
|
||||
@ -106,7 +103,7 @@ func PerformVoluntaryExit(
|
||||
} else {
|
||||
log.WithError(err).Errorf("voluntary exit failed for account %s", cfg.FormattedPubKeys[i])
|
||||
}
|
||||
} else if err := writeSignedVoluntaryExitJSON(ctx, sve, cfg.OutputDirectory); err != nil {
|
||||
} else if err := writeSignedVoluntaryExitJSON(sve, cfg.OutputDirectory); err != nil {
|
||||
log.WithError(err).Error("failed to write voluntary exit")
|
||||
}
|
||||
} else if err := client.ProposeExit(ctx, cfg.ValidatorClient, cfg.Keymanager.Sign, key, epoch); err != nil {
|
||||
@ -180,7 +177,7 @@ func displayExitInfo(rawExitedKeys [][]byte, trimmedExitedKeys []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func writeSignedVoluntaryExitJSON(ctx context.Context, sve *eth.SignedVoluntaryExit, outputDirectory string) error {
|
||||
func writeSignedVoluntaryExitJSON(sve *eth.SignedVoluntaryExit, outputDirectory string) error {
|
||||
if err := file.MkdirAll(outputDirectory); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
@ -53,7 +52,7 @@ func TestWriteSignedVoluntaryExitJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
output := path.Join(bazel.TestTmpDir(), "TestWriteSignedVoluntaryExitJSON")
|
||||
require.NoError(t, writeSignedVoluntaryExitJSON(context.Background(), sve, output))
|
||||
require.NoError(t, writeSignedVoluntaryExitJSON(sve, output))
|
||||
|
||||
b, err := file.ReadFileAsBytes(path.Join(output, "validator-exit-300.json"))
|
||||
require.NoError(t, err)
|
||||
|
@ -202,21 +202,16 @@ func FilterExitAccountsFromUserInput(
|
||||
return rawPubKeys, formattedPubKeys, nil
|
||||
}
|
||||
|
||||
promptHeader := au.Red("===============IMPORTANT===============")
|
||||
promptDescription := "Please navigate to the following website and make sure you understand the current implications " +
|
||||
"of a voluntary exit before making the final decision:"
|
||||
promptURL := au.Blue("https://docs.prylabs.network/docs/wallet/exiting-a-validator")
|
||||
promptQuestion := "If you still want to continue with the voluntary exit, please input a phrase found at the above URL"
|
||||
promptText := fmt.Sprintf("%s\n%s\n%s\n%s", promptHeader, promptDescription, promptURL, promptQuestion)
|
||||
resp, err := prompt.ValidatePrompt(r, promptText, func(input string) error {
|
||||
return prompt.ValidatePhrase(input, ExitPassphrase)
|
||||
})
|
||||
promptHeader := au.Red("===============CONFIRMATION NEEDED===============")
|
||||
promptQuestion := "continue with the voluntary exit? (y/n)"
|
||||
promptText := fmt.Sprintf("%s\n%s", promptHeader, promptQuestion)
|
||||
resp, err := prompt.ValidatePrompt(r, promptText, prompt.ValidateYesOrNo)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if strings.EqualFold(resp, "n") {
|
||||
log.Info("Voluntary exit aborted")
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
return rawPubKeys, formattedPubKeys, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user