2018-03-02 15:24:09 +00:00
|
|
|
package wallet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"testing"
|
2019-08-27 13:29:42 +00:00
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/internal/keytestcases"
|
2018-03-02 15:24:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewAccount(t *testing.T) {
|
2019-08-27 13:29:42 +00:00
|
|
|
for _, testCase := range keytestcases.Arr {
|
|
|
|
acc, err := NewAccountFromWIF(testCase.Wif)
|
2018-03-02 15:24:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
compareFields(t, testCase, acc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDecryptAccount(t *testing.T) {
|
2019-08-27 13:29:42 +00:00
|
|
|
for _, testCase := range keytestcases.Arr {
|
|
|
|
acc, err := DecryptAccount(testCase.EncryptedWif, testCase.Passphrase)
|
2018-03-02 15:24:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
compareFields(t, testCase, acc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewFromWif(t *testing.T) {
|
2019-08-27 13:29:42 +00:00
|
|
|
for _, testCase := range keytestcases.Arr {
|
|
|
|
acc, err := NewAccountFromWIF(testCase.Wif)
|
2018-03-02 15:24:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
compareFields(t, testCase, acc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 13:29:42 +00:00
|
|
|
func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) {
|
|
|
|
if want, have := tk.Address, acc.Address; want != have {
|
2018-03-02 15:24:09 +00:00
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
2019-08-27 13:29:42 +00:00
|
|
|
if want, have := tk.Wif, acc.wif; want != have {
|
2018-03-02 15:24:09 +00:00
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
2019-08-27 13:29:42 +00:00
|
|
|
if want, have := tk.PublicKey, hex.EncodeToString(acc.publicKey); want != have {
|
2018-03-02 15:24:09 +00:00
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
2019-08-27 13:29:42 +00:00
|
|
|
if want, have := tk.PrivateKey, acc.privateKey.String(); want != have {
|
2018-03-02 15:24:09 +00:00
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
|
|
|
}
|