diff --git a/cli/nep17_test.go b/cli/nep17_test.go index 768ecb145..50d84baf2 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -111,10 +111,10 @@ func TestNEP17Transfer(t *testing.T) { "neo-go", "wallet", "nep17", "transfer", "--rpc-endpoint", "http://" + e.RPC.Addr, "--wallet", validatorWallet, - "--from", validatorAddr, "--to", w.Accounts[0].Address, "--token", "NEO", "--amount", "1", + "--from", validatorAddr, } t.Run("InvalidPassword", func(t *testing.T) { @@ -131,6 +131,33 @@ func TestNEP17Transfer(t *testing.T) { require.NoError(t, err) b, _ := e.Chain.GetGoverningTokenBalance(sh) require.Equal(t, big.NewInt(1), b) + + t.Run("default address", func(t *testing.T) { + const validatorDefault = "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc" + 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") + e.checkTxPersisted(t) + + args := args[:len(args)-2] // cut '--from' argument + e.In.WriteString("one\r") + e.Run(t, args...) + e.checkTxPersisted(t) + + sh, err := address.StringToUint160(w.Accounts[0].Address) + require.NoError(t, err) + b, _ := e.Chain.GetGoverningTokenBalance(sh) + require.Equal(t, big.NewInt(2), b) + + sh, err = address.StringToUint160(validatorDefault) + require.NoError(t, err) + b, _ = e.Chain.GetGoverningTokenBalance(sh) + require.Equal(t, big.NewInt(41), b) + }) } func TestNEP17MultiTransfer(t *testing.T) { diff --git a/cli/testdata/wallet1_solo.json b/cli/testdata/wallet1_solo.json index 1612925d6..db25b7d3e 100644 --- a/cli/testdata/wallet1_solo.json +++ b/cli/testdata/wallet1_solo.json @@ -16,7 +16,7 @@ "deployed": false }, "lock": false, - "isdefault": false + "isdefault": true }, { "address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY", diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index 9a9e0b65c..7378d6375 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -359,7 +359,10 @@ func multiTransferNEP17(ctx *cli.Context) error { defer wall.Close() fromFlag := ctx.Generic("from").(*flags.Address) - from := fromFlag.Uint160() + from, err := getDefaultAddress(fromFlag, wall) + if err != nil { + return cli.NewExitError(err, 1) + } acc, err := getDecryptedAccount(ctx, wall, from) if err != nil { return cli.NewExitError(err, 1) @@ -422,7 +425,10 @@ func transferNEP17(ctx *cli.Context) error { defer wall.Close() fromFlag := ctx.Generic("from").(*flags.Address) - from := fromFlag.Uint160() + from, err := getDefaultAddress(fromFlag, wall) + if err != nil { + return cli.NewExitError(err, 1) + } acc, err := getDecryptedAccount(ctx, wall, from) if err != nil { return cli.NewExitError(err, 1) @@ -484,3 +490,14 @@ func signAndSendTransfer(ctx *cli.Context, c *client.Client, acc *wallet.Account fmt.Fprintln(ctx.App.Writer, tx.Hash().StringLE()) return nil } + +func getDefaultAddress(fromFlag *flags.Address, w *wallet.Wallet) (util.Uint160, error) { + if fromFlag.IsSet { + return fromFlag.Uint160(), nil + } + addr := w.GetChangeAddress() + if addr.Equals(util.Uint160{}) { + return util.Uint160{}, errors.New("can't get default address") + } + return addr, nil +}