mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
b77e533d13
And drop associated _pkg.dev remnants (refs. #307). Original `dev` branch had two separate packages for public and private keys, but those are so intertwined (`TestHelper` subpackage is a proof) that it's better unite them and all associated code (like WIF and NEP-2) in one package. This patch also: * creates internal `keytestcases` package to share things with wallet (maybe it'll be changed in some future) * ports some tests from `dev` * ports Verify() method for public key from `dev` * expands TestPrivateKey() with public key check
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package wallet
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/internal/keytestcases"
|
|
)
|
|
|
|
func TestNewAccount(t *testing.T) {
|
|
for _, testCase := range keytestcases.Arr {
|
|
acc, err := NewAccountFromWIF(testCase.Wif)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compareFields(t, testCase, acc)
|
|
}
|
|
}
|
|
|
|
func TestDecryptAccount(t *testing.T) {
|
|
for _, testCase := range keytestcases.Arr {
|
|
acc, err := DecryptAccount(testCase.EncryptedWif, testCase.Passphrase)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compareFields(t, testCase, acc)
|
|
}
|
|
}
|
|
|
|
func TestNewFromWif(t *testing.T) {
|
|
for _, testCase := range keytestcases.Arr {
|
|
acc, err := NewAccountFromWIF(testCase.Wif)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compareFields(t, testCase, acc)
|
|
}
|
|
}
|
|
|
|
func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) {
|
|
if want, have := tk.Address, acc.Address; want != have {
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
}
|
|
if want, have := tk.Wif, acc.wif; want != have {
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
}
|
|
if want, have := tk.PublicKey, hex.EncodeToString(acc.publicKey); want != have {
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
}
|
|
if want, have := tk.PrivateKey, acc.privateKey.String(); want != have {
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
}
|
|
}
|