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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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!")
}
}
|