github.com/Evanesco-Labs/go-evanesco@v1.0.1/zkpminer/vrf/vrf_test.go (about) 1 package vrf 2 3 import ( 4 "crypto/ecdsa" 5 "crypto/elliptic" 6 "crypto/rand" 7 "github.com/Evanesco-Labs/go-evanesco/zkpminer/keypair" 8 "github.com/stretchr/testify/assert" 9 "testing" 10 ) 11 12 func TestECMarshall(t *testing.T) { 13 key, err := ecdsa.GenerateKey(keypair.Curve, rand.Reader) 14 if err != nil { 15 t.Fatal(err) 16 } 17 18 privateKey, err := keypair.NewPrivateKey(key) 19 if err != nil { 20 t.Fatal(err) 21 } 22 23 privBytes := elliptic.Marshal(keypair.Curve, privateKey.X, privateKey.Y) 24 25 x, y := elliptic.Unmarshal(keypair.Curve, privBytes) 26 if x == nil || y == nil { 27 t.Fatal("nil") 28 } 29 30 assert.Equal(t, privateKey.X.Cmp(x), 0) 31 assert.Equal(t, privateKey.Y.Cmp(y), 0) 32 } 33 34 func TestVrf(t *testing.T) { 35 _, key := keypair.GenerateKeyPair() 36 privateKey, err := keypair.NewPrivateKey(key.PrivateKey) 37 if err != nil { 38 t.Fatal(err) 39 } 40 41 publicKey, err := keypair.NewPublicKey(&key.PublicKey) 42 43 message := []byte("go evanesco") 44 rExp, proof := Evaluate(privateKey, message) 45 46 if proof == nil { 47 t.Fatalf("Evaluate fatal") 48 } 49 50 r, err := ProofToHash(publicKey, message, proof) 51 if err != nil { 52 t.Fatal(err) 53 } 54 55 assert.Equal(t, rExp, r, "Vrf hash should be the same.") 56 }