diff options
Diffstat (limited to 'veto/veto_test.go')
-rw-r--r-- | veto/veto_test.go | 95 |
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 |