package veto import ( "math/rand" "testing" "kesim.org/seal/curve" ) 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 = []*curve.Curve25519Point{} 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 = []*curve.Curve25519Point{} 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) } if vote.veto { t.Logf("Veto for index no. %d\n", i) } 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) if e != nil { t.Fatalf("Error calculating Round2 for [%d]: %v", i, e) } t.Logf("gcy[%d]: %v", i, gcy) gcys = append(gcys, gcy) } if !(points)(gcys).IsVetoed() { t.Fatalf("not vetoed, but should!") } }