From 8cfb72d5e92b1b039631be6e6dd96c7b00a62e56 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 26 Apr 2021 15:56:19 +0300 Subject: [PATCH] cli: allow to omit `data` parameter for NEP17 transfers There's a case when cosigners are specified and data is not. --- cli/cmdargs/parser.go | 10 ++++++---- cli/nep17_test.go | 14 +++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cli/cmdargs/parser.go b/cli/cmdargs/parser.go index 252ca4cfc..a34a70397 100644 --- a/cli/cmdargs/parser.go +++ b/cli/cmdargs/parser.go @@ -76,12 +76,14 @@ func GetDataFromContext(ctx *cli.Context) (int, interface{}, *cli.ExitError) { if err != nil { return offset, nil, cli.NewExitError(fmt.Errorf("unable to parse 'data' parameter: %w", err), 1) } - if len(params) != 1 { + if len(params) > 1 { return offset, nil, cli.NewExitError("'data' should be represented as a single parameter", 1) } - data, err = smartcontract.ExpandParameterToEmitable(params[0]) - if err != nil { - return offset, nil, cli.NewExitError(fmt.Sprintf("failed to convert 'data' to emitable type: %s", err.Error()), 1) + if len(params) != 0 { + data, err = smartcontract.ExpandParameterToEmitable(params[0]) + if err != nil { + return offset, nil, cli.NewExitError(fmt.Sprintf("failed to convert 'data' to emitable type: %s", err.Error()), 1) + } } } return offset, data, nil diff --git a/cli/nep17_test.go b/cli/nep17_test.go index 659343a8d..07a496a97 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -134,9 +134,9 @@ func TestNEP17Transfer(t *testing.T) { require.Equal(t, big.NewInt(1), b) hVerify := deployVerifyContract(t, e) + const validatorDefault = "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo" t.Run("default address", func(t *testing.T) { - const validatorDefault = "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo" e.In.WriteString("one\r") e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", "--rpc-endpoint", "http://"+e.RPC.Addr, @@ -162,6 +162,18 @@ func TestNEP17Transfer(t *testing.T) { require.Equal(t, big.NewInt(41), b) }) + t.Run("with signers", func(t *testing.T) { + e.In.WriteString("one\r") + e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", + "--rpc-endpoint", "http://"+e.RPC.Addr, + "--wallet", validatorWallet, + "--from", validatorAddr, + "NEO:"+validatorDefault+":42", + "GAS:"+validatorDefault+":7", + "--", validatorAddr+":Global") + e.checkTxPersisted(t) + }) + validTil := e.Chain.BlockHeight() + 100 cmd := []string{ "neo-go", "wallet", "nep17", "transfer",