2019-08-27 13:29:42 +00:00
|
|
|
package keys
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-01-25 11:20:35 +00:00
|
|
|
import (
|
2018-12-05 11:30:13 +00:00
|
|
|
"testing"
|
2019-08-27 13:29:42 +00:00
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/internal/keytestcases"
|
2019-08-27 14:06:32 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-12-05 11:30:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNEP2Encrypt(t *testing.T) {
|
2019-08-27 13:29:42 +00:00
|
|
|
for _, testCase := range keytestcases.Arr {
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-08-27 13:29:42 +00:00
|
|
|
privKey, err := NewPrivateKeyFromHex(testCase.PrivateKey)
|
2019-11-24 15:40:07 +00:00
|
|
|
if testCase.Invalid {
|
|
|
|
assert.Error(t, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Nil(t, err)
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-08-27 13:29:42 +00:00
|
|
|
encryptedWif, err := NEP2Encrypt(privKey, testCase.Passphrase)
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Nil(t, err)
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Equal(t, testCase.EncryptedWif, encryptedWif)
|
2018-12-05 11:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNEP2Decrypt(t *testing.T) {
|
2019-08-27 13:29:42 +00:00
|
|
|
for _, testCase := range keytestcases.Arr {
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-08-27 13:29:42 +00:00
|
|
|
privKeyString, err := NEP2Decrypt(testCase.EncryptedWif, testCase.Passphrase)
|
2019-11-24 15:40:07 +00:00
|
|
|
if testCase.Invalid {
|
|
|
|
assert.Error(t, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Nil(t, err)
|
2018-12-05 11:30:13 +00:00
|
|
|
|
|
|
|
privKey, err := NewPrivateKeyFromWIF(privKeyString)
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Nil(t, err)
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Equal(t, testCase.PrivateKey, privKey.String())
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-09-05 06:35:02 +00:00
|
|
|
wif := privKey.WIF()
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Equal(t, testCase.Wif, wif)
|
2018-12-05 11:30:13 +00:00
|
|
|
|
2019-09-05 06:35:02 +00:00
|
|
|
address := privKey.Address()
|
2019-08-27 14:06:32 +00:00
|
|
|
assert.Equal(t, testCase.Address, address)
|
2018-12-05 11:30:13 +00:00
|
|
|
}
|
2019-01-25 11:20:35 +00:00
|
|
|
}
|