From 90b054afd0c457ea553a6a869f8a7e450c246c7a Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 16 Apr 2021 12:03:03 +0300 Subject: [PATCH] cli: check address flag is set for validator-related commands --- cli/candidate_test.go | 10 ++++++++++ cli/wallet/validator.go | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/cli/candidate_test.go b/cli/candidate_test.go index ff16ba0ba..f247bf9d0 100644 --- a/cli/candidate_test.go +++ b/cli/candidate_test.go @@ -23,6 +23,11 @@ func TestRegisterCandidate(t *testing.T) { "GAS:"+validatorPriv.Address()+":10000") e.checkTxPersisted(t) + // missing address + e.RunWithError(t, "neo-go", "wallet", "candidate", "register", + "--rpc-endpoint", "http://"+e.RPC.Addr, + "--wallet", validatorWallet) + e.In.WriteString("one\r") e.Run(t, "neo-go", "wallet", "candidate", "register", "--rpc-endpoint", "http://"+e.RPC.Addr, @@ -52,6 +57,11 @@ func TestRegisterCandidate(t *testing.T) { require.Equal(t, b, vs[0].Votes) }) + // missing address + e.RunWithError(t, "neo-go", "wallet", "candidate", "unregister", + "--rpc-endpoint", "http://"+e.RPC.Addr, + "--wallet", validatorWallet) + e.In.WriteString("one\r") e.Run(t, "neo-go", "wallet", "candidate", "unregister", "--rpc-endpoint", "http://"+e.RPC.Addr, diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index 0b6e3a28b..eaf3d492e 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -87,6 +87,9 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error { defer wall.Close() addrFlag := ctx.Generic("address").(*flags.Address) + if !addrFlag.IsSet { + return cli.NewExitError("address was not provided", 1) + } addr := addrFlag.Uint160() acc, err := getDecryptedAccount(ctx, wall, addr) if err != nil { @@ -139,6 +142,9 @@ func handleVote(ctx *cli.Context) error { defer wall.Close() addrFlag := ctx.Generic("address").(*flags.Address) + if !addrFlag.IsSet { + return cli.NewExitError("address was not provided", 1) + } addr := addrFlag.Uint160() acc, err := getDecryptedAccount(ctx, wall, addr) if err != nil {