mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
f3f6662fc9
* Initial draft of the neo-go wallet * Cleanup + more test for util package * integrated wallet into neo-cli partially * base wallet implementation + smartcontract code.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package wallet
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewAccount(t *testing.T) {
|
|
for _, testCase := range testKeyCases {
|
|
acc, err := NewAccountFromWIF(testCase.wif)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compareFields(t, testCase, acc)
|
|
}
|
|
}
|
|
|
|
func TestDecryptAccount(t *testing.T) {
|
|
for _, testCase := range testKeyCases {
|
|
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 testKeyCases {
|
|
acc, err := NewAccountFromWIF(testCase.wif)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compareFields(t, testCase, acc)
|
|
}
|
|
}
|
|
|
|
func compareFields(t *testing.T, tk testKey, 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)
|
|
}
|
|
}
|