Merge pull request #208 from harmony-one/crypto-unit-test

add unit test for crypto/pki/utils.go
pull/211/head
chaosma 6 years ago committed by GitHub
commit 4ccb7ae019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      crypto/pki/utils_test.go

@ -0,0 +1,25 @@
package pki
import (
"github.com/harmony-one/harmony/crypto"
"reflect"
"testing"
"time"
)
func TestGetPublicKeyFromPrivateKey(test *testing.T) {
suite := crypto.Ed25519Curve
t := time.Now().UnixNano()
scalar := suite.Scalar().SetInt64(t)
pubKey := GetPublicKeyFromScalar(scalar)
bytes := [32]byte{}
tmp, err := scalar.MarshalBinary()
copy(bytes[:], tmp)
if err != nil {
test.Error("unable to marshal private key to binary")
}
pubKey1 := GetPublicKeyFromPrivateKey(bytes)
if !reflect.DeepEqual(pubKey, pubKey1) {
test.Error("two public keys should be equal")
}
}
Loading…
Cancel
Save