2022-10-05 15:06:06 +00:00
|
|
|
package nep_test
|
2021-04-22 15:21:18 +00:00
|
|
|
|
|
|
|
import (
|
2021-05-05 14:48:40 +00:00
|
|
|
"bytes"
|
2022-02-04 16:18:35 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
2021-04-26 14:09:37 +00:00
|
|
|
"fmt"
|
2021-04-23 15:08:47 +00:00
|
|
|
"io"
|
2021-05-05 10:22:26 +00:00
|
|
|
"math/big"
|
2022-02-22 16:27:32 +00:00
|
|
|
"os"
|
2021-11-17 11:14:22 +00:00
|
|
|
"path/filepath"
|
2022-02-04 16:18:35 +00:00
|
|
|
"strconv"
|
2021-04-22 15:21:18 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/testcli"
|
2023-08-29 17:39:27 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/versionutil"
|
2021-04-22 15:21:18 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
2021-05-05 10:22:26 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-04-23 10:37:59 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
2021-04-23 16:00:45 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2021-04-22 15:21:18 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-04-23 16:00:45 +00:00
|
|
|
const (
|
2021-05-12 20:17:03 +00:00
|
|
|
// nftOwnerAddr is the owner of NFT-ND HASHY token (../examples/nft-nd/nft.go).
|
2021-05-11 13:32:09 +00:00
|
|
|
nftOwnerAddr = "NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB"
|
2022-10-05 06:44:10 +00:00
|
|
|
nftOwnerWallet = "../../examples/my_wallet.json"
|
2021-04-23 16:00:45 +00:00
|
|
|
nftOwnerPass = "qwerty"
|
2023-08-29 17:39:27 +00:00
|
|
|
|
|
|
|
// Keep contract NEFs consistent between runs.
|
|
|
|
_ = versionutil.TestVersion
|
2021-04-23 16:00:45 +00:00
|
|
|
)
|
|
|
|
|
2021-04-22 15:21:18 +00:00
|
|
|
func TestNEP11Import(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2021-04-22 15:21:18 +00:00
|
|
|
|
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")
|
2021-04-22 15:21:18 +00:00
|
|
|
|
2021-05-17 09:08:40 +00:00
|
|
|
// deploy NFT NeoNameService contract
|
|
|
|
nnsContractHash := deployNNSContract(t, e)
|
2022-02-04 16:18:35 +00:00
|
|
|
// deploy NFT-D NeoFS Object contract
|
|
|
|
nfsContractHash := deployNFSContract(t, e)
|
2021-04-22 15:21:18 +00:00
|
|
|
neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo)
|
|
|
|
require.NoError(t, err)
|
|
|
|
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
"neo-go", "wallet", "nep11", "import",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-04-22 15:21:18 +00:00
|
|
|
"--wallet", walletPath,
|
|
|
|
}
|
|
|
|
// missing token hash
|
|
|
|
e.RunWithError(t, args...)
|
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
// excessive parameters
|
|
|
|
e.RunWithError(t, append(args, "--token", nnsContractHash.StringLE(), "something")...)
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
// good: non-divisible
|
2021-04-22 15:21:18 +00:00
|
|
|
e.Run(t, append(args, "--token", nnsContractHash.StringLE())...)
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
// good: divisible
|
|
|
|
e.Run(t, append(args, "--token", nfsContractHash.StringLE())...)
|
|
|
|
|
2021-04-22 15:21:18 +00:00
|
|
|
// already exists
|
|
|
|
e.RunWithError(t, append(args, "--token", nnsContractHash.StringLE())...)
|
|
|
|
|
2021-11-18 13:37:42 +00:00
|
|
|
// not a NEP-11 token
|
2021-04-22 15:21:18 +00:00
|
|
|
e.RunWithError(t, append(args, "--token", neoContractHash.StringLE())...)
|
2021-04-23 10:37:59 +00:00
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
checkInfo := func(t *testing.T, h util.Uint160, name string, symbol string, decimals int) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^Name:\\s*"+name)
|
|
|
|
e.CheckNextLine(t, "^Symbol:\\s*"+symbol)
|
|
|
|
e.CheckNextLine(t, "^Hash:\\s*"+h.StringLE())
|
|
|
|
e.CheckNextLine(t, "^Decimals:\\s*"+strconv.Itoa(decimals))
|
|
|
|
e.CheckNextLine(t, "^Address:\\s*"+address.Uint160ToString(h))
|
|
|
|
e.CheckNextLine(t, "^Standard:\\s*"+string(manifest.NEP11StandardName))
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
2021-04-23 10:37:59 +00:00
|
|
|
t.Run("Info", func(t *testing.T) {
|
2022-08-05 10:32:37 +00:00
|
|
|
t.Run("excessive parameters", func(t *testing.T) {
|
|
|
|
e.RunWithError(t, "neo-go", "wallet", "nep11", "info",
|
|
|
|
"--wallet", walletPath, "--token", nnsContractHash.StringLE(), "qwerty")
|
|
|
|
})
|
2021-04-23 10:37:59 +00:00
|
|
|
t.Run("WithToken", func(t *testing.T) {
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "info",
|
|
|
|
"--wallet", walletPath, "--token", nnsContractHash.StringLE())
|
2022-02-04 16:18:35 +00:00
|
|
|
checkInfo(t, nnsContractHash, "NameService", "NNS", 0)
|
2021-04-23 10:37:59 +00:00
|
|
|
})
|
|
|
|
t.Run("NoToken", func(t *testing.T) {
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "info",
|
|
|
|
"--wallet", walletPath)
|
2022-02-04 16:18:35 +00:00
|
|
|
checkInfo(t, nnsContractHash, "NameService", "NNS", 0)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "")
|
2022-02-04 16:18:35 +00:00
|
|
|
checkInfo(t, nfsContractHash, "NeoFS Object NFT", "NFSO", 2)
|
2021-04-23 10:37:59 +00:00
|
|
|
})
|
|
|
|
})
|
2021-04-23 15:08:47 +00:00
|
|
|
|
|
|
|
t.Run("Remove", func(t *testing.T) {
|
2022-08-05 10:32:37 +00:00
|
|
|
e.RunWithError(t, "neo-go", "wallet", "nep11", "remove",
|
|
|
|
"--wallet", walletPath, "--token", nnsContractHash.StringLE(), "parameter")
|
2021-04-23 15:08:47 +00:00
|
|
|
e.In.WriteString("y\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "remove",
|
|
|
|
"--wallet", walletPath, "--token", nnsContractHash.StringLE())
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "info",
|
|
|
|
"--wallet", walletPath)
|
2022-02-04 16:18:35 +00:00
|
|
|
checkInfo(t, nfsContractHash, "NeoFS Object NFT", "NFSO", 2)
|
2021-04-23 15:08:47 +00:00
|
|
|
_, err := e.Out.ReadString('\n')
|
|
|
|
require.Equal(t, err, io.EOF)
|
|
|
|
})
|
2021-04-22 15:21:18 +00:00
|
|
|
}
|
2021-04-23 16:00:45 +00:00
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(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-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
// copy wallet to temp dir in order not to overwrite the original file
|
2022-02-22 16:27:32 +00:00
|
|
|
bytesRead, err := os.ReadFile(nftOwnerWallet)
|
2021-04-23 16:00:45 +00:00
|
|
|
require.NoError(t, err)
|
2021-11-17 11:14:22 +00:00
|
|
|
wall := filepath.Join(tmpDir, "my_wallet.json")
|
2022-02-22 16:27:32 +00:00
|
|
|
err = os.WriteFile(wall, bytesRead, 0755)
|
2021-04-23 16:00:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// transfer funds to contract owner
|
|
|
|
e.In.WriteString("one\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "transfer",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", testcli.ValidatorWallet,
|
2021-04-23 16:00:45 +00:00
|
|
|
"--to", nftOwnerAddr,
|
|
|
|
"--token", "GAS",
|
|
|
|
"--amount", "10000",
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2022-10-05 06:44:10 +00:00
|
|
|
"--from", testcli.ValidatorAddr)
|
|
|
|
e.CheckTxPersisted(t)
|
2021-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
// deploy NFT HASHY contract
|
|
|
|
h := deployNFTContract(t, e)
|
|
|
|
|
2021-04-28 14:50:12 +00:00
|
|
|
mint := func(t *testing.T) []byte {
|
|
|
|
// mint 1 HASHY token by transferring 10 GAS to HASHY contract
|
|
|
|
e.In.WriteString(nftOwnerPass + "\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "transfer",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2021-04-28 14:50:12 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--to", h.StringLE(),
|
|
|
|
"--token", "GAS",
|
|
|
|
"--amount", "10",
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2021-04-28 14:50:12 +00:00
|
|
|
"--from", nftOwnerAddr)
|
2022-10-05 06:44:10 +00:00
|
|
|
txMint, _ := e.CheckTxPersisted(t)
|
2021-04-28 14:50:12 +00:00
|
|
|
|
|
|
|
// get NFT ID from AER
|
|
|
|
aer, err := e.Chain.GetAppExecResults(txMint.Hash(), trigger.Application)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(aer))
|
|
|
|
require.Equal(t, 2, len(aer[0].Events))
|
|
|
|
hashyMintEvent := aer[0].Events[1]
|
|
|
|
require.Equal(t, "Transfer", hashyMintEvent.Name)
|
|
|
|
tokenID, err := hashyMintEvent.Item.Value().([]stackitem.Item)[3].TryBytes()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, tokenID)
|
|
|
|
return tokenID
|
|
|
|
}
|
2021-04-23 16:00:45 +00:00
|
|
|
|
2021-04-28 14:50:12 +00:00
|
|
|
tokenID := mint(t)
|
2022-09-08 16:05:32 +00:00
|
|
|
var hashBeforeTransfer = e.Chain.CurrentHeaderHash()
|
2021-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
// check the balance
|
|
|
|
cmdCheckBalance := []string{"neo-go", "wallet", "nep11", "balance",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-04-23 16:00:45 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--address", nftOwnerAddr}
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult := func(t *testing.T, acc string, ids ...[]byte) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Account\\s+"+acc)
|
|
|
|
e.CheckNextLine(t, "^\\s*HASHY:\\s+HASHY NFT \\("+h.StringLE()+"\\)")
|
2022-08-29 19:39:13 +00:00
|
|
|
|
|
|
|
// Hashes can be ordered in any way, so make a regexp for them.
|
|
|
|
var tokstring = "("
|
|
|
|
for i, id := range ids {
|
|
|
|
if i > 0 {
|
|
|
|
tokstring += "|"
|
|
|
|
}
|
|
|
|
tokstring += hex.EncodeToString(id)
|
|
|
|
}
|
|
|
|
tokstring += ")"
|
|
|
|
|
|
|
|
for range ids {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Token: "+tokstring+"\\s*$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Amount: 1\\s*$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Updated: [0-9]+\\s*$")
|
2022-08-29 19:39:13 +00:00
|
|
|
}
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckEOF(t)
|
2021-04-23 16:00:45 +00:00
|
|
|
}
|
|
|
|
// balance check: by symbol, token is not imported
|
2022-08-29 19:39:13 +00:00
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", "HASHY")...)
|
|
|
|
checkBalanceResult(t, nftOwnerAddr, tokenID)
|
2022-08-05 10:32:37 +00:00
|
|
|
// balance check: excessive parameters
|
|
|
|
e.RunWithError(t, append(cmdCheckBalance, "--token", h.StringLE(), "neo-go")...)
|
2021-04-23 16:00:45 +00:00
|
|
|
// balance check: by hash, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult(t, nftOwnerAddr, tokenID)
|
2021-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
// import token
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "import",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2021-04-23 16:00:45 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--token", h.StringLE())
|
|
|
|
|
|
|
|
// balance check: by symbol, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", "HASHY")...)
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult(t, nftOwnerAddr, tokenID)
|
2021-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
// balance check: all accounts
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "balance",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2021-04-23 16:00:45 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--token", h.StringLE())
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult(t, nftOwnerAddr, tokenID)
|
2021-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
// remove token from wallet
|
|
|
|
e.In.WriteString("y\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "remove",
|
|
|
|
"--wallet", wall, "--token", h.StringLE())
|
2021-04-27 14:55:01 +00:00
|
|
|
|
|
|
|
// ownerOf: missing contract hash
|
|
|
|
cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOf",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-04-27 14:55:01 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdOwnerOf...)
|
|
|
|
cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// ownerOf: missing token ID
|
|
|
|
e.RunWithError(t, cmdOwnerOf...)
|
2022-02-04 16:18:35 +00:00
|
|
|
cmdOwnerOf = append(cmdOwnerOf, "--id", hex.EncodeToString(tokenID))
|
2021-04-27 14:55:01 +00:00
|
|
|
|
|
|
|
// ownerOf: good
|
|
|
|
e.Run(t, cmdOwnerOf...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, nftOwnerAddr)
|
2021-04-23 16:00:45 +00:00
|
|
|
|
2021-04-28 14:50:12 +00:00
|
|
|
// tokensOf: missing contract hash
|
|
|
|
cmdTokensOf := []string{"neo-go", "wallet", "nep11", "tokensOf",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdTokensOf...)
|
|
|
|
cmdTokensOf = append(cmdTokensOf, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// tokensOf: missing owner address
|
|
|
|
e.RunWithError(t, cmdTokensOf...)
|
|
|
|
cmdTokensOf = append(cmdTokensOf, "--address", nftOwnerAddr)
|
|
|
|
|
|
|
|
// tokensOf: good
|
|
|
|
e.Run(t, cmdTokensOf...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(tokenID), e.GetNextLine(t))
|
2021-04-28 14:50:12 +00:00
|
|
|
|
2021-04-26 14:09:37 +00:00
|
|
|
// properties: no contract
|
|
|
|
cmdProperties := []string{
|
|
|
|
"neo-go", "wallet", "nep11", "properties",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-04-26 14:09:37 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdProperties...)
|
|
|
|
cmdProperties = append(cmdProperties, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// properties: no token ID
|
|
|
|
e.RunWithError(t, cmdProperties...)
|
2022-02-04 16:18:35 +00:00
|
|
|
cmdProperties = append(cmdProperties, "--id", hex.EncodeToString(tokenID))
|
2021-04-26 14:09:37 +00:00
|
|
|
|
|
|
|
// properties: ok
|
|
|
|
e.Run(t, cmdProperties...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, fmt.Sprintf(`{"name":"HASHY %s"}`, base64.StdEncoding.EncodeToString(tokenID)), e.GetNextLine(t))
|
2021-04-26 14:09:37 +00:00
|
|
|
|
2021-04-28 14:50:12 +00:00
|
|
|
// tokensOf: good, several tokens
|
|
|
|
tokenID1 := mint(t)
|
|
|
|
e.Run(t, cmdTokensOf...)
|
2021-05-05 14:48:40 +00:00
|
|
|
fst, snd := tokenID, tokenID1
|
|
|
|
if bytes.Compare(tokenID, tokenID1) == 1 {
|
|
|
|
fst, snd = snd, fst
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(fst), e.GetNextLine(t))
|
|
|
|
require.Equal(t, hex.EncodeToString(snd), e.GetNextLine(t))
|
2021-04-28 14:50:12 +00:00
|
|
|
|
|
|
|
// tokens: missing contract hash
|
|
|
|
cmdTokens := []string{"neo-go", "wallet", "nep11", "tokens",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdTokens...)
|
|
|
|
cmdTokens = append(cmdTokens, "--token", h.StringLE())
|
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
// tokens: excessive parameters
|
|
|
|
e.RunWithError(t, append(cmdTokens, "additional")...)
|
2021-04-28 14:50:12 +00:00
|
|
|
// tokens: good, several tokens
|
|
|
|
e.Run(t, cmdTokens...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(fst), e.GetNextLine(t))
|
|
|
|
require.Equal(t, hex.EncodeToString(snd), e.GetNextLine(t))
|
2021-04-28 14:50:12 +00:00
|
|
|
|
|
|
|
// balance check: several tokens, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult(t, nftOwnerAddr, tokenID, tokenID1)
|
2021-04-28 14:50:12 +00:00
|
|
|
|
2021-04-23 16:00:45 +00:00
|
|
|
cmdTransfer := []string{
|
|
|
|
"neo-go", "wallet", "nep11", "transfer",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-04-23 16:00:45 +00:00
|
|
|
"--wallet", wall,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--to", testcli.ValidatorAddr,
|
2021-04-23 16:00:45 +00:00
|
|
|
"--from", nftOwnerAddr,
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2021-04-23 16:00:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// transfer: unimported token with symbol id specified
|
|
|
|
e.In.WriteString(nftOwnerPass + "\r")
|
|
|
|
e.RunWithError(t, append(cmdTransfer,
|
|
|
|
"--token", "HASHY")...)
|
|
|
|
cmdTransfer = append(cmdTransfer, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// transfer: no id specified
|
|
|
|
e.In.WriteString(nftOwnerPass + "\r")
|
|
|
|
e.RunWithError(t, cmdTransfer...)
|
|
|
|
|
|
|
|
// transfer: good
|
|
|
|
e.In.WriteString(nftOwnerPass + "\r")
|
2022-02-04 16:18:35 +00:00
|
|
|
e.Run(t, append(cmdTransfer, "--id", hex.EncodeToString(tokenID))...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2021-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
// check balance after transfer
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult(t, nftOwnerAddr, tokenID1)
|
2021-05-05 10:22:26 +00:00
|
|
|
|
2021-11-18 13:37:42 +00:00
|
|
|
// transfer: good, to NEP-11-Payable contract, with data
|
2021-05-05 10:22:26 +00:00
|
|
|
verifyH := deployVerifyContract(t, e)
|
|
|
|
cmdTransfer = []string{
|
|
|
|
"neo-go", "wallet", "nep11", "transfer",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2021-05-05 10:22:26 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--to", verifyH.StringLE(),
|
|
|
|
"--from", nftOwnerAddr,
|
|
|
|
"--token", h.StringLE(),
|
2022-02-04 16:18:35 +00:00
|
|
|
"--id", hex.EncodeToString(tokenID1),
|
2021-09-15 09:40:30 +00:00
|
|
|
"--force",
|
2021-05-05 10:22:26 +00:00
|
|
|
"string:some_data",
|
|
|
|
}
|
|
|
|
e.In.WriteString(nftOwnerPass + "\r")
|
|
|
|
e.Run(t, cmdTransfer...)
|
2022-10-05 06:44:10 +00:00
|
|
|
tx, _ := e.CheckTxPersisted(t)
|
2021-05-05 10:22:26 +00:00
|
|
|
// check OnNEP11Payment event
|
|
|
|
aer, err := e.Chain.GetAppExecResults(tx.Hash(), trigger.Application)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(aer[0].Events))
|
|
|
|
nftOwnerHash, err := address.StringToUint160(nftOwnerAddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, state.NotificationEvent{
|
|
|
|
ScriptHash: verifyH,
|
|
|
|
Name: "OnNEP11Payment",
|
|
|
|
Item: stackitem.NewArray([]stackitem.Item{
|
2022-05-30 08:01:12 +00:00
|
|
|
stackitem.NewByteArray(nftOwnerHash.BytesBE()),
|
2021-05-05 10:22:26 +00:00
|
|
|
stackitem.NewBigInteger(big.NewInt(1)),
|
|
|
|
stackitem.NewByteArray(tokenID1),
|
|
|
|
stackitem.NewByteArray([]byte("some_data")),
|
|
|
|
}),
|
|
|
|
}, aer[0].Events[1])
|
|
|
|
|
|
|
|
// check balance after transfer
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult(t, nftOwnerAddr)
|
2022-09-08 16:05:32 +00:00
|
|
|
|
|
|
|
// historic calls still remember the good old days.
|
|
|
|
cmdOwnerOf = append(cmdOwnerOf, "--historic", hashBeforeTransfer.StringLE())
|
|
|
|
e.Run(t, cmdOwnerOf...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, nftOwnerAddr)
|
2022-09-08 16:05:32 +00:00
|
|
|
|
|
|
|
cmdTokensOf = append(cmdTokensOf, "--historic", hashBeforeTransfer.StringLE())
|
|
|
|
e.Run(t, cmdTokensOf...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(tokenID), e.GetNextLine(t))
|
2022-09-08 16:05:32 +00:00
|
|
|
|
|
|
|
cmdTokens = append(cmdTokens, "--historic", hashBeforeTransfer.StringLE())
|
|
|
|
e.Run(t, cmdTokens...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(tokenID), e.GetNextLine(t))
|
2022-09-08 16:05:32 +00:00
|
|
|
|
|
|
|
// this one is not affected by transfer, but anyway
|
|
|
|
cmdProperties = append(cmdProperties, "--historic", hashBeforeTransfer.StringLE())
|
|
|
|
e.Run(t, cmdProperties...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, fmt.Sprintf(`{"name":"HASHY %s"}`, base64.StdEncoding.EncodeToString(tokenID)), e.GetNextLine(t))
|
2021-04-23 16:00:45 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2022-02-04 16:18:35 +00:00
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
|
|
|
// copy wallet to temp dir in order not to overwrite the original file
|
2022-10-05 06:44:10 +00:00
|
|
|
bytesRead, err := os.ReadFile(testcli.ValidatorWallet)
|
2022-02-04 16:18:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
wall := filepath.Join(tmpDir, "my_wallet.json")
|
2022-02-22 16:27:32 +00:00
|
|
|
err = os.WriteFile(wall, bytesRead, 0755)
|
2022-02-04 16:18:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// deploy NeoFS Object contract
|
|
|
|
h := deployNFSContract(t, e)
|
|
|
|
|
|
|
|
mint := func(t *testing.T, containerID, objectID util.Uint256) []byte {
|
|
|
|
// mint 1.00 NFSO token by transferring 10 GAS to NFSO contract
|
2022-10-05 06:44:10 +00:00
|
|
|
e.In.WriteString(testcli.ValidatorPass + "\r")
|
2022-02-04 16:18:35 +00:00
|
|
|
e.Run(t, "neo-go", "wallet", "nep17", "transfer",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--to", h.StringLE(),
|
|
|
|
"--token", "GAS",
|
|
|
|
"--amount", "10",
|
|
|
|
"--force",
|
2022-10-05 06:44:10 +00:00
|
|
|
"--from", testcli.ValidatorAddr,
|
2022-02-04 16:18:35 +00:00
|
|
|
"--", "[", "hash256:"+containerID.StringLE(), "hash256:"+objectID.StringLE(), "]",
|
|
|
|
)
|
2022-10-05 06:44:10 +00:00
|
|
|
txMint, _ := e.CheckTxPersisted(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// get NFT ID from AER
|
|
|
|
aer, err := e.Chain.GetAppExecResults(txMint.Hash(), trigger.Application)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(aer))
|
|
|
|
require.Equal(t, 2, len(aer[0].Events))
|
|
|
|
nfsoMintEvent := aer[0].Events[1]
|
|
|
|
require.Equal(t, "Transfer", nfsoMintEvent.Name)
|
|
|
|
tokenID, err := nfsoMintEvent.Item.Value().([]stackitem.Item)[3].TryBytes()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, tokenID)
|
|
|
|
return tokenID
|
|
|
|
}
|
|
|
|
|
|
|
|
container1ID := util.Uint256{1, 2, 3}
|
|
|
|
object1ID := util.Uint256{4, 5, 6}
|
|
|
|
token1ID := mint(t, container1ID, object1ID)
|
|
|
|
|
|
|
|
container2ID := util.Uint256{7, 8, 9}
|
|
|
|
object2ID := util.Uint256{10, 11, 12}
|
|
|
|
token2ID := mint(t, container2ID, object2ID)
|
|
|
|
|
|
|
|
// check properties
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "properties",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
"--token", h.StringLE(),
|
|
|
|
"--id", hex.EncodeToString(token1ID))
|
2022-10-05 06:44:10 +00:00
|
|
|
jProps := e.GetNextLine(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
props := make(map[string]string)
|
|
|
|
require.NoError(t, json.Unmarshal([]byte(jProps), &props))
|
|
|
|
require.Equal(t, base64.StdEncoding.EncodeToString(container1ID.BytesBE()), props["containerID"])
|
|
|
|
require.Equal(t, base64.StdEncoding.EncodeToString(object1ID.BytesBE()), props["objectID"])
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckEOF(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
2022-08-29 19:39:13 +00:00
|
|
|
type idAmount struct {
|
|
|
|
id string
|
|
|
|
amount string
|
|
|
|
}
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
// check the balance
|
|
|
|
cmdCheckBalance := []string{"neo-go", "wallet", "nep11", "balance",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
"--wallet", wall,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--address", testcli.ValidatorAddr}
|
2022-08-29 19:39:13 +00:00
|
|
|
checkBalanceResult := func(t *testing.T, acc string, objs ...idAmount) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Account\\s+"+acc)
|
|
|
|
e.CheckNextLine(t, "^\\s*NFSO:\\s+NeoFS Object NFT \\("+h.StringLE()+"\\)")
|
2022-08-29 19:39:13 +00:00
|
|
|
|
|
|
|
for _, o := range objs {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, "^\\s*Token: "+o.id+"\\s*$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Amount: "+o.amount+"\\s*$")
|
|
|
|
e.CheckNextLine(t, "^\\s*Updated: [0-9]+\\s*$")
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckEOF(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
2022-08-29 19:39:13 +00:00
|
|
|
tokz := []idAmount{
|
|
|
|
{hex.EncodeToString(token1ID), "1"},
|
|
|
|
{hex.EncodeToString(token2ID), "1"},
|
|
|
|
}
|
2022-02-04 16:18:35 +00:00
|
|
|
// balance check: by symbol, token is not imported
|
2022-08-29 19:39:13 +00:00
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", "NFSO")...)
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz...)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// overall NFSO balance check: by hash, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz...)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// particular NFSO balance check: by hash, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE(), "--id", hex.EncodeToString(token2ID))...)
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz[1])
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// import token
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "import",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--token", h.StringLE())
|
|
|
|
|
|
|
|
// overall balance check: by symbol, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", "NFSO")...)
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz...)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// particular balance check: by symbol, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", "NFSO", "--id", hex.EncodeToString(token1ID))...)
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz[0])
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// remove token from wallet
|
|
|
|
e.In.WriteString("y\r")
|
|
|
|
e.Run(t, "neo-go", "wallet", "nep11", "remove",
|
|
|
|
"--wallet", wall, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// ownerOfD: missing contract hash
|
|
|
|
cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOfD",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdOwnerOf...)
|
|
|
|
cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// ownerOfD: missing token ID
|
|
|
|
e.RunWithError(t, cmdOwnerOf...)
|
|
|
|
cmdOwnerOf = append(cmdOwnerOf, "--id", hex.EncodeToString(token1ID))
|
|
|
|
|
|
|
|
// ownerOfD: good
|
|
|
|
e.Run(t, cmdOwnerOf...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, testcli.ValidatorAddr)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// tokensOf: missing contract hash
|
|
|
|
cmdTokensOf := []string{"neo-go", "wallet", "nep11", "tokensOf",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdTokensOf...)
|
|
|
|
cmdTokensOf = append(cmdTokensOf, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// tokensOf: missing owner address
|
|
|
|
e.RunWithError(t, cmdTokensOf...)
|
2022-10-05 06:44:10 +00:00
|
|
|
cmdTokensOf = append(cmdTokensOf, "--address", testcli.ValidatorAddr)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// tokensOf: good
|
|
|
|
e.Run(t, cmdTokensOf...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(token1ID), e.GetNextLine(t))
|
|
|
|
require.Equal(t, hex.EncodeToString(token2ID), e.GetNextLine(t))
|
|
|
|
e.CheckEOF(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// properties: no contract
|
|
|
|
cmdProperties := []string{
|
|
|
|
"neo-go", "wallet", "nep11", "properties",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdProperties...)
|
|
|
|
cmdProperties = append(cmdProperties, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// properties: no token ID
|
|
|
|
e.RunWithError(t, cmdProperties...)
|
|
|
|
cmdProperties = append(cmdProperties, "--id", hex.EncodeToString(token2ID))
|
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
// properties: additional parameter
|
|
|
|
e.RunWithError(t, append(cmdProperties, "additiona")...)
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
// properties: ok
|
|
|
|
e.Run(t, cmdProperties...)
|
2022-10-05 06:44:10 +00:00
|
|
|
jProps = e.GetNextLine(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
props = make(map[string]string)
|
|
|
|
require.NoError(t, json.Unmarshal([]byte(jProps), &props))
|
|
|
|
require.Equal(t, base64.StdEncoding.EncodeToString(container2ID.BytesBE()), props["containerID"])
|
|
|
|
require.Equal(t, base64.StdEncoding.EncodeToString(object2ID.BytesBE()), props["objectID"])
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckEOF(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// tokensOf: good, several tokens
|
|
|
|
e.Run(t, cmdTokensOf...)
|
|
|
|
fst, snd := token1ID, token2ID
|
|
|
|
if bytes.Compare(token1ID, token2ID) == 1 {
|
|
|
|
fst, snd = snd, fst
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(fst), e.GetNextLine(t))
|
|
|
|
require.Equal(t, hex.EncodeToString(snd), e.GetNextLine(t))
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// tokens: missing contract hash
|
|
|
|
cmdTokens := []string{"neo-go", "wallet", "nep11", "tokens",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
e.RunWithError(t, cmdTokens...)
|
|
|
|
cmdTokens = append(cmdTokens, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// tokens: good, several tokens
|
|
|
|
e.Run(t, cmdTokens...)
|
2022-10-05 06:44:10 +00:00
|
|
|
require.Equal(t, hex.EncodeToString(fst), e.GetNextLine(t))
|
|
|
|
require.Equal(t, hex.EncodeToString(snd), e.GetNextLine(t))
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// balance check: several tokens, ok
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz...)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
cmdTransfer := []string{
|
|
|
|
"neo-go", "wallet", "nep11", "transfer",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--to", nftOwnerAddr,
|
2022-10-05 06:44:10 +00:00
|
|
|
"--from", testcli.ValidatorAddr,
|
2022-02-04 16:18:35 +00:00
|
|
|
"--force",
|
|
|
|
}
|
|
|
|
|
|
|
|
// transfer: unimported token with symbol id specified
|
2022-10-05 06:44:10 +00:00
|
|
|
e.In.WriteString(testcli.ValidatorPass + "\r")
|
2022-02-04 16:18:35 +00:00
|
|
|
e.RunWithError(t, append(cmdTransfer,
|
|
|
|
"--token", "NFSO")...)
|
|
|
|
cmdTransfer = append(cmdTransfer, "--token", h.StringLE())
|
|
|
|
|
|
|
|
// transfer: no id specified
|
2022-10-05 06:44:10 +00:00
|
|
|
e.In.WriteString(testcli.ValidatorPass + "\r")
|
2022-02-04 16:18:35 +00:00
|
|
|
e.RunWithError(t, cmdTransfer...)
|
|
|
|
|
|
|
|
// transfer: good
|
2022-10-05 06:44:10 +00:00
|
|
|
e.In.WriteString(testcli.ValidatorPass + "\r")
|
2022-02-04 16:18:35 +00:00
|
|
|
e.Run(t, append(cmdTransfer, "--id", hex.EncodeToString(token1ID))...)
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckTxPersisted(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// check balance after transfer
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz[1]) // only token2ID expected to be on the balance
|
2022-02-04 16:18:35 +00:00
|
|
|
|
|
|
|
// transfer: good, 1/4 of the balance, to NEP-11-Payable contract, with data
|
|
|
|
verifyH := deployVerifyContract(t, e)
|
|
|
|
cmdTransfer = []string{
|
|
|
|
"neo-go", "wallet", "nep11", "transfer",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
2022-02-04 16:18:35 +00:00
|
|
|
"--wallet", wall,
|
|
|
|
"--to", verifyH.StringLE(),
|
2022-10-05 06:44:10 +00:00
|
|
|
"--from", testcli.ValidatorAddr,
|
2022-02-04 16:18:35 +00:00
|
|
|
"--token", h.StringLE(),
|
|
|
|
"--id", hex.EncodeToString(token2ID),
|
|
|
|
"--amount", "0.25",
|
|
|
|
"--force",
|
|
|
|
"string:some_data",
|
|
|
|
}
|
2022-10-05 06:44:10 +00:00
|
|
|
e.In.WriteString(testcli.ValidatorPass + "\r")
|
2022-02-04 16:18:35 +00:00
|
|
|
e.Run(t, cmdTransfer...)
|
2022-10-05 06:44:10 +00:00
|
|
|
tx, _ := e.CheckTxPersisted(t)
|
2022-02-04 16:18:35 +00:00
|
|
|
// check OnNEP11Payment event
|
|
|
|
aer, err := e.Chain.GetAppExecResults(tx.Hash(), trigger.Application)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(aer[0].Events))
|
2022-10-05 06:44:10 +00:00
|
|
|
validatorHash, err := address.StringToUint160(testcli.ValidatorAddr)
|
2022-02-04 16:18:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, state.NotificationEvent{
|
|
|
|
ScriptHash: verifyH,
|
|
|
|
Name: "OnNEP11Payment",
|
|
|
|
Item: stackitem.NewArray([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(validatorHash.BytesBE()),
|
|
|
|
stackitem.NewBigInteger(big.NewInt(25)),
|
|
|
|
stackitem.NewByteArray(token2ID),
|
|
|
|
stackitem.NewByteArray([]byte("some_data")),
|
|
|
|
}),
|
|
|
|
}, aer[0].Events[1])
|
|
|
|
|
|
|
|
// check balance after transfer
|
|
|
|
e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...)
|
2022-08-29 19:39:13 +00:00
|
|
|
tokz[1].amount = "0.75"
|
2022-10-05 06:44:10 +00:00
|
|
|
checkBalanceResult(t, testcli.ValidatorAddr, tokz[1])
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func deployNFSContract(t *testing.T, e *testcli.Executor) util.Uint160 {
|
|
|
|
return testcli.DeployContract(t, e, "../../examples/nft-d/nft.go", "../../examples/nft-d/nft.yml", testcli.ValidatorWallet, testcli.ValidatorAddr, testcli.ValidatorPass)
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func deployNFTContract(t *testing.T, e *testcli.Executor) util.Uint160 {
|
|
|
|
return testcli.DeployContract(t, e, "../../examples/nft-nd/nft.go", "../../examples/nft-nd/nft.yml", nftOwnerWallet, nftOwnerAddr, nftOwnerPass)
|
2021-04-23 16:00:45 +00:00
|
|
|
}
|
2021-05-17 09:08:40 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func deployNNSContract(t *testing.T, e *testcli.Executor) util.Uint160 {
|
|
|
|
return testcli.DeployContract(t, e, "../../examples/nft-nd-nns/", "../../examples/nft-nd-nns/nns.yml", testcli.ValidatorWallet, testcli.ValidatorAddr, testcli.ValidatorPass)
|
2021-05-17 09:08:40 +00:00
|
|
|
}
|
2022-10-05 15:06:06 +00:00
|
|
|
|
|
|
|
func deployVerifyContract(t *testing.T, e *testcli.Executor) util.Uint160 {
|
|
|
|
return testcli.DeployContract(t, e, "../smartcontract/testdata/verify.go", "../smartcontract/testdata/verify.yml", testcli.ValidatorWallet, testcli.ValidatorAddr, testcli.ValidatorPass)
|
|
|
|
}
|