From f848783d5de628f9dd198f518d8105b1da8124ea Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 21 Apr 2021 12:50:04 +0300 Subject: [PATCH] cli: allow to provide cosigners for 'wallet nep17 transfer' --- cli/contract_test.go | 45 +++++++++++++++++++++++++++----------------- cli/nep17_test.go | 42 ++++++++++++++++++++++++++++++----------- cli/wallet/nep17.go | 35 +++++++++++++++++++++------------- 3 files changed, 81 insertions(+), 41 deletions(-) diff --git a/cli/contract_test.go b/cli/contract_test.go index 5e9202c9e..17f7fec96 100644 --- a/cli/contract_test.go +++ b/cli/contract_test.go @@ -226,6 +226,33 @@ func TestContractDeployWithData(t *testing.T) { require.Equal(t, []byte("take_me_to_church"), res.Stack[0].Value()) } +func deployVerifyContract(t *testing.T, e *executor) util.Uint160 { + tmpDir := path.Join(os.TempDir(), "neogo.test.deployverifycontract") + require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) + t.Cleanup(func() { + os.RemoveAll(tmpDir) + }) + // deploy verification contract + nefName := path.Join(tmpDir, "verify.nef") + manifestName := path.Join(tmpDir, "verify.manifest.json") + e.Run(t, "neo-go", "contract", "compile", + "--in", "testdata/verify.go", + "--config", "testdata/verify.yml", + "--out", nefName, "--manifest", manifestName) + e.In.WriteString("one\r") + e.Run(t, "neo-go", "contract", "deploy", + "--rpc-endpoint", "http://"+e.RPC.Addr, + "--wallet", validatorWallet, "--address", validatorAddr, + "--in", nefName, "--manifest", manifestName) + line, err := e.Out.ReadString('\n') + require.NoError(t, err) + line = strings.TrimSpace(strings.TrimPrefix(line, "Contract: ")) + hVerify, err := util.Uint160DecodeStringLE(line) + require.NoError(t, err) + e.checkTxPersisted(t) + return hVerify +} + func TestComlileAndInvokeFunction(t *testing.T) { e := newExecutor(t, true) @@ -315,23 +342,7 @@ func TestComlileAndInvokeFunction(t *testing.T) { require.Equal(t, []byte("on create|sub create"), res.Stack[0].Value()) // deploy verification contract - nefName = path.Join(tmpDir, "verify.nef") - manifestName = path.Join(tmpDir, "verify.manifest.json") - e.Run(t, "neo-go", "contract", "compile", - "--in", "testdata/verify.go", - "--config", "testdata/verify.yml", - "--out", nefName, "--manifest", manifestName) - e.In.WriteString("one\r") - e.Run(t, "neo-go", "contract", "deploy", - "--rpc-endpoint", "http://"+e.RPC.Addr, - "--wallet", validatorWallet, "--address", validatorAddr, - "--in", nefName, "--manifest", manifestName) - line, err = e.Out.ReadString('\n') - require.NoError(t, err) - line = strings.TrimSpace(strings.TrimPrefix(line, "Contract: ")) - hVerify, err := util.Uint160DecodeStringLE(line) - require.NoError(t, err) - e.checkTxPersisted(t) + hVerify := deployVerifyContract(t, e) t.Run("real invoke", func(t *testing.T) { cmd := []string{"neo-go", "contract", "invokefunction", diff --git a/cli/nep17_test.go b/cli/nep17_test.go index e74b1563e..8226b8bb6 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -132,6 +132,8 @@ func TestNEP17Transfer(t *testing.T) { b, _ := e.Chain.GetGoverningTokenBalance(sh) require.Equal(t, big.NewInt(1), b) + hVerify := deployVerifyContract(t, e) + t.Run("default address", func(t *testing.T) { const validatorDefault = "NTh9TnZTstvAePEYWDGLLxidBikJE24uTo" e.In.WriteString("one\r") @@ -159,21 +161,39 @@ func TestNEP17Transfer(t *testing.T) { require.Equal(t, big.NewInt(41), b) }) + validTil := e.Chain.BlockHeight() + 100 + cmd := []string{ + "neo-go", "wallet", "nep17", "transfer", + "--rpc-endpoint", "http://" + e.RPC.Addr, + "--wallet", validatorWallet, + "--to", address.Uint160ToString(e.Chain.GetNotaryContractScriptHash()), + "--token", "GAS", + "--amount", "1", + "--from", validatorAddr, + "[", validatorAddr, strconv.Itoa(int(validTil)), "]"} + t.Run("with data", func(t *testing.T) { e.In.WriteString("one\r") - validTil := e.Chain.BlockHeight() + 100 - e.Run(t, []string{ - "neo-go", "wallet", "nep17", "transfer", - "--rpc-endpoint", "http://" + e.RPC.Addr, - "--wallet", validatorWallet, - "--to", address.Uint160ToString(e.Chain.GetNotaryContractScriptHash()), - "--token", "GAS", - "--amount", "1", - "--from", validatorAddr, - "[", validatorAddr, strconv.Itoa(int(validTil)), "]", - }...) + e.Run(t, cmd...) e.checkTxPersisted(t) }) + + 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") + e.RunWithError(t, append(cmd, "--", validatorAddr+":None")...) + }) + t.Run("good", func(t *testing.T) { + e.In.WriteString("one\r") + e.Run(t, append(cmd, "--", validatorAddr+":Global")...) // CalledByEntry is enough, but it's the default value, so check something else + e.checkTxPersisted(t) + }) + t.Run("several signers", func(t *testing.T) { + e.In.WriteString("one\r") + e.Run(t, append(cmd, "--", validatorAddr, hVerify.StringLE())...) + e.checkTxPersisted(t) + }) + }) } func TestNEP17MultiTransfer(t *testing.T) { diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index f23b89f5a..88f90c108 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -112,12 +112,15 @@ func newNEP17Commands() []cli.Command { { Name: "transfer", Usage: "transfer NEP17 tokens", - UsageText: "transfer --wallet --rpc-endpoint --timeout