forked from TrueCloudLab/neoneo-go
cli: use default adress in transfer
This commit is contained in:
parent
ee10ea19e7
commit
d4723d8e81
3 changed files with 48 additions and 4 deletions
|
@ -111,10 +111,10 @@ func TestNEP17Transfer(t *testing.T) {
|
||||||
"neo-go", "wallet", "nep17", "transfer",
|
"neo-go", "wallet", "nep17", "transfer",
|
||||||
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
||||||
"--wallet", validatorWallet,
|
"--wallet", validatorWallet,
|
||||||
"--from", validatorAddr,
|
|
||||||
"--to", w.Accounts[0].Address,
|
"--to", w.Accounts[0].Address,
|
||||||
"--token", "NEO",
|
"--token", "NEO",
|
||||||
"--amount", "1",
|
"--amount", "1",
|
||||||
|
"--from", validatorAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("InvalidPassword", func(t *testing.T) {
|
t.Run("InvalidPassword", func(t *testing.T) {
|
||||||
|
@ -131,6 +131,33 @@ func TestNEP17Transfer(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
b, _ := e.Chain.GetGoverningTokenBalance(sh)
|
b, _ := e.Chain.GetGoverningTokenBalance(sh)
|
||||||
require.Equal(t, big.NewInt(1), b)
|
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) {
|
func TestNEP17MultiTransfer(t *testing.T) {
|
||||||
|
|
2
cli/testdata/wallet1_solo.json
vendored
2
cli/testdata/wallet1_solo.json
vendored
|
@ -16,7 +16,7 @@
|
||||||
"deployed": false
|
"deployed": false
|
||||||
},
|
},
|
||||||
"lock": false,
|
"lock": false,
|
||||||
"isdefault": false
|
"isdefault": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY",
|
"address": "NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY",
|
||||||
|
|
|
@ -359,7 +359,10 @@ func multiTransferNEP17(ctx *cli.Context) error {
|
||||||
defer wall.Close()
|
defer wall.Close()
|
||||||
|
|
||||||
fromFlag := ctx.Generic("from").(*flags.Address)
|
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)
|
acc, err := getDecryptedAccount(ctx, wall, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
|
@ -422,7 +425,10 @@ func transferNEP17(ctx *cli.Context) error {
|
||||||
defer wall.Close()
|
defer wall.Close()
|
||||||
|
|
||||||
fromFlag := ctx.Generic("from").(*flags.Address)
|
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)
|
acc, err := getDecryptedAccount(ctx, wall, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
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())
|
fmt.Fprintln(ctx.App.Writer, tx.Hash().StringLE())
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue