cli: add tests for nep5 import/remove
Also unify `remove` and `import` arguments.
This commit is contained in:
parent
075f353062
commit
9817da7c4e
2 changed files with 61 additions and 6 deletions
|
@ -1,7 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -134,3 +137,59 @@ func TestNEP5MultiTransfer(t *testing.T) {
|
||||||
b, _ = e.Chain.GetGoverningTokenBalance(privs[2].GetScriptHash())
|
b, _ = e.Chain.GetGoverningTokenBalance(privs[2].GetScriptHash())
|
||||||
require.Equal(t, big.NewInt(13), b)
|
require.Equal(t, big.NewInt(13), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNEP5ImportToken(t *testing.T) {
|
||||||
|
e := newExecutor(t, true)
|
||||||
|
defer e.Close(t)
|
||||||
|
|
||||||
|
tmpDir := os.TempDir()
|
||||||
|
walletPath := path.Join(tmpDir, "walletForImport.json")
|
||||||
|
defer os.Remove(walletPath)
|
||||||
|
|
||||||
|
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
|
||||||
|
e.Run(t, "neo-go", "wallet", "nep5", "import",
|
||||||
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
||||||
|
"--wallet", walletPath,
|
||||||
|
"--token", client.GasContractHash.StringLE())
|
||||||
|
e.Run(t, "neo-go", "wallet", "nep5", "import",
|
||||||
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
||||||
|
"--wallet", walletPath,
|
||||||
|
"--token", client.NeoContractHash.StringLE())
|
||||||
|
|
||||||
|
t.Run("Info", func(t *testing.T) {
|
||||||
|
checkGASInfo := func(t *testing.T) {
|
||||||
|
e.checkNextLine(t, "^Name:\\s*GAS")
|
||||||
|
e.checkNextLine(t, "^Symbol:\\s*gas")
|
||||||
|
e.checkNextLine(t, "^Hash:\\s*"+client.GasContractHash.StringLE())
|
||||||
|
e.checkNextLine(t, "^Decimals:\\s*8")
|
||||||
|
e.checkNextLine(t, "^Address:\\s*"+address.Uint160ToString(client.GasContractHash))
|
||||||
|
}
|
||||||
|
t.Run("WithToken", func(t *testing.T) {
|
||||||
|
e.Run(t, "neo-go", "wallet", "nep5", "info",
|
||||||
|
"--wallet", walletPath, "--token", client.GasContractHash.StringLE())
|
||||||
|
checkGASInfo(t)
|
||||||
|
})
|
||||||
|
t.Run("NoToken", func(t *testing.T) {
|
||||||
|
e.Run(t, "neo-go", "wallet", "nep5", "info",
|
||||||
|
"--wallet", walletPath)
|
||||||
|
checkGASInfo(t)
|
||||||
|
_, err := e.Out.ReadString('\n')
|
||||||
|
require.NoError(t, err)
|
||||||
|
e.checkNextLine(t, "^Name:\\s*NEO")
|
||||||
|
e.checkNextLine(t, "^Symbol:\\s*neo")
|
||||||
|
e.checkNextLine(t, "^Hash:\\s*"+client.NeoContractHash.StringLE())
|
||||||
|
e.checkNextLine(t, "^Decimals:\\s*0")
|
||||||
|
e.checkNextLine(t, "^Address:\\s*"+address.Uint160ToString(client.NeoContractHash))
|
||||||
|
})
|
||||||
|
t.Run("Remove", func(t *testing.T) {
|
||||||
|
e.In.WriteString("y\r")
|
||||||
|
e.Run(t, "neo-go", "wallet", "nep5", "remove",
|
||||||
|
"--wallet", walletPath, "--token", client.NeoContractHash.StringLE())
|
||||||
|
e.Run(t, "neo-go", "wallet", "nep5", "info",
|
||||||
|
"--wallet", walletPath)
|
||||||
|
checkGASInfo(t)
|
||||||
|
_, err := e.Out.ReadString('\n')
|
||||||
|
require.Equal(t, err, io.EOF)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ func newNEP5Commands() []cli.Command {
|
||||||
{
|
{
|
||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove NEP5 token from the wallet",
|
Usage: "remove NEP5 token from the wallet",
|
||||||
UsageText: "remove --wallet <path> <hash-or-name>",
|
UsageText: "remove --wallet <path> --token <hash-or-name>",
|
||||||
Action: removeNEP5Token,
|
Action: removeNEP5Token,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
walletPathFlag,
|
walletPathFlag,
|
||||||
|
@ -314,11 +314,7 @@ func removeNEP5Token(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
defer wall.Close()
|
defer wall.Close()
|
||||||
|
|
||||||
name := ctx.Args().First()
|
token, err := getMatchingToken(ctx, wall, ctx.String("token"))
|
||||||
if name == "" {
|
|
||||||
return cli.NewExitError("token must be specified", 1)
|
|
||||||
}
|
|
||||||
token, err := getMatchingToken(ctx, wall, name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue