Skip to content
Snippets Groups Projects
Commit c31182f4 authored by Ben Adida's avatar Ben Adida
Browse files

full election test now working all the way to the result, which is not being saved properly.

parent 87a8a6d9
No related branches found
No related tags found
No related merge requests found
......@@ -71,7 +71,7 @@ class KeyPair(object):
self.sk.x = Utils.random_mpz_lt(p)
self.pk.y = pow(g, self.sk.x, p)
self.sk.pk = self.pk
self.sk.public_key = self.pk
class PublicKey:
def __init__(self):
......@@ -148,11 +148,11 @@ class PublicKey:
class SecretKey:
def __init__(self):
self.x = None
self.pk = None
self.public_key = None
@property
def public_key(self):
return self.pk
def pk(self):
return self.public_key
def decryption_factor(self, ciphertext):
"""
......
......@@ -194,6 +194,10 @@ class Questions(LegacyObject):
class Tally(LegacyObject):
WRAPPED_OBJ_CLASS = homomorphic.Tally
FIELDS = ['tally', 'num_tallied']
STRUCTURED_FIELDS = {
'tally': arrayOf(arrayOf('legacy/EGCiphertext'))}
class Eligibility(LegacyObject):
pass
......@@ -19,6 +19,7 @@ import helios
from helios import datatypes
# useful stuff in auth
from auth.models import User, AUTH_SYSTEMS
from auth.jsonfield import JSONField
......@@ -443,7 +444,9 @@ class Election(HeliosModel):
return helios.get_election_url(self)
def init_tally(self):
return Tally(election=self)
# FIXME: create the right kind of tally
from helios.workflows import homomorphic
return homomorphic.Tally(election=self)
@property
def registration_status_pretty(self):
......
......@@ -97,7 +97,6 @@ The encrypted tally for election %s has been computed.
Helios
""" % election.name)
if election.has_helios_trustee():
tally_helios_decrypt.delay(election_id = election.id)
......
......@@ -455,9 +455,23 @@ class ElectionBlackboxTests(TestCase):
self.assertRedirects(response, "%s/helios/elections/%s/cast_done" % (settings.URL_HOST, election_id))
# encrypted tally
response = self.client.post("/helios/elections/%s/compute_tally" % election_id, {
"csrf_token" : self.client.session['csrf_token']
})
self.assertRedirects(response, "/helios/elections/%s/view" % election_id)
# should trigger helios decryption automatically
self.assertNotEquals(models.Election.objects.get(uuid=election_id).get_helios_trustee().decryption_proofs, None)
# combine decryptions
response = self.client.post("/helios/elections/%s/combine_decryptions" % election_id, {
"csrf_token" : self.client.session['csrf_token'],
"subject" : "tally subject",
"body" : "tally body",
"send_to" : "all"
})
self.assertRedirects(response, "/helios/elections/%s/view" % election_id)
# check that tally matches
response = self.client.get("/helios/elections/%s/result" % election_id)
self.assertEquals(utils.from_json(response.content), [0,1])
......@@ -325,25 +325,27 @@ class Tally(WorkflowObject):
"""
def __init__(self, *args, **kwargs):
super(Tally, self).__init__(*args, **kwargs)
super(Tally, self).__init__()
self.election = kwargs.get('election',None)
election = kwargs.get('election',None)
self.tally = None
self.num_tallied = 0
if self.election:
self.init_election(self.election)
if election:
self.init_election(election)
self.tally = [[0 for a in q['answers']] for q in self.questions]
else:
self.questions = None
self.public_key = None
self.tally = None
def init_election(self, election):
"""
given the election, initialize some params
"""
self.election = election
self.questions = election.questions
self.public_key = election.public_key
self.tally = [[0 for a in q['answers']] for q in self.questions]
def add_vote_batch(self, encrypted_votes, verify_p=True):
"""
......@@ -393,8 +395,8 @@ class Tally(WorkflowObject):
# look up appropriate discrete log
# this is the string conversion
question_factors.append(str(dec_factor))
question_proof.append(proof.toJSONDict())
question_factors.append(dec_factor)
question_proof.append(proof)
decryption_factors.append(question_factors)
decryption_proof.append(question_proof)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment