From 0a5fe8458901969db24c781ab63a208642011ab5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 1 Sep 2020 14:55:10 +0300 Subject: [PATCH] cli: add tests for `wallet export` --- cli/executor_test.go | 7 ++++++- cli/wallet_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cli/executor_test.go b/cli/executor_test.go index 142cfce3d..3fe1347c6 100644 --- a/cli/executor_test.go +++ b/cli/executor_test.go @@ -14,6 +14,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/network" "github.com/nspcc-dev/neo-go/pkg/rpc/server" @@ -26,12 +27,16 @@ import ( ) const ( + validatorWIF = "KxyjQ8eUa4FHt3Gvioyt1Wz29cTUrE4eTqX3yFSk1YFCsPL8uNsY" validatorAddr = "NVNvVRW5Q5naSx2k2iZm7xRgtRNGuZppAK" validatorWallet = "testdata/wallet1_solo.json" ) -var validatorHash, _ = address.StringToUint160(validatorAddr) +var ( + validatorHash, _ = address.StringToUint160(validatorAddr) + validatorPriv, _ = keys.NewPrivateKeyFromWIF(validatorWIF) +) // executor represents context for a test instance. // It can be safely used in multiple tests, but not in parallel. diff --git a/cli/wallet_test.go b/cli/wallet_test.go index 2a57a2fdf..2e80f7e53 100644 --- a/cli/wallet_test.go +++ b/cli/wallet_test.go @@ -3,6 +3,7 @@ package main import ( "os" "path" + "strings" "testing" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -83,3 +84,30 @@ func TestWalletInit(t *testing.T) { }) }) } + +func TestWalletExport(t *testing.T) { + e := newExecutor(t, false) + defer e.Close(t) + + t.Run("Encrypted", func(t *testing.T) { + e.Run(t, "neo-go", "wallet", "export", + "--wallet", validatorWallet, validatorAddr) + line, err := e.Out.ReadString('\n') + require.NoError(t, err) + enc, err := keys.NEP2Encrypt(validatorPriv, "one") + require.NoError(t, err) + require.Equal(t, enc, strings.TrimSpace(line)) + }) + t.Run("Decrypted", func(t *testing.T) { + t.Run("NoAddress", func(t *testing.T) { + e.RunWithError(t, "neo-go", "wallet", "export", + "--wallet", validatorWallet, "--decrypt") + }) + e.In.WriteString("one\r") + e.Run(t, "neo-go", "wallet", "export", + "--wallet", validatorWallet, "--decrypt", validatorAddr) + line, err := e.Out.ReadString('\n') + require.NoError(t, err) + require.Equal(t, validatorWIF, strings.TrimSpace(line)) + }) +}