diff --git a/cli/nep11_test.go b/cli/nep11_test.go index 7a7b8ff1e..035561466 100644 --- a/cli/nep11_test.go +++ b/cli/nep11_test.go @@ -4,11 +4,13 @@ import ( "fmt" "io" "io/ioutil" + "math/big" "os" "path" "testing" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" @@ -267,16 +269,51 @@ func TestNEP11_OwnerOf_BalanceOf_Transfer(t *testing.T) { // transfer: no id specified e.In.WriteString(nftOwnerPass + "\r") e.RunWithError(t, cmdTransfer...) - cmdTransfer = append(cmdTransfer, "--id", string(tokenID)) // transfer: good e.In.WriteString(nftOwnerPass + "\r") - e.Run(t, cmdTransfer...) + e.Run(t, append(cmdTransfer, "--id", string(tokenID))...) e.checkTxPersisted(t) // check balance after transfer e.Run(t, append(cmdCheckBalance, "--token", h.StringLE())...) checkBalanceResult(t, nftOwnerAddr, "1") // tokenID1 + + // transfer: good, to NEP11-Payable contract, with data + verifyH := deployVerifyContract(t, e) + cmdTransfer = []string{ + "neo-go", "wallet", "nep11", "transfer", + "--rpc-endpoint", "http://" + e.RPC.Addr, + "--wallet", wall, + "--to", verifyH.StringLE(), + "--from", nftOwnerAddr, + "--token", h.StringLE(), + "--id", string(tokenID1), + "string:some_data", + } + e.In.WriteString(nftOwnerPass + "\r") + e.Run(t, cmdTransfer...) + tx, _ := e.checkTxPersisted(t) + // 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{ + stackitem.NewByteArray(nftOwnerHash.BytesBE()), + 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())...) + checkBalanceResult(t, nftOwnerAddr, "0") } func deployNFTContract(t *testing.T, e *executor) util.Uint160 { diff --git a/cli/nep17_test.go b/cli/nep17_test.go index 07a496a97..4a2a3f058 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -86,7 +86,7 @@ func TestNEP17Balance(t *testing.T) { } e.checkNextLine(t, "^\\s*$") - addr4, err := address.StringToUint160("NTe3yHH5zsaEGvEHTsFRpCjTef6Aod4yb6") // deployed verify.go contract + addr4, err := address.StringToUint160("NaZjSxmRZ4ErG2QEXCQMjjJfvAxMPiutmi") // deployed verify.go contract require.NoError(t, err) e.checkNextLine(t, "^Account "+address.Uint160ToString(addr4)) e.checkEOF(t) diff --git a/cli/testdata/verify.go b/cli/testdata/verify.go index 85e433920..0e6c51352 100644 --- a/cli/testdata/verify.go +++ b/cli/testdata/verify.go @@ -1,6 +1,9 @@ package testdata -import "github.com/nspcc-dev/neo-go/pkg/interop" +import ( + "github.com/nspcc-dev/neo-go/pkg/interop" + "github.com/nspcc-dev/neo-go/pkg/interop/runtime" +) func Verify() bool { return true @@ -8,3 +11,10 @@ func Verify() bool { func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { } + +// OnNEP11Payment notifies about NEP11 payment. You don't call this method directly, +// instead it's called by NEP11 contract when you transfer funds from your address +// to the address of this NFT contract. +func OnNEP11Payment(from interop.Hash160, amount int, token []byte, data interface{}) { + runtime.Notify("OnNEP11Payment", from, amount, token, data) +} diff --git a/cli/testdata/verify.yml b/cli/testdata/verify.yml index 8b39995ea..8d3cb83ad 100644 --- a/cli/testdata/verify.yml +++ b/cli/testdata/verify.yml @@ -1 +1,12 @@ name: Test verify +Events: + - name: OnNEP11Payment + parameters: + - name: from + type: Hash160 + - name: amount + type: Integer + - name: tokenId + type: ByteArray + - name: data + type: Any diff --git a/cli/testdata/wallet1_solo.json b/cli/testdata/wallet1_solo.json index bab9b7b66..92653b2b3 100644 --- a/cli/testdata/wallet1_solo.json +++ b/cli/testdata/wallet1_solo.json @@ -1,84 +1,84 @@ { - "version": "3.0", - "accounts": [ + "scrypt" : { + "r" : 8, + "p" : 8, + "n" : 16384 + }, + "version" : "3.0", + "accounts" : [ { - "address": "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", - "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", - "label": "", - "contract": { - "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", - "parameters": [ + "address" : "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo", + "label" : "", + "lock" : false, + "contract" : { + "parameters" : [ { - "name": "parameter0", - "type": "Signature" + "type" : "Signature", + "name" : "parameter0" } ], - "deployed": false + "script" : "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBdHR2qg==", + "deployed" : false }, - "lock": false, - "isdefault": true + "isdefault" : true, + "key" : "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL" }, { - "address": "NgEisvCqr2h8wpRxQb7bVPWUZdbVCY8Uo6", - "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", - "label": "", - "contract": { - "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl", - "parameters": [ + "label" : "", + "address" : "NgEisvCqr2h8wpRxQb7bVPWUZdbVCY8Uo6", + "isdefault" : false, + "key" : "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", + "contract" : { + "parameters" : [ { - "name": "parameter0", - "type": "Signature" + "name" : "parameter0", + "type" : "Signature" }, { - "name": "parameter1", - "type": "Signature" + "type" : "Signature", + "name" : "parameter1" }, { - "name": "parameter2", - "type": "Signature" + "type" : "Signature", + "name" : "parameter2" } ], - "deployed": false + "deployed" : false, + "script" : "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl" }, - "lock": false, - "isdefault": false + "lock" : false }, { - "address": "NNudMSGzEoktFzdYGYoNb3bzHzbmM1genF", - "key": "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL", - "label": "", - "contract": { - "script": "EQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CEUF7zmyl", - "parameters": [ - { - "name": "parameter0", - "type": "Signature" - } - ], - "deployed": false - }, - "lock": false, - "isdefault": false - }, - { - "address" : "NTe3yHH5zsaEGvEHTsFRpCjTef6Aod4yb6", - "key" : "6PYSgdjUPVjo3ZJLg2CsheXnEZzyvUuSm4jCtXP6X7FT82sAQHWt2wpu5A", + "address" : "NNudMSGzEoktFzdYGYoNb3bzHzbmM1genF", "label" : "", "contract" : { - "script" : "VwEAEdsgQFcAA0A=", - "deployed" : true, - "parameters" : [] + "parameters" : [ + { + "name" : "parameter0", + "type" : "Signature" + } + ], + "deployed" : false, + "script" : "EQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CEUF7zmyl" }, "lock" : false, - "isdefault" : false + "isdefault" : false, + "key" : "6PYL8Gnjsz4RBKX18jx5ZAQTDH7PKkZwEVjPKEkjNzCDNFE6TKZwaFLibL" + }, + { + "contract" : { + "parameters" : [], + "script" : "VwEAEdsgQFcAA0BXAQR4eXp7VBTAcAwOT25ORVAxMVBheW1lbnRoUEGVAW9hIUA=", + "deployed" : true + }, + "lock" : false, + "isdefault" : false, + "key" : "6PYVxVpeNjxGDFTTG61ARGy6mCz6fQsGm9qW2tsFW3ox1zM6KpCoWSE4PB", + "address" : "NaZjSxmRZ4ErG2QEXCQMjjJfvAxMPiutmi", + "label" : "acc" } ], - "scrypt": { - "n": 16384, - "r": 8, - "p": 8 - }, - "extra": { - "Tokens": null + "extra" : { + "Tokens" : null } -} +} \ No newline at end of file diff --git a/cli/wallet/nep11.go b/cli/wallet/nep11.go index ee20157b7..322cbc6d0 100644 --- a/cli/wallet/nep11.go +++ b/cli/wallet/nep11.go @@ -80,7 +80,7 @@ func newNEP11Commands() []cli.Command { { Name: "transfer", Usage: "transfer NEP11 tokens", - UsageText: "transfer --wallet --rpc-endpoint --timeout