-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserde_test.go
48 lines (39 loc) · 1.66 KB
/
serde_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package dleq
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/athanorlabs/go-dleq/ed25519"
"github.com/athanorlabs/go-dleq/secp256k1"
)
func TestProof_Serde(t *testing.T) {
curveA := secp256k1.NewCurve()
curveB := ed25519.NewCurve()
x, err := GenerateSecretForCurves(curveA, curveB)
require.NoError(t, err)
proof, err := NewProof(curveA, curveB, x)
require.NoError(t, err)
err = proof.Verify(curveA, curveB)
require.NoError(t, err)
ser := proof.Serialize()
deser := new(Proof)
err = deser.Deserialize(curveA, curveB, ser)
require.NoError(t, err)
require.Equal(t, proof.CommitmentA, deser.CommitmentA)
require.True(t, proof.CommitmentB.Equals(deser.CommitmentB))
require.Equal(t, len(proof.proofs), len(deser.proofs))
for i := range proof.proofs {
require.Equal(t, proof.proofs[i].commitmentA.commitment, deser.proofs[i].commitmentA.commitment)
require.True(t, proof.proofs[i].commitmentB.commitment.Equals(deser.proofs[i].commitmentB.commitment))
require.Equal(t, proof.proofs[i].ringSig.eCurveA, deser.proofs[i].ringSig.eCurveA)
require.Equal(t, proof.proofs[i].ringSig.eCurveB, deser.proofs[i].ringSig.eCurveB)
require.Equal(t, proof.proofs[i].ringSig.a0, deser.proofs[i].ringSig.a0)
require.Equal(t, proof.proofs[i].ringSig.a1, deser.proofs[i].ringSig.a1)
require.Equal(t, proof.proofs[i].ringSig.b0, deser.proofs[i].ringSig.b0)
require.Equal(t, proof.proofs[i].ringSig.b1, deser.proofs[i].ringSig.b1)
}
require.Equal(t, proof.signatureA, deser.signatureA)
require.Equal(t, proof.signatureB, deser.signatureB)
err = deser.Verify(curveA, curveB)
require.NoError(t, err)
t.Logf("size of serialized proof: %d bytes", len(ser))
}