cli: allow to omit data parameter for NEP17 transfers

There's a case when cosigners are specified and data is not.
This commit is contained in:
Anna Shaleva 2021-04-26 15:56:19 +03:00
parent 3eefda7f1a
commit 8cfb72d5e9
2 changed files with 19 additions and 5 deletions

View file

@ -76,12 +76,14 @@ func GetDataFromContext(ctx *cli.Context) (int, interface{}, *cli.ExitError) {
if err != nil { if err != nil {
return offset, nil, cli.NewExitError(fmt.Errorf("unable to parse 'data' parameter: %w", err), 1) 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) return offset, nil, cli.NewExitError("'data' should be represented as a single parameter", 1)
} }
data, err = smartcontract.ExpandParameterToEmitable(params[0]) if len(params) != 0 {
if err != nil { data, err = smartcontract.ExpandParameterToEmitable(params[0])
return offset, nil, cli.NewExitError(fmt.Sprintf("failed to convert 'data' to emitable type: %s", err.Error()), 1) 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 return offset, data, nil

View file

@ -134,9 +134,9 @@ func TestNEP17Transfer(t *testing.T) {
require.Equal(t, big.NewInt(1), b) require.Equal(t, big.NewInt(1), b)
hVerify := deployVerifyContract(t, e) hVerify := deployVerifyContract(t, e)
const validatorDefault = "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo"
t.Run("default address", func(t *testing.T) { t.Run("default address", func(t *testing.T) {
const validatorDefault = "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo"
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addr,
@ -162,6 +162,18 @@ func TestNEP17Transfer(t *testing.T) {
require.Equal(t, big.NewInt(41), b) 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 validTil := e.Chain.BlockHeight() + 100
cmd := []string{ cmd := []string{
"neo-go", "wallet", "nep17", "transfer", "neo-go", "wallet", "nep17", "transfer",