2022-10-05 15:06:06 +00:00
|
|
|
package nep_test
|
2020-08-29 11:41:33 +00:00
|
|
|
|
|
|
|
import (
|
2020-09-01 12:40:32 +00:00
|
|
|
"io"
|
2020-08-31 09:42:42 +00:00
|
|
|
"math/big"
|
2021-11-17 11:14:22 +00:00
|
|
|
"path/filepath"
|
2020-08-29 11:41:33 +00:00
|
|
|
"strconv"
|
2020-09-28 14:24:21 +00:00
|
|
|
"strings"
|
2020-08-29 11:41:33 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/testcli"
|
2020-12-13 18:25:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
2020-08-31 09:42:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
2020-12-01 08:40:58 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
2021-04-23 14:32:48 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
2020-08-31 09:42:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-08-29 11:41:33 +00:00
|
|
|
)
|
|
|
|
|
2020-11-24 08:14:25 +00:00
|
|
|
func TestNEP17Balance(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2020-11-24 08:14:25 +00:00
|
|
|
cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"}
|
2020-09-28 14:24:21 +00:00
|
|
|
cmdbase := append(cmdbalance,
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
2020-09-28 14:24:21 +00:00
|
|
|
)
|
2022-10-05 06:44:10 +00:00
|
|
|
cmd := append(cmdbase, "--address", testcli.ValidatorAddr)
|
2022-08-05 10:32:37 +00:00
|
|
|
t.Run("excessive parameters", func(t *testing.T) {
|
|
|
|
e.RunWithError(t, append(cmd, "--token", "NEO", "gas")...)
|
|
|
|
})
|
2020-08-29 11:41:33 +00:00
|
|
|
t.Run("NEO", func(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
b, index := e.Chain.GetGoverningTokenBalance(testcli.ValidatorHash)
|
2020-08-29 11:41:33 +00:00
|
|
|
checkResult := func(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.ValidatorAddr)
|
|
|
|
e.CheckNextLine(t, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
|
|
|
|
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
|
|
|
|
e.CheckEOF(t)
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
|
|
|
t.Run("Alias", func(t *testing.T) {
|
2020-12-13 18:05:49 +00:00
|
|
|
e.Run(t, append(cmd, "--token", "NEO")...)
|
2020-08-29 11:41:33 +00:00
|
|
|
checkResult(t)
|
|
|
|
})
|
|
|
|
t.Run("Hash", func(t *testing.T) {
|
|
|
|
e.Run(t, append(cmd, "--token", e.Chain.GoverningTokenHash().StringLE())...)
|
|
|
|
checkResult(t)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run("GAS", func(t *testing.T) {
|
2020-12-13 18:05:49 +00:00
|
|
|
e.Run(t, append(cmd, "--token", "GAS")...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.ValidatorAddr)
|
|
|
|
e.CheckNextLine(t, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
|
|
|
|
b := e.Chain.GetUtilityTokenBalance(testcli.ValidatorHash)
|
|
|
|
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(b.Int64()).String()+"$")
|
2020-08-29 11:41:33 +00:00
|
|
|
})
|
2021-12-27 13:29:35 +00:00
|
|
|
t.Run("zero balance of known token", func(t *testing.T) {
|
|
|
|
e.Run(t, append(cmdbase, []string{"--token", "NEO"}...)...)
|
|
|
|
addr1, err := address.StringToUint160("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn")
|
|
|
|
require.NoError(t, err)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr1))
|
|
|
|
e.CheckNextLine(t, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
|
|
|
|
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(0).String()+"$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Updated:")
|
|
|
|
e.CheckNextLine(t, "^\\s*$")
|
2021-12-27 13:29:35 +00:00
|
|
|
})
|
2020-09-28 14:24:21 +00:00
|
|
|
t.Run("all accounts", func(t *testing.T) {
|
|
|
|
e.Run(t, cmdbase...)
|
2021-05-11 13:32:09 +00:00
|
|
|
addr1, err := address.StringToUint160("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn")
|
2020-09-28 14:24:21 +00:00
|
|
|
require.NoError(t, err)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr1))
|
|
|
|
e.CheckNextLine(t, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
|
2020-09-28 14:24:21 +00:00
|
|
|
balance := e.Chain.GetUtilityTokenBalance(addr1)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Updated:")
|
|
|
|
e.CheckNextLine(t, "^\\s*$")
|
2020-09-28 14:24:21 +00:00
|
|
|
|
2021-05-11 14:13:33 +00:00
|
|
|
addr2, err := address.StringToUint160("NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq")
|
2020-09-28 14:24:21 +00:00
|
|
|
require.NoError(t, err)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr2))
|
|
|
|
e.CheckNextLine(t, "^\\s*$")
|
2020-09-28 14:24:21 +00:00
|
|
|
|
2021-05-11 14:13:33 +00:00
|
|
|
addr3, err := address.StringToUint160("NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP")
|
2020-09-28 14:24:21 +00:00
|
|
|
require.NoError(t, err)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr3))
|
2020-09-28 14:24:21 +00:00
|
|
|
// The order of assets is undefined.
|
|
|
|
for i := 0; i < 2; i++ {
|
2022-10-05 06:44:10 +00:00
|
|
|
line := e.GetNextLine(t)
|
2020-09-28 14:24:21 +00:00
|
|
|
if strings.Contains(line, "GAS") {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckLine(t, line, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
|
2020-09-28 14:24:21 +00:00
|
|
|
balance = e.Chain.GetUtilityTokenBalance(addr3)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Updated:")
|
2020-09-28 14:24:21 +00:00
|
|
|
} else {
|
2022-10-05 06:44:10 +00:00
|
|
|
balance, index := e.Chain.GetGoverningTokenBalance(testcli.ValidatorHash)
|
|
|
|
e.CheckLine(t, line, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
|
|
|
|
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+balance.String()+"$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
|
2020-09-28 14:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-02 12:43:09 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*$")
|
2022-10-28 09:12:32 +00:00
|
|
|
addr4, err := address.StringToUint160("NiFxRcC5Anz9pmqQyMHh5vamBUZDbRRRzA") // deployed verify.go contract
|
2021-03-02 12:43:09 +00:00
|
|
|
require.NoError(t, err)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr4))
|
|
|
|
e.CheckEOF(t)
|
2020-09-28 14:24:21 +00:00
|
|
|
})
|
|
|
|
t.Run("Bad token", func(t *testing.T) {
|
|
|
|
e.Run(t, append(cmd, "--token", "kek")...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.ValidatorAddr)
|
|
|
|
e.CheckNextLine(t, `^\s*Can't find data for "kek" token\s*`)
|
|
|
|
e.CheckEOF(t)
|
2020-09-28 14:24:21 +00:00
|
|
|
})
|
|
|
|
t.Run("Bad wallet", func(t *testing.T) {
|
|
|
|
e.RunWithError(t, append(cmdbalance, "--wallet", "/dev/null")...)
|
|
|
|
})
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
2020-08-31 09:42:42 +00:00
|
|
|
|
2020-11-24 08:14:25 +00:00
|
|
|
func TestNEP17Transfer(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
w, err := wallet.NewWalletFromFile("../testdata/testwallet.json")
|
2020-08-31 09:42:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2020-08-31 09:42:42 +00:00
|
|
|
args := []string{
|
2020-11-24 08:14:25 +00:00
|
|
|
"neo-go", "wallet", "nep17", "transfer",
|
2020-08-31 09:42:42 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
2020-08-31 09:42:42 +00:00
|
|
|
"--to", w.Accounts[0].Address,
|
2020-12-13 18:05:49 +00:00
|
|
|
"--token", "NEO",
|
2020-08-31 09:42:42 +00:00
|
|
|
"--amount", "1",
|
2022-10-05 06:44:10 +00:00
|
|
|
"--from", testcli.ValidatorAddr,
|
2020-08-31 09:42:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 08:02:28 +00:00
|
|
|
t.Run("missing receiver", func(t *testing.T) {
|
|
|
|
as := append([]string{}, args[:8]...)
|
|
|
|
as = append(as, args[10:]...)
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.RunWithError(t, as...)
|
|
|
|
e.In.Reset()
|
|
|
|
})
|
|
|
|
|
2020-08-31 09:42:42 +00:00
|
|
|
t.Run("InvalidPassword", func(t *testing.T) {
|
|
|
|
e.In.WriteString("onetwothree\r")
|
|
|
|
e.RunWithError(t, args...)
|
|
|
|
e.In.Reset()
|
|
|
|
})
|
|
|
|
|
2021-09-15 09:40:30 +00:00
|
|
|
t.Run("no confirmation", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.RunWithError(t, args...)
|
|
|
|
e.In.Reset()
|
|
|
|
})
|
|
|
|
t.Run("cancel after prompt", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.RunWithError(t, args...)
|
|
|
|
e.In.Reset()
|
|
|
|
})
|
|
|
|
|
2020-08-31 09:42:42 +00:00
|
|
|
e.In.WriteString("one\r")
|
2021-09-15 09:40:30 +00:00
|
|
|
e.In.WriteString("Y\r")
|
2020-08-31 09:42:42 +00:00
|
|
|
e.Run(t, args...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, `^Network fee:\s*(\d|\.)+`)
|
|
|
|
e.CheckNextLine(t, `^System fee:\s*(\d|\.)+`)
|
|
|
|
e.CheckNextLine(t, `^Total fee:\s*(\d|\.)+`)
|
|
|
|
e.CheckTxPersisted(t)
|
2020-08-31 09:42:42 +00:00
|
|
|
|
2022-09-01 16:04:47 +00:00
|
|
|
sh := w.Accounts[0].ScriptHash()
|
2020-08-31 09:42:42 +00:00
|
|
|
b, _ := e.Chain.GetGoverningTokenBalance(sh)
|
|
|
|
require.Equal(t, big.NewInt(1), b)
|
2021-01-11 12:58:37 +00:00
|
|
|
|
2021-09-15 09:40:30 +00:00
|
|
|
t.Run("with force", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, append(args, "--force")...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2021-09-15 09:40:30 +00:00
|
|
|
|
|
|
|
b, _ := e.Chain.GetGoverningTokenBalance(sh)
|
|
|
|
require.Equal(t, big.NewInt(2), b)
|
|
|
|
})
|
|
|
|
|
2021-04-21 09:50:04 +00:00
|
|
|
hVerify := deployVerifyContract(t, e)
|
2021-05-11 13:32:09 +00:00
|
|
|
const validatorDefault = "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn"
|
2021-04-21 09:50:04 +00:00
|
|
|
|
2021-01-11 12:58:37 +00:00
|
|
|
t.Run("default address", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--from", testcli.ValidatorAddr,
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2021-01-11 12:58:37 +00:00
|
|
|
"NEO:"+validatorDefault+":42",
|
|
|
|
"GAS:"+validatorDefault+":7")
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2021-01-11 12:58:37 +00:00
|
|
|
|
|
|
|
args := args[:len(args)-2] // cut '--from' argument
|
2021-09-15 09:40:30 +00:00
|
|
|
args = append(args, "--force")
|
2021-01-11 12:58:37 +00:00
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, args...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2021-01-11 12:58:37 +00:00
|
|
|
|
|
|
|
b, _ := e.Chain.GetGoverningTokenBalance(sh)
|
2021-09-15 09:40:30 +00:00
|
|
|
require.Equal(t, big.NewInt(3), b)
|
2021-01-11 12:58:37 +00:00
|
|
|
|
|
|
|
sh, err = address.StringToUint160(validatorDefault)
|
|
|
|
require.NoError(t, err)
|
|
|
|
b, _ = e.Chain.GetGoverningTokenBalance(sh)
|
|
|
|
require.Equal(t, big.NewInt(41), b)
|
|
|
|
})
|
2021-04-16 10:45:54 +00:00
|
|
|
|
2021-04-26 12:56:19 +00:00
|
|
|
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,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--from", testcli.ValidatorAddr,
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2021-04-26 12:56:19 +00:00
|
|
|
"NEO:"+validatorDefault+":42",
|
|
|
|
"GAS:"+validatorDefault+":7",
|
2022-10-05 06:44:10 +00:00
|
|
|
"--", testcli.ValidatorAddr+":Global")
|
|
|
|
e.CheckTxPersisted(t)
|
2021-04-26 12:56:19 +00:00
|
|
|
})
|
|
|
|
|
2021-04-21 09:50:04 +00:00
|
|
|
validTil := e.Chain.BlockHeight() + 100
|
|
|
|
cmd := []string{
|
|
|
|
"neo-go", "wallet", "nep17", "transfer",
|
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
2021-04-21 09:50:04 +00:00
|
|
|
"--to", address.Uint160ToString(e.Chain.GetNotaryContractScriptHash()),
|
|
|
|
"--token", "GAS",
|
|
|
|
"--amount", "1",
|
2022-10-05 06:44:10 +00:00
|
|
|
"--from", testcli.ValidatorAddr,
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2022-10-05 06:44:10 +00:00
|
|
|
"[", testcli.ValidatorAddr, strconv.Itoa(int(validTil)), "]"}
|
2021-04-21 09:50:04 +00:00
|
|
|
|
2021-04-16 10:45:54 +00:00
|
|
|
t.Run("with data", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
2021-04-21 09:50:04 +00:00
|
|
|
e.Run(t, cmd...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2021-04-16 10:45:54 +00:00
|
|
|
})
|
2021-04-21 09:50:04 +00:00
|
|
|
|
|
|
|
t.Run("with data and signers", func(t *testing.T) {
|
|
|
|
t.Run("invalid sender's scope", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
2022-10-05 06:44:10 +00:00
|
|
|
e.RunWithError(t, append(cmd, "--", testcli.ValidatorAddr+":None")...)
|
2021-04-21 09:50:04 +00:00
|
|
|
})
|
|
|
|
t.Run("good", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
2022-10-05 06:44:10 +00:00
|
|
|
e.Run(t, append(cmd, "--", testcli.ValidatorAddr+":Global")...) // CalledByEntry is enough, but it's the default value, so check something else
|
|
|
|
e.CheckTxPersisted(t)
|
2021-04-21 09:50:04 +00:00
|
|
|
})
|
|
|
|
t.Run("several signers", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
2022-10-05 06:44:10 +00:00
|
|
|
e.Run(t, append(cmd, "--", testcli.ValidatorAddr, hVerify.StringLE())...)
|
|
|
|
e.CheckTxPersisted(t)
|
2021-04-21 09:50:04 +00:00
|
|
|
})
|
|
|
|
})
|
2020-08-31 09:42:42 +00:00
|
|
|
}
|
2020-09-01 12:20:38 +00:00
|
|
|
|
2020-11-24 08:14:25 +00:00
|
|
|
func TestNEP17MultiTransfer(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
privs, _ := testcli.GenerateKeys(t, 3)
|
2020-09-01 12:20:38 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2020-12-13 18:25:04 +00:00
|
|
|
neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo)
|
2020-09-25 16:32:53 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-01 12:20:38 +00:00
|
|
|
args := []string{
|
2020-11-24 08:14:25 +00:00
|
|
|
"neo-go", "wallet", "nep17", "multitransfer",
|
2020-10-14 15:13:20 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
|
|
|
"--from", testcli.ValidatorAddr,
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2020-12-13 18:05:49 +00:00
|
|
|
"NEO:" + privs[0].Address() + ":42",
|
2020-09-01 12:20:38 +00:00
|
|
|
"GAS:" + privs[1].Address() + ":7",
|
2020-09-25 16:32:53 +00:00
|
|
|
neoContractHash.StringLE() + ":" + privs[2].Address() + ":13",
|
2020-09-01 12:20:38 +00:00
|
|
|
}
|
2021-04-21 12:01:42 +00:00
|
|
|
hVerify := deployVerifyContract(t, e)
|
2020-09-01 12:20:38 +00:00
|
|
|
|
2021-04-21 12:01:42 +00:00
|
|
|
t.Run("no cosigners", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, args...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2021-04-21 12:01:42 +00:00
|
|
|
|
|
|
|
b, _ := e.Chain.GetGoverningTokenBalance(privs[0].GetScriptHash())
|
|
|
|
require.Equal(t, big.NewInt(42), b)
|
|
|
|
b = e.Chain.GetUtilityTokenBalance(privs[1].GetScriptHash())
|
|
|
|
require.Equal(t, big.NewInt(int64(fixedn.Fixed8FromInt64(7))), b)
|
|
|
|
b, _ = e.Chain.GetGoverningTokenBalance(privs[2].GetScriptHash())
|
|
|
|
require.Equal(t, big.NewInt(13), b)
|
|
|
|
})
|
2020-09-01 12:20:38 +00:00
|
|
|
|
2021-04-21 12:01:42 +00:00
|
|
|
t.Run("invalid sender scope", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.RunWithError(t, append(args,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--", testcli.ValidatorAddr+":None")...) // invalid sender scope
|
2021-04-21 12:01:42 +00:00
|
|
|
})
|
|
|
|
t.Run("Global sender scope", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, append(args,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--", testcli.ValidatorAddr+":Global")...)
|
|
|
|
e.CheckTxPersisted(t)
|
2021-04-21 12:01:42 +00:00
|
|
|
})
|
|
|
|
t.Run("Several cosigners", func(t *testing.T) {
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, append(args,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--", testcli.ValidatorAddr, hVerify.StringLE())...)
|
|
|
|
e.CheckTxPersisted(t)
|
2021-04-21 12:01:42 +00:00
|
|
|
})
|
2020-09-01 12:20:38 +00:00
|
|
|
}
|
2020-09-01 12:40:32 +00:00
|
|
|
|
2020-11-24 08:14:25 +00:00
|
|
|
func TestNEP17ImportToken(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2021-08-25 19:17:37 +00:00
|
|
|
tmpDir := t.TempDir()
|
2021-11-17 11:14:22 +00:00
|
|
|
walletPath := filepath.Join(tmpDir, "walletForImport.json")
|
2020-09-01 12:40:32 +00:00
|
|
|
|
2020-12-13 18:25:04 +00:00
|
|
|
neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo)
|
2020-09-25 16:32:53 +00:00
|
|
|
require.NoError(t, err)
|
2020-12-13 18:25:04 +00:00
|
|
|
gasContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Gas)
|
2020-09-25 16:32:53 +00:00
|
|
|
require.NoError(t, err)
|
2021-05-17 09:08:40 +00:00
|
|
|
nnsContractHash := deployNNSContract(t, e)
|
2020-09-01 12:40:32 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
|
2021-04-16 09:29:46 +00:00
|
|
|
|
|
|
|
// missing token hash
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "nep17", "import",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", walletPath)
|
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
// additional parameter
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "nep17", "import",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", walletPath,
|
|
|
|
"--token", gasContractHash.StringLE(), "useless")
|
2020-11-24 08:14:25 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "import",
|
2020-09-01 12:40:32 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", walletPath,
|
2020-09-25 16:32:53 +00:00
|
|
|
"--token", gasContractHash.StringLE())
|
2020-11-24 08:14:25 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "import",
|
2020-09-01 12:40:32 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", walletPath,
|
2021-04-16 09:29:46 +00:00
|
|
|
"--token", address.Uint160ToString(neoContractHash)) // try address instead of sh
|
2020-09-01 12:40:32 +00:00
|
|
|
|
2021-11-18 13:37:42 +00:00
|
|
|
// not a NEP-17 token
|
2021-04-22 15:21:18 +00:00
|
|
|
e.RunWithError(t, "neo-go", "wallet", "nep17", "import",
|
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
|
|
|
"--wallet", walletPath,
|
|
|
|
"--token", nnsContractHash.StringLE())
|
|
|
|
|
2020-09-01 12:40:32 +00:00
|
|
|
t.Run("Info", func(t *testing.T) {
|
|
|
|
checkGASInfo := func(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Name:\\s*GasToken")
|
|
|
|
e.CheckNextLine(t, "^Symbol:\\s*GAS")
|
|
|
|
e.CheckNextLine(t, "^Hash:\\s*"+gasContractHash.StringLE())
|
|
|
|
e.CheckNextLine(t, "^Decimals:\\s*8")
|
|
|
|
e.CheckNextLine(t, "^Address:\\s*"+address.Uint160ToString(gasContractHash))
|
|
|
|
e.CheckNextLine(t, "^Standard:\\s*"+string(manifest.NEP17StandardName))
|
2020-09-01 12:40:32 +00:00
|
|
|
}
|
2022-08-05 10:32:37 +00:00
|
|
|
t.Run("excessive parameters", func(t *testing.T) {
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "nep17", "info",
|
|
|
|
"--wallet", walletPath, "--token", gasContractHash.StringLE(), "parameter")
|
|
|
|
})
|
2020-09-01 12:40:32 +00:00
|
|
|
t.Run("WithToken", func(t *testing.T) {
|
2020-11-24 08:14:25 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "info",
|
2020-09-25 16:32:53 +00:00
|
|
|
"--wallet", walletPath, "--token", gasContractHash.StringLE())
|
2020-09-01 12:40:32 +00:00
|
|
|
checkGASInfo(t)
|
|
|
|
})
|
|
|
|
t.Run("NoToken", func(t *testing.T) {
|
2020-11-24 08:14:25 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "info",
|
2020-09-01 12:40:32 +00:00
|
|
|
"--wallet", walletPath)
|
|
|
|
checkGASInfo(t)
|
|
|
|
_, err := e.Out.ReadString('\n')
|
|
|
|
require.NoError(t, err)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Name:\\s*NeoToken")
|
|
|
|
e.CheckNextLine(t, "^Symbol:\\s*NEO")
|
|
|
|
e.CheckNextLine(t, "^Hash:\\s*"+neoContractHash.StringLE())
|
|
|
|
e.CheckNextLine(t, "^Decimals:\\s*0")
|
|
|
|
e.CheckNextLine(t, "^Address:\\s*"+address.Uint160ToString(neoContractHash))
|
|
|
|
e.CheckNextLine(t, "^Standard:\\s*"+string(manifest.NEP17StandardName))
|
2020-09-01 12:40:32 +00:00
|
|
|
})
|
|
|
|
t.Run("Remove", func(t *testing.T) {
|
2022-08-05 10:32:37 +00:00
|
|
|
e.RunWithError(t, "neo-go", "wallet", "nep17", "remove",
|
|
|
|
"--wallet", walletPath, "--token", neoContractHash.StringLE(), "add")
|
2020-09-01 12:40:32 +00:00
|
|
|
e.In.WriteString("y\r")
|
2020-11-24 08:14:25 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "remove",
|
2020-09-25 16:32:53 +00:00
|
|
|
"--wallet", walletPath, "--token", neoContractHash.StringLE())
|
2020-11-24 08:14:25 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "info",
|
2020-09-01 12:40:32 +00:00
|
|
|
"--wallet", walletPath)
|
|
|
|
checkGASInfo(t)
|
|
|
|
_, err := e.Out.ReadString('\n')
|
|
|
|
require.Equal(t, err, io.EOF)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|