aboutsummaryrefslogtreecommitdiff
path: root/commit_test.go
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2024-11-21 17:13:47 +0100
committerÖzgür Kesim <oec@codeblau.de>2024-11-21 17:13:47 +0100
commit0ada8c47427bfe604024d383ed7a250b04c82fee (patch)
tree4bc5e6432512a8060308413d303b675b0658bd1b /commit_test.go
parent32cee46e39527a09504615b822cc61969c46184d (diff)
refactor: lifted nizk/ up and awayHEADwip
Diffstat (limited to 'commit_test.go')
-rw-r--r--commit_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/commit_test.go b/commit_test.go
new file mode 100644
index 0000000..873061c
--- /dev/null
+++ b/commit_test.go
@@ -0,0 +1,57 @@
+package seal
+
+import (
+ "testing"
+
+ . "kesim.org/seal/common"
+)
+
+func TestStatement(t *testing.T) {
+ id := Curve.RandomScalar()
+
+ b1 := NewBit(id, true)
+ b2 := NewBit(id, false)
+
+ if !b1.Commitment.Verify(id, b1.Proof) {
+ t.Fatal("Could not verify st1 with c1, plus=true case")
+ }
+ if !b2.Commitment.Verify(id, b2.Proof) {
+ t.Fatal("Could not verify st2 with c2, plus=false case")
+ }
+
+ // Use the wrong proof
+ if b2.Commitment.Verify(id, b1.Proof) {
+ t.Fatal("Verify with wrong proof should have failed!")
+ }
+
+ // Use wrong id
+ x := Curve.RandomScalar()
+ if b1.Commitment.Verify(x, b1.Proof) || b2.Commitment.Verify(x, b2.Proof) {
+ t.Fatal("Verify with wrong id should have failed!")
+ }
+}
+
+func TestStatementFromScalar(t *testing.T) {
+ var α, β, id = Curve.RandomScalar(), Curve.RandomScalar(), Curve.RandomScalar()
+
+ b1 := NewBitFromScalars(id, true, α, β)
+ b2 := NewBitFromScalars(id, false, α, β)
+
+ if !b1.Commitment.Verify(id, b1.Proof) {
+ t.Fatal("Could not verify st1 with c1, plus=true case")
+ }
+ if !b2.Commitment.Verify(id, b2.Proof) {
+ t.Fatal("Could not verify st2 with c2, plus=false case")
+ }
+
+ // Use the wrong proof
+ if b2.Commitment.Verify(id, b1.Proof) {
+ t.Fatal("Verify with wrong proof should have failed!")
+ }
+
+ // Use the wrong Id
+ x := Curve.RandomScalar()
+ if b1.Commitment.Verify(x, b2.Proof) || b2.Commitment.Verify(x, b2.Proof) {
+ t.Fatal("Verify with wrong id should have failed!")
+ }
+}