neo-go/pkg/wallet/account_test.go
Anthony De Meulemeester f3f6662fc9
Base wallet implementation (#35)
* Initial draft of the neo-go wallet

* Cleanup + more test for util package

* integrated wallet into neo-cli partially

* base wallet implementation + smartcontract code.
2018-03-02 16:24:09 +01:00

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