cli: add tests for wallet export

This commit is contained in:
Evgenii Stratonikov 2020-09-01 14:55:10 +03:00
parent 5d7f177811
commit 0a5fe84589
2 changed files with 34 additions and 1 deletions

View file

@ -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.

View file

@ -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))
})
}