aboutsummaryrefslogtreecommitdiff
path: root/src/test/python
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2014-03-30 21:41:58 +0000
committerFlorian Dold <florian.dold@gmail.com>2014-03-30 21:41:58 +0000
commit9f10abfdc35d8f189a8e0a77a389799ca6b7f9e5 (patch)
tree39d855abacebeaa45752e4abc5b4a660d2603d70 /src/test/python
parent1fbef203844b19f8141bddcba20a977de34b211e (diff)
downloadgnunet-java-9f10abfdc35d8f189a8e0a77a389799ca6b7f9e5.tar.gz
gnunet-java-9f10abfdc35d8f189a8e0a77a389799ca6b7f9e5.zip
- fix election crypto
- multi-way elections - high-level signature containers - fix bug in mesh test case - fix bug in Strings.java - ivy repo
Diffstat (limited to 'src/test/python')
-rw-r--r--src/test/python/test_voting_single.py51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/test/python/test_voting_single.py b/src/test/python/test_voting_single.py
index ad90519..220492c 100644
--- a/src/test/python/test_voting_single.py
+++ b/src/test/python/test_voting_single.py
@@ -4,10 +4,12 @@ Test the voting implementation with a single authority.
4import os 4import os
5import subprocess 5import subprocess
6import time 6import time
7import random
8import shutil
7 9
8 10
9NUM_AUTHORITIES = 1 11NUM_AUTHORITIES = 1
10NUM_VOTERS = 1 12NUM_VOTERS = 5
11 13
12 14
13def wait_for_after(ts): 15def wait_for_after(ts):
@@ -15,6 +17,8 @@ def wait_for_after(ts):
15 if now < ts: 17 if now < ts:
16 print "waiting", ts - now, "seconds" 18 print "waiting", ts - now, "seconds"
17 time.sleep(ts - now) 19 time.sleep(ts - now)
20 else:
21 print "not waiting"
18 22
19def get_config(section, option, filename=None, expand=False): 23def get_config(section, option, filename=None, expand=False):
20 args = ["gnunet-config"] 24 args = ["gnunet-config"]
@@ -75,7 +79,9 @@ public_key = subprocess.check_output(["gnunet-ecc", "--print-public-key", privat
75 79
76print "public key", public_key 80print "public key", public_key
77 81
78create_identity("voter0", conf[0]) 82for vi in range(NUM_VOTERS):
83 create_identity("voter"+str(vi), conf[0])
84
79create_identity("issuer", conf[0]) 85create_identity("issuer", conf[0])
80create_identity("groupca", conf[0]) 86create_identity("groupca", conf[0])
81 87
@@ -89,15 +95,15 @@ TS_KEYGEN_END = now + 10
89TS_START = now + 15 95TS_START = now + 15
90TS_CLOSING = now + 20 96TS_CLOSING = now + 20
91TS_CONCLUDE = now + 25 97TS_CONCLUDE = now + 25
92TS_QUERY = now + 30 98TS_QUERY = now + 35
93TS_END = now + 35 99TS_END = now + 40
94 100
95ballot.write("[authorities]\n") 101ballot.write("[authorities]\n")
96ballot.write("auth0 = %s\n" % public_key) 102ballot.write("auth0 = %s\n" % public_key)
97ballot.write("[election]\n") 103ballot.write("[election]\n")
98ballot.write("TOPIC = mytopic\n") 104ballot.write("TOPIC = mytopic\n")
99ballot.write("THRESHOLD = 1\n") 105ballot.write("THRESHOLD = 1\n")
100ballot.write("CHOICES = yes//no\n") 106ballot.write("CHOICES = yes//no//maybe\n")
101ballot.write("GROUP = mygroup\n") 107ballot.write("GROUP = mygroup\n")
102ballot.write("CA_PUB = %s\n" % get_identity_pubkey("groupca", conf[0])) 108ballot.write("CA_PUB = %s\n" % get_identity_pubkey("groupca", conf[0]))
103ballot.write("TIMESTAMP_KEYGEN_START = %s\n" % TS_KEYGEN_START) 109ballot.write("TIMESTAMP_KEYGEN_START = %s\n" % TS_KEYGEN_START)
@@ -110,15 +116,17 @@ ballot.write("TIMESTAMP_END = %s\n" % TS_END)
110 116
111ballot.close() 117ballot.close()
112 118
113groupcert_filename = os.path.join(testdir, "v0-cert") 119# create group certs for all voters
114groupcert_file = open(groupcert_filename, "w") 120for vi in range(NUM_VOTERS):
121 groupcert_filename = os.path.join(testdir, "v"+str(vi)+"-cert")
122 groupcert_file = open(groupcert_filename, "w")
115 123
116v0_pub = get_identity_pubkey("voter0", conf[0]) 124 v_pub = get_identity_pubkey("voter"+str(vi), conf[0])
117 125
118subprocess.check_call(["gnunet-ballot-group-certify", "-c", conf[0], 126 subprocess.check_call(["gnunet-ballot-group-certify", "-c", conf[0],
119 "-g", "mygroup", "-e", "groupca", "-m", v0_pub], stdout=groupcert_file) 127 "-g", "mygroup", "-e", "groupca", "-m", v_pub], stdout=groupcert_file)
120 128
121groupcert_file.close() 129 groupcert_file.close()
122 130
123# register the ballot with authorities 131# register the ballot with authorities
124subprocess.check_call(["gnunet-ballot", "-LINFO", "-i", ballot_filename, "-e", "issuer", "-c", conf[0]]) 132subprocess.check_call(["gnunet-ballot", "-LINFO", "-i", ballot_filename, "-e", "issuer", "-c", conf[0]])
@@ -135,18 +143,25 @@ subprocess.check_call(["gnunet-ballot", "-LDEBUG", "-k", ballot_filename, "-c",
135 143
136print "threshold public key retrieved" 144print "threshold public key retrieved"
137 145
138exit() 146# actually vote
147for vi in range(NUM_VOTERS):
148 voter_ballot_filename = os.path.join(testdir, "v"+str(vi)+"-ballot")
149 shutil.copy(ballot_filename, voter_ballot_filename)
150 groupcert_filename = os.path.join(testdir, "v"+str(vi)+"-cert")
151 # add voter's group information
152 subprocess.check_call(["gnunet-ballot", "-g", groupcert_filename, voter_ballot_filename, "-c", conf[0]])
139 153
140# add voter's group information 154 ch = random.choice(["yes", "no", "maybe"])
141subprocess.check_call(["gnunet-ballot", "-g", groupcert_filename, ballot_filename, "-c", conf[0]])
142 155
143# actually vote ... 156 # actually vote ...
144subprocess.check_call(["gnunet-ballot", "-x", "yes", ballot_filename, "-e", "voter0", "-c", conf[0]]) 157 subprocess.check_call(["gnunet-ballot", "-x", ch, voter_ballot_filename, "-e", "voter"+str(vi), "-c", conf[0]])
145 158
146wait_for_after(TS_START) 159wait_for_after(TS_START)
147 160
148# submit the ballot with the vote 161for vi in range(NUM_VOTERS):
149subprocess.check_call(["gnunet-ballot", "-s", ballot_filename, "-c", conf[0]]) 162 voter_ballot_filename = os.path.join(testdir, "v"+str(vi)+"-ballot")
163 # submit the ballot with the vote
164 subprocess.check_call(["gnunet-ballot", "-s", voter_ballot_filename, "-c", conf[0]])
150 165
151wait_for_after(TS_QUERY) 166wait_for_after(TS_QUERY)
152 167