mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-26 19:43:48 +00:00
Fix NEP2Encrypt add Unit Tests (#108)
* fix NEP2 add unit tests * version update
This commit is contained in:
parent
e2f42e92a0
commit
5b57a10250
4 changed files with 66 additions and 6 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.45.11
|
||||
0.45.12
|
||||
|
|
|
@ -12,11 +12,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
errNoPath = errors.New("Target path where the wallet should be stored is mandatory and should be passed using (--path, -p) flags.")
|
||||
errPhraseMissmatch = errors.New("The entered passphrases do not match. Maybe you have misspelled them?")
|
||||
errNoPath = errors.New("target path where the wallet should be stored is mandatory and should be passed using (--path, -p) flags")
|
||||
errPhraseMismatch = errors.New("the entered pass-phrases do not match. Maybe you have misspelled them")
|
||||
)
|
||||
|
||||
// NewComand creates a new Wallet command.
|
||||
// NewCommand creates a new Wallet command.
|
||||
func NewCommand() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "wallet",
|
||||
|
@ -102,7 +102,7 @@ func createAccount(ctx *cli.Context, wall *wallet.Wallet) error {
|
|||
)
|
||||
|
||||
if phrase != phraseCheck {
|
||||
return errPhraseMissmatch
|
||||
return errPhraseMismatch
|
||||
}
|
||||
|
||||
return wall.CreateAccount(name, phrase)
|
||||
|
|
|
@ -58,7 +58,7 @@ func NEP2Encrypt(priv *PrivateKey, passphrase string) (s string, err error) {
|
|||
derivedKey2 := derivedKey[32:]
|
||||
xr := xor(priv.Bytes(), derivedKey1)
|
||||
|
||||
encrypted, err := crypto.AESEncrypt(derivedKey2, xr)
|
||||
encrypted, err := crypto.AESEncrypt(xr, derivedKey2)
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
|
|
60
pkg/wallet/nep2_test.go
Normal file
60
pkg/wallet/nep2_test.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package wallet
|
||||
|
||||
import(
|
||||
"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)
|
||||
}
|
||||
|
||||
if want, have:= testCase.encryptedWif, encryptedWif; want != have {
|
||||
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()
|
||||
if err != nil{
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want, have := testCase.wif, wif; want != have {
|
||||
t.Fatalf("expected %s got %s", want, have)
|
||||
}
|
||||
|
||||
address, err := privKey.Address()
|
||||
if err != nil{
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want, have := testCase.address, address; want != have {
|
||||
t.Fatalf("expected %s got %s", want, have)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue