aboutsummaryrefslogtreecommitdiff
path: root/veto/veto_test.go
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2024-03-20 22:24:18 +0100
committerÖzgür Kesim <oec@codeblau.de>2024-03-20 22:24:18 +0100
commit6017ace9301d0078e34bdbb3b29ef71e4ba408a5 (patch)
tree137b96ea2db013120287d5dab29992d336c99701 /veto/veto_test.go
parent60f58c25788c273caddd36dfc3bce44757170a67 (diff)
veto: commitment(round1), round2 and veto check implemented
The core elements to resemble the calculation of the AV-net protocol is ready, Votes generate Commitments, calculate the Proofs for the X's, R's, calculate the data for round2 and calculate the final vote, according to the paper.
Diffstat (limited to 'veto/veto_test.go')
-rw-r--r--veto/veto_test.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/veto/veto_test.go b/veto/veto_test.go
new file mode 100644
index 0000000..847c7a0
--- /dev/null
+++ b/veto/veto_test.go
@@ -0,0 +1,95 @@
+package veto
+
+import (
+ "math/rand"
+ "testing"
+)
+
+func TestVoteGeneration(t *testing.T) {
+
+ for i := range 100 {
+ veto := i%3 == 1
+ vote, e := newVoteWithRand(veto, nil)
+
+ if e != nil {
+ t.Fatalf("unexpected error: %v", e)
+ }
+ if vote.veto != veto {
+ t.Fatalf("expected veto %t, but got %t", veto, vote.veto)
+ }
+ com := vote.Commitment()
+ if !com.VerifyProofs() {
+ t.Fatalf("Proofs not correct! %+v", com)
+ }
+ }
+}
+
+func TestRound2NoVeto(t *testing.T) {
+ var (
+ vs = []*Vote{}
+ cs = []*Commitment{}
+ gcys = []*point{}
+ num = 100
+ )
+ for i := range num {
+ vote, e := newVoteWithRand(false, nil)
+
+ if e != nil {
+ t.Fatalf("unexpected error: %v", e)
+ }
+ com := vote.Commitment()
+ if !com.VerifyProofs() {
+ t.Fatalf("Proofs not correct for %d! %+v", i, com)
+ }
+ vs = append(vs, vote)
+ cs = append(cs, com)
+ }
+
+ for i := range num {
+ gcy, e := vs[i].Round2(cs)
+ t.Logf("gcy: %v, e: %v", gcy, e)
+ if e != nil {
+ t.Fatalf("Error calculating Round2: %v", e)
+ }
+ gcys = append(gcys, gcy)
+ }
+
+ if (points)(gcys).IsVetoed() {
+ t.Fatalf("veto expected, but got didn't")
+ }
+}
+
+func TestRound2WithVeto(t *testing.T) {
+ var (
+ vs = []*Vote{}
+ cs = []*Commitment{}
+ gcys = []*point{}
+ num = 100
+ index = int(rand.Int31n(int32(num)))
+ )
+ for i := range num {
+ vote, e := newVoteWithRand(i == index, nil)
+ if e != nil {
+ t.Fatalf("unexpected error: %v", e)
+ }
+ com := vote.Commitment()
+ if !com.VerifyProofs() {
+ t.Fatalf("Proofs not correct for %d! %+v", i, com)
+ }
+ vs = append(vs, vote)
+ cs = append(cs, com)
+ }
+
+ for i := range num {
+ gcy, e := vs[i].Round2(cs)
+ t.Logf("gcy: %v, e: %v", gcy, e)
+ if e != nil {
+ t.Fatalf("Error calculating Round2: %v", e)
+ }
+ gcys = append(gcys, gcy)
+ }
+
+ if !(points)(gcys).IsVetoed() {
+ t.Fatalf("not vetoed, but should!")
+ }
+} \ No newline at end of file