neo-go/pkg/crypto/keys/nep2_test.go

51 lines
1 KiB
Go
Raw Normal View History

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)
2019-11-24 15:40:07 +00:00
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 {
privKeyString, err := NEP2Decrypt(testCase.EncryptedWif, testCase.Passphrase)
2019-11-24 15:40:07 +00:00
if testCase.Invalid {
assert.Error(t, err)
continue
}
assert.Nil(t, err)
privKey, err := NewPrivateKeyFromWIF(privKeyString)
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)
}
}