2018-12-05 11:30:13 +00:00
|
|
|
package wallet
|
|
|
|
|
2019-01-25 11:20:35 +00:00
|
|
|
import (
|
2018-12-05 11:30:13 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNEP2Encrypt(t *testing.T) {
|
|
|
|
for _, testCase := range testKeyCases {
|
|
|
|
|
|
|
|
privKey, err := NewPrivateKeyFromHex(testCase.privateKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
encryptedWif, err := NEP2Encrypt(privKey, testCase.passphrase)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-25 11:20:35 +00:00
|
|
|
if want, have := testCase.encryptedWif, encryptedWif; want != have {
|
2018-12-05 11:30:13 +00:00
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNEP2Decrypt(t *testing.T) {
|
|
|
|
for _, testCase := range testKeyCases {
|
|
|
|
|
|
|
|
privKeyString, err := NEP2Decrypt(testCase.encryptedWif, testCase.passphrase)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
privKey, err := NewPrivateKeyFromWIF(privKeyString)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if want, have := testCase.privateKey, privKey.String(); want != have {
|
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
|
|
|
|
|
|
|
wif, err := privKey.WIF()
|
2019-01-25 11:20:35 +00:00
|
|
|
if err != nil {
|
2018-12-05 11:30:13 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if want, have := testCase.wif, wif; want != have {
|
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
|
|
|
|
|
|
|
address, err := privKey.Address()
|
2019-01-25 11:20:35 +00:00
|
|
|
if err != nil {
|
2018-12-05 11:30:13 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if want, have := testCase.address, address; want != have {
|
|
|
|
t.Fatalf("expected %s got %s", want, have)
|
|
|
|
}
|
|
|
|
}
|
2019-01-25 11:20:35 +00:00
|
|
|
}
|