From 8503a9f54ead778fec4938cdd4ee2e494f5aacad Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Thu, 21 Dec 2023 15:33:30 +0300 Subject: [PATCH] cli: add Required flag for CLI parameters Required field is added for CLI commands. MarkRequired function change required parameter. Closes #2861 Signed-off-by: Ekaterina Pavlova --- cli/flags/util.go | 31 ++++++++++- cli/nep_test/nep11_test.go | 40 +++++++------- cli/nep_test/nep17_test.go | 2 +- cli/query/query.go | 11 ++-- cli/server/server.go | 10 ++-- cli/smartcontract/contract_test.go | 83 ++++++++++++++++++++--------- cli/smartcontract/smart_contract.go | 82 +++++++++++++++------------- cli/util/convert.go | 2 +- cli/wallet/candidate_test.go | 4 +- cli/wallet/multisig_test.go | 4 +- cli/wallet/nep11.go | 28 +++++----- cli/wallet/nep17.go | 12 ++--- cli/wallet/validator.go | 12 ++--- cli/wallet/wallet.go | 26 +++++---- cli/wallet/wallet_test.go | 33 ++++++------ 15 files changed, 226 insertions(+), 154 deletions(-) diff --git a/cli/flags/util.go b/cli/flags/util.go index 6b215b5e2..b556f587f 100644 --- a/cli/flags/util.go +++ b/cli/flags/util.go @@ -1,6 +1,10 @@ package flags -import "strings" +import ( + "strings" + + "github.com/urfave/cli" +) func eachName(longName string, fn func(string)) { parts := strings.Split(longName, ",") @@ -9,3 +13,28 @@ func eachName(longName string, fn func(string)) { fn(name) } } + +// MarkRequired marks flags with specified names as required. +func MarkRequired(flagSet []cli.Flag, names ...string) []cli.Flag { + updatedflagSet := make([]cli.Flag, 0, len(flagSet)) + for _, flag := range flagSet { + for _, n := range names { + if n == flag.GetName() { + switch f := (flag).(type) { + case cli.StringFlag: + f.Required = true + flag = f + case cli.IntFlag: + f.Required = true + flag = f + case cli.BoolFlag: + f.Required = true + flag = f + } + break + } + } + updatedflagSet = append(updatedflagSet, flag) + } + return updatedflagSet +} diff --git a/cli/nep_test/nep11_test.go b/cli/nep_test/nep11_test.go index 334a27dd7..1011cc57f 100644 --- a/cli/nep_test/nep11_test.go +++ b/cli/nep_test/nep11_test.go @@ -228,12 +228,10 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) { // ownerOf: missing contract hash cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOf", "--rpc-endpoint", "http://" + e.RPC.Addresses()[0], - } - e.RunWithError(t, cmdOwnerOf...) - cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE()) + "--token", h.StringLE()} - // ownerOf: missing token ID - e.RunWithError(t, cmdOwnerOf...) + // ownerOf: bad token ID + e.RunWithError(t, append(cmdOwnerOf, "--id", "test")...) cmdOwnerOf = append(cmdOwnerOf, "--id", hex.EncodeToString(tokenID)) // ownerOf: good @@ -259,12 +257,10 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) { cmdProperties := []string{ "neo-go", "wallet", "nep11", "properties", "--rpc-endpoint", "http://" + e.RPC.Addresses()[0], - } - e.RunWithError(t, cmdProperties...) - cmdProperties = append(cmdProperties, "--token", h.StringLE()) + "--token", h.StringLE()} - // properties: no token ID - e.RunWithError(t, cmdProperties...) + // properties: bad token ID + e.RunWithError(t, append(cmdProperties, "--id", "test")...) cmdProperties = append(cmdProperties, "--id", hex.EncodeToString(tokenID)) // properties: ok @@ -312,12 +308,12 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) { // transfer: unimported token with symbol id specified e.In.WriteString(nftOwnerPass + "\r") e.RunWithError(t, append(cmdTransfer, - "--token", "HASHY")...) + "--token", "HASHY", "--id", "test")...) cmdTransfer = append(cmdTransfer, "--token", h.StringLE()) - // transfer: no id specified + // transfer: bad id e.In.WriteString(nftOwnerPass + "\r") - e.RunWithError(t, cmdTransfer...) + e.RunWithError(t, append(cmdTransfer, "--id", "test")...) // transfer: good e.In.WriteString(nftOwnerPass + "\r") @@ -506,10 +502,10 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) { cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOfD", "--rpc-endpoint", "http://" + e.RPC.Addresses()[0], } - e.RunWithError(t, cmdOwnerOf...) - cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE()) + e.RunWithError(t, append(cmdOwnerOf, "--id", "")...) + cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE(), "--id", "") - // ownerOfD: missing token ID + // ownerOfD: bad token ID e.RunWithError(t, cmdOwnerOf...) cmdOwnerOf = append(cmdOwnerOf, "--id", hex.EncodeToString(token1ID)) @@ -539,11 +535,11 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) { "neo-go", "wallet", "nep11", "properties", "--rpc-endpoint", "http://" + e.RPC.Addresses()[0], } - e.RunWithError(t, cmdProperties...) + e.RunWithError(t, append(cmdProperties, "--id", "")...) cmdProperties = append(cmdProperties, "--token", h.StringLE()) - // properties: no token ID - e.RunWithError(t, cmdProperties...) + // properties: bad token ID + e.RunWithError(t, append(cmdProperties, "--id", "")...) cmdProperties = append(cmdProperties, "--id", hex.EncodeToString(token2ID)) // properties: additional parameter @@ -596,12 +592,12 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) { // transfer: unimported token with symbol id specified e.In.WriteString(testcli.ValidatorPass + "\r") e.RunWithError(t, append(cmdTransfer, - "--token", "NFSO")...) + "--token", "NFSO", "--id", "")...) cmdTransfer = append(cmdTransfer, "--token", h.StringLE()) - // transfer: no id specified + // transfer: bad id specified e.In.WriteString(testcli.ValidatorPass + "\r") - e.RunWithError(t, cmdTransfer...) + e.RunWithError(t, append(cmdTransfer, "--id", "")...) // transfer: good e.In.WriteString(testcli.ValidatorPass + "\r") diff --git a/cli/nep_test/nep17_test.go b/cli/nep_test/nep17_test.go index 5964added..a6b092859 100644 --- a/cli/nep_test/nep17_test.go +++ b/cli/nep_test/nep17_test.go @@ -111,7 +111,7 @@ func TestNEP17Balance(t *testing.T) { e.CheckEOF(t) }) t.Run("Bad wallet", func(t *testing.T) { - e.RunWithError(t, append(cmdbalance, "--wallet", "/dev/null")...) + e.RunWithError(t, append(cmdbalance, "--wallet", "/dev/null", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])...) }) } diff --git a/cli/query/query.go b/cli/query/query.go index 4b909b088..8e83be48f 100644 --- a/cli/query/query.go +++ b/cli/query/query.go @@ -43,35 +43,36 @@ func NewCommands() []cli.Command { Usage: "Get candidates and votes", UsageText: "neo-go query candidates -r endpoint [-s timeout]", Action: queryCandidates, - Flags: options.RPC, + Flags: flags.MarkRequired(options.RPC, + options.RPCEndpointFlag+", r"), }, { Name: "committee", Usage: "Get committee list", UsageText: "neo-go query committee -r endpoint [-s timeout]", Action: queryCommittee, - Flags: options.RPC, + Flags: flags.MarkRequired(options.RPC, options.RPCEndpointFlag+", r"), }, { Name: "height", Usage: "Get node height", UsageText: "neo-go query height -r endpoint [-s timeout]", Action: queryHeight, - Flags: options.RPC, + Flags: flags.MarkRequired(options.RPC, options.RPCEndpointFlag+", r"), }, { Name: "tx", Usage: "Query transaction status", UsageText: "neo-go query tx -r endpoint [-s timeout] [-v]", Action: queryTx, - Flags: queryTxFlags, + Flags: flags.MarkRequired(queryTxFlags, options.RPCEndpointFlag+", r"), }, { Name: "voter", Usage: "Print NEO holder account state", UsageText: "neo-go query voter
-r endpoint [-s timeout]", Action: queryVoter, - Flags: options.RPC, + Flags: flags.MarkRequired(options.RPC, options.RPCEndpointFlag+", r"), }, }, }} diff --git a/cli/server/server.go b/cli/server/server.go index f2670d599..fadecbd5c 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -54,16 +54,18 @@ func NewCommands() []cli.Command { Usage: "block number to start from (default: 0)", }, cli.StringFlag{ - Name: "out, o", - Usage: "Output file (stdout if not given)", + Name: "out, o", + Required: true, + Usage: "Output file (stdout if not given)", }, ) var cfgCountInFlags = make([]cli.Flag, len(cfgWithCountFlags)) copy(cfgCountInFlags, cfgWithCountFlags) cfgCountInFlags = append(cfgCountInFlags, cli.StringFlag{ - Name: "in, i", - Usage: "Input file (stdin if not given)", + Name: "in, i", + Required: true, + Usage: "Input file (stdin if not given)", }, cli.StringFlag{ Name: "dump", diff --git a/cli/smartcontract/contract_test.go b/cli/smartcontract/contract_test.go index 8072d505b..a07badcea 100644 --- a/cli/smartcontract/contract_test.go +++ b/cli/smartcontract/contract_test.go @@ -30,6 +30,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/stretchr/testify/require" + "github.com/urfave/cli" "gopkg.in/yaml.v3" ) @@ -58,10 +59,10 @@ func TestCalcHash(t *testing.T) { e.RunWithError(t, append(cmd, "--in", nefPath, "--manifest", manifestPath)...) }) t.Run("no nef file", func(t *testing.T) { - e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--manifest", manifestPath)...) + e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--manifest", manifestPath, "--in", "")...) }) t.Run("no manifest file", func(t *testing.T) { - e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", nefPath)...) + e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", nefPath, "--manifest", "")...) }) t.Run("invalid nef path", func(t *testing.T) { e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), @@ -220,9 +221,6 @@ func TestContractInitAndCompile(t *testing.T) { tmpDir := t.TempDir() e := testcli.NewExecutor(t, false) - t.Run("no path is provided", func(t *testing.T) { - e.RunWithError(t, "neo-go", "contract", "init") - }) t.Run("invalid path", func(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "init", "--name", "\x00") }) @@ -244,9 +242,6 @@ func TestContractInitAndCompile(t *testing.T) { nefPath := filepath.Join(tmpDir, "testcontract.nef") manifestPath := filepath.Join(tmpDir, "testcontract.manifest.json") cmd := []string{"neo-go", "contract", "compile"} - t.Run("missing source", func(t *testing.T) { - e.RunWithError(t, cmd...) - }) cmd = append(cmd, "--in", srcPath, "--out", nefPath, "--manifest", manifestPath) t.Run("missing config, but require manifest", func(t *testing.T) { @@ -447,7 +442,7 @@ func TestDeployWithSigners(t *testing.T) { }) t.Run("missing RPC", func(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "deploy", - "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, + "--wallet", testcli.ValidatorWallet, "-r", "", "--address", testcli.ValidatorAddr, "--in", nefName, "--manifest", manifestName, "[", "str1", "str2", "]") }) @@ -477,28 +472,28 @@ func TestContractManifestGroups(t *testing.T) { "--out", nefName, "--manifest", manifestName) t.Run("missing wallet", func(t *testing.T) { - e.RunWithError(t, "neo-go", "contract", "manifest", "add-group") + e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", "-s", "test", "--nef", "test", "--manifest", "test") }) t.Run("invalid wallet", func(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", - "--wallet", t.TempDir()) + "--wallet", t.TempDir(), "-s", "test", "--nef", "test", "--manifest", "test") }) t.Run("invalid sender", func(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", "--wallet", testcli.TestWalletPath, "--address", testcli.TestWalletAccount, - "--sender", "not-a-sender") + "--sender", "not-a-sender", "--nef", "test", "--manifest", "test") }) t.Run("invalid NEF file", func(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", "--wallet", testcli.TestWalletPath, "--address", testcli.TestWalletAccount, - "--sender", testcli.TestWalletAccount, "--nef", tmpDir) + "--sender", testcli.TestWalletAccount, "--nef", tmpDir, "--manifest", "test") }) t.Run("corrupted NEF file", func(t *testing.T) { f := filepath.Join(tmpDir, "invalid.nef") require.NoError(t, os.WriteFile(f, []byte{1, 2, 3}, os.ModePerm)) e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", "--wallet", testcli.TestWalletPath, "--address", testcli.TestWalletAccount, - "--sender", testcli.TestWalletAccount, "--nef", f) + "--sender", testcli.TestWalletAccount, "--nef", f, "--manifest", "test") }) t.Run("invalid manifest file", func(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "manifest", "add-group", @@ -558,10 +553,6 @@ func TestContract_TestInvokeScript(t *testing.T) { "--config", "testdata/deploy/neo-go.yml", "--out", goodNef, "--manifest", manifestName) - t.Run("missing in", func(t *testing.T) { - e.RunWithError(t, "neo-go", "contract", "testinvokescript", - "--rpc-endpoint", "http://"+e.RPC.Addresses()[0]) - }) t.Run("unexisting in", func(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "testinvokescript", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], @@ -683,10 +674,6 @@ func TestComlileAndInvokeFunction(t *testing.T) { t.Run("invalid cosigner", func(t *testing.T) { e.RunWithError(t, append(cmd, "--", "notahash")...) }) - t.Run("missing RPC address", func(t *testing.T) { - e.RunWithError(t, "neo-go", "contract", "testinvokefunction", - h.StringLE(), "getValue") - }) e.Run(t, cmd...) @@ -960,9 +947,6 @@ func TestContractInspect(t *testing.T) { "--out", nefName, "--manifest", manifestName) cmd := []string{"neo-go", "contract", "inspect"} - t.Run("missing input", func(t *testing.T) { - e.RunWithError(t, cmd...) - }) t.Run("with raw '.go'", func(t *testing.T) { e.RunWithError(t, append(cmd, "--in", srcPath)...) e.Run(t, append(cmd, "--in", srcPath, "--compile")...) @@ -1095,3 +1079,52 @@ func TestContractCompile_NEFSizeCheck(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "compile", "--in", in) require.NoFileExists(t, filepath.Join(tmpDir, "main.nef")) } + +func TestSmartcontractCommands(t *testing.T) { + tmpDir := t.TempDir() + app := cli.NewApp() + app.Commands = smartcontract.NewCommands() + app.ExitErrHandler = func(*cli.Context, error) {} + + manifestF := filepath.Join(tmpDir, "manifest.json") + bindingF := filepath.Join(tmpDir, "binding.yml") + nefF := filepath.Join(tmpDir, "out.nef") + + checkError := func(t *testing.T, msg string, args ...string) { + // cli.ExitError doesn't implement wraping properly, so we check for an error message. + err := app.Run(append([]string{"", "contract"}, args...)) + require.True(t, strings.Contains(err.Error(), msg), "got: %v", err) + } + cmd := []string{"compile", + "--manifest", manifestF, + "--bindings", bindingF, + "--out", nefF, + } + t.Run("contract compile missing in", func(t *testing.T) { + checkError(t, "Required flag \"in\" not set", cmd...) + }) + cmd = []string{"deploy", + "-r", "test", + "-w", "test", + } + t.Run("contract deploy missing in, manifest", func(t *testing.T) { + checkError(t, "Required flags \"in, manifest\" not set", cmd...) + }) + cmd = []string{"testinvokescript", + "-r", "test"} + t.Run("contract testinvokescript missing in", func(t *testing.T) { + checkError(t, "Required flag \"in\" not set", cmd...) + }) + + t.Run("contract init missing name", func(t *testing.T) { + checkError(t, "Required flag \"name\" not set", "init", "--skip") + }) + + t.Run("contract inspect missing in, manifest", func(t *testing.T) { + checkError(t, "Required flags \"in, manifest\" not set", "calc-hash", "--s", random.Uint160().StringLE()) + }) + + t.Run("contract manifest add-group missing in, manifest", func(t *testing.T) { + checkError(t, "Required flags \"sender, nef, manifest\" not set", "manifest", "add-group", "-w", random.Uint160().StringLE()) + }) +} diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index ec3fe68fc..1f512407e 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -75,51 +75,56 @@ func RuntimeNotify(args []any) { // NewCommands returns 'contract' command. func NewCommands() []cli.Command { - testInvokeScriptFlags := []cli.Flag{ + testInvokeScriptFlags := append([]cli.Flag{ cli.StringFlag{ - Name: "in, i", - Usage: "Input location of the .nef file that needs to be invoked", + Name: "in, i", + Required: true, + Usage: "Input location of the .nef file that needs to be invoked", }, options.Historic, - } - testInvokeScriptFlags = append(testInvokeScriptFlags, options.RPC...) - testInvokeFunctionFlags := []cli.Flag{options.Historic} - testInvokeFunctionFlags = append(testInvokeFunctionFlags, options.RPC...) - invokeFunctionFlags := []cli.Flag{ + }, options.RPC...) + testInvokeFunctionFlags := append([]cli.Flag{options.Historic}, options.RPC...) + invokeFunctionFlags := append([]cli.Flag{ addressFlag, txctx.GasFlag, txctx.SysGasFlag, txctx.OutFlag, txctx.ForceFlag, - } - invokeFunctionFlags = append(invokeFunctionFlags, options.Wallet...) + }, options.Wallet...) invokeFunctionFlags = append(invokeFunctionFlags, options.RPC...) + deployFlags := append(invokeFunctionFlags, []cli.Flag{ cli.StringFlag{ - Name: "in, i", - Usage: "Input file for the smart contract (*.nef)", + Name: "in, i", + Required: true, + Usage: "Input file for the smart contract (*.nef)", }, cli.StringFlag{ - Name: "manifest, m", - Usage: "Manifest input file (*.manifest.json)", + Name: "manifest, m", + Required: true, + Usage: "Manifest input file (*.manifest.json)", }, }...) + manifestAddGroupFlags := append([]cli.Flag{ cli.StringFlag{ - Name: "sender, s", - Usage: "deploy transaction sender", + Name: "sender, s", + Required: true, + Usage: "deploy transaction sender", }, flags.AddressFlag{ Name: addressFlagName, // use the same name for handler code unification. Usage: "account to sign group with", }, cli.StringFlag{ - Name: "nef, n", - Usage: "path to the NEF file", + Name: "nef, n", + Required: true, + Usage: "path to the NEF file", }, cli.StringFlag{ - Name: "manifest, m", - Usage: "path to the manifest", + Name: "manifest, m", + Required: true, + Usage: "path to the manifest", }, }, options.Wallet...) return []cli.Command{{ @@ -140,8 +145,9 @@ func NewCommands() []cli.Command { Action: contractCompile, Flags: []cli.Flag{ cli.StringFlag{ - Name: "in, i", - Usage: "Input file for the smart contract to be compiled (*.go file or directory)", + Name: "in, i", + Required: true, + Usage: "Input file for the smart contract to be compiled (*.go file or directory)", }, cli.StringFlag{ Name: "out, o", @@ -188,20 +194,20 @@ func NewCommands() []cli.Command { { Name: "deploy", Usage: "deploy a smart contract (.nef with description)", - UsageText: "neo-go contract deploy -r endpoint -w wallet [-a address] [-g gas] [-e sysgas] --in contract.nef --manifest contract.manifest.json [--out file] [--force] [data]", + UsageText: "neo-go contract deploy -r endpoint -w wallet [--wallet-config path] [-a address] [-g gas] [-e sysgas] --in contract.nef --manifest contract.manifest.json [--out file] [--force] [data]", Description: `Deploys given contract into the chain. The gas parameter is for additional gas to be added as a network fee to prioritize the transaction. The data parameter is an optional parameter to be passed to '_deploy' method. `, Action: contractDeploy, - Flags: deployFlags, + Flags: flags.MarkRequired(deployFlags, options.RPCEndpointFlag+", r"), }, generateWrapperCmd, generateRPCWrapperCmd, { Name: "invokefunction", Usage: "invoke deployed contract on the blockchain", - UsageText: "neo-go contract invokefunction -r endpoint -w wallet [-a address] [-g gas] [-e sysgas] [--out file] [--force] scripthash [method] [arguments...] [--] [signers...]", + UsageText: "neo-go contract invokefunction -r endpoint -w wallet [--wallet-config path] [-a address] [-g gas] [-e sysgas] [--out file] [--force] scripthash [method] [arguments...] [--] [signers...]", Description: `Executes given (as a script hash) deployed script with the given method, arguments and signers. Sender is included in the list of signers by default with None witness scope. If you'd like to change default sender's scope, @@ -210,7 +216,7 @@ func NewCommands() []cli.Command { command sends an invocation transaction to the network. `, Action: invokeFunction, - Flags: invokeFunctionFlags, + Flags: flags.MarkRequired(invokeFunctionFlags, options.RPCEndpointFlag+", r"), }, { Name: "testinvokefunction", @@ -230,7 +236,7 @@ func NewCommands() []cli.Command { ` + cmdargs.SignersParsingDoc + ` `, Action: testInvokeFunction, - Flags: testInvokeFunctionFlags, + Flags: flags.MarkRequired(testInvokeFunctionFlags, options.RPCEndpointFlag+", r"), }, { Name: "testinvokescript", @@ -241,7 +247,7 @@ func NewCommands() []cli.Command { for the details about parameters. `, Action: testInvokeScript, - Flags: testInvokeScriptFlags, + Flags: flags.MarkRequired(testInvokeScriptFlags, options.RPCEndpointFlag+", r"), }, { Name: "init", @@ -250,8 +256,9 @@ func NewCommands() []cli.Command { Action: initSmartContract, Flags: []cli.Flag{ cli.StringFlag{ - Name: "name, n", - Usage: "name of the smart-contract to be initialized", + Name: "name, n", + Required: true, + Usage: "name of the smart-contract to be initialized", }, cli.BoolFlag{ Name: "skip-details, skip", @@ -270,8 +277,9 @@ func NewCommands() []cli.Command { Usage: "compile input file (it should be go code then)", }, cli.StringFlag{ - Name: "in, i", - Usage: "input file of the program (either .go or .nef)", + Name: "in, i", + Required: true, + Usage: "input file of the program (either .go or .nef)", }, }, }, @@ -286,12 +294,14 @@ func NewCommands() []cli.Command { Usage: "sender script hash or address", }, cli.StringFlag{ - Name: "in", - Usage: "path to NEF file", + Name: "in", + Required: true, + Usage: "path to NEF file", }, cli.StringFlag{ - Name: "manifest, m", - Usage: "path to manifest file", + Name: "manifest, m", + Required: true, + Usage: "path to manifest file", }, }, }, diff --git a/cli/util/convert.go b/cli/util/convert.go index 002711b52..803cbab0e 100644 --- a/cli/util/convert.go +++ b/cli/util/convert.go @@ -67,7 +67,7 @@ flag is included, the specified value is added to the resulting conflicting tran in both scenarios. `, Action: cancelTx, - Flags: txCancelFlags, + Flags: flags.MarkRequired(txCancelFlags, options.RPCEndpointFlag+", r"), }, { Name: "txdump", diff --git a/cli/wallet/candidate_test.go b/cli/wallet/candidate_test.go index 446b9a82f..7e422d227 100644 --- a/cli/wallet/candidate_test.go +++ b/cli/wallet/candidate_test.go @@ -153,8 +153,8 @@ func TestRegisterCandidate(t *testing.T) { vs, err = e.Chain.GetEnrollments() require.Equal(t, 0, len(vs)) - // query voter: missing address - e.RunWithError(t, "neo-go", "query", "voter") + // query voter: bad address + e.RunWithError(t, "neo-go", "query", "voter", "-r", "") // Excessive parameters. e.RunWithError(t, "neo-go", "query", "voter", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], validatorAddress, validatorAddress) e.RunWithError(t, "neo-go", "query", "committee", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], "something") diff --git a/cli/wallet/multisig_test.go b/cli/wallet/multisig_test.go index 5972c3659..283a43c80 100644 --- a/cli/wallet/multisig_test.go +++ b/cli/wallet/multisig_test.go @@ -80,11 +80,11 @@ func TestSignMultisigTx(t *testing.T) { "--out", txPath) // missing wallet - e.RunWithError(t, "neo-go", "wallet", "sign") + e.RunWithError(t, "neo-go", "wallet", "sign", "--in", "") // missing in e.RunWithError(t, "neo-go", "wallet", "sign", - "--wallet", wallet2Path) + "--wallet", wallet2Path, "--in", "") // missing address e.RunWithError(t, "neo-go", "wallet", "sign", diff --git a/cli/wallet/nep11.go b/cli/wallet/nep11.go index 8c5b9caf6..e52678720 100644 --- a/cli/wallet/nep11.go +++ b/cli/wallet/nep11.go @@ -66,14 +66,14 @@ func newNEP11Commands() []cli.Command { account (if they use the same names/symbols). `, Action: getNEP11Balance, - Flags: balanceFlags, + Flags: flags.MarkRequired(balanceFlags, options.RPCEndpointFlag+", r"), }, { Name: "import", Usage: "import NEP-11 token to a wallet", - UsageText: "import -w wallet [--wallet-config path] --rpc-endpoint --timeout