neo-go/pkg/crypto/keys/nep2_test.go
Roman Khimov b5b05a969c keys: make NEP2Decrypt return a PrivateKey rather than WIF
There is no point in encoding the output of this function in a WIF format,
most of the users actually want the real key and those who need a WIF can
easily get if from the key (and it's simpler than getting the key from the
WIF).

It also fixes a severe bug in NEP2Decrypt, base58 decoding errors were not
processed correctly.
2020-01-09 18:05:14 +03:00

45 lines
954 B
Go

package keys
import (
"testing"
"github.com/CityOfZion/neo-go/pkg/internal/keytestcases"
"github.com/stretchr/testify/assert"
)
func TestNEP2Encrypt(t *testing.T) {
for _, testCase := range keytestcases.Arr {
privKey, err := NewPrivateKeyFromHex(testCase.PrivateKey)
if testCase.Invalid {
assert.Error(t, err)
continue
}
assert.Nil(t, err)
encryptedWif, err := NEP2Encrypt(privKey, testCase.Passphrase)
assert.Nil(t, err)
assert.Equal(t, testCase.EncryptedWif, encryptedWif)
}
}
func TestNEP2Decrypt(t *testing.T) {
for _, testCase := range keytestcases.Arr {
privKey, err := NEP2Decrypt(testCase.EncryptedWif, testCase.Passphrase)
if testCase.Invalid {
assert.Error(t, err)
continue
}
assert.Nil(t, err)
assert.Equal(t, testCase.PrivateKey, privKey.String())
wif := privKey.WIF()
assert.Equal(t, testCase.Wif, wif)
address := privKey.Address()
assert.Equal(t, testCase.Address, address)
}
}