diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-03-30 21:41:58 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-03-30 21:41:58 +0000 |
commit | 9f10abfdc35d8f189a8e0a77a389799ca6b7f9e5 (patch) | |
tree | 39d855abacebeaa45752e4abc5b4a660d2603d70 /src/test/python | |
parent | 1fbef203844b19f8141bddcba20a977de34b211e (diff) | |
download | gnunet-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.py | 51 |
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. | |||
4 | import os | 4 | import os |
5 | import subprocess | 5 | import subprocess |
6 | import time | 6 | import time |
7 | import random | ||
8 | import shutil | ||
7 | 9 | ||
8 | 10 | ||
9 | NUM_AUTHORITIES = 1 | 11 | NUM_AUTHORITIES = 1 |
10 | NUM_VOTERS = 1 | 12 | NUM_VOTERS = 5 |
11 | 13 | ||
12 | 14 | ||
13 | def wait_for_after(ts): | 15 | def 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 | ||
19 | def get_config(section, option, filename=None, expand=False): | 23 | def 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 | ||
76 | print "public key", public_key | 80 | print "public key", public_key |
77 | 81 | ||
78 | create_identity("voter0", conf[0]) | 82 | for vi in range(NUM_VOTERS): |
83 | create_identity("voter"+str(vi), conf[0]) | ||
84 | |||
79 | create_identity("issuer", conf[0]) | 85 | create_identity("issuer", conf[0]) |
80 | create_identity("groupca", conf[0]) | 86 | create_identity("groupca", conf[0]) |
81 | 87 | ||
@@ -89,15 +95,15 @@ TS_KEYGEN_END = now + 10 | |||
89 | TS_START = now + 15 | 95 | TS_START = now + 15 |
90 | TS_CLOSING = now + 20 | 96 | TS_CLOSING = now + 20 |
91 | TS_CONCLUDE = now + 25 | 97 | TS_CONCLUDE = now + 25 |
92 | TS_QUERY = now + 30 | 98 | TS_QUERY = now + 35 |
93 | TS_END = now + 35 | 99 | TS_END = now + 40 |
94 | 100 | ||
95 | ballot.write("[authorities]\n") | 101 | ballot.write("[authorities]\n") |
96 | ballot.write("auth0 = %s\n" % public_key) | 102 | ballot.write("auth0 = %s\n" % public_key) |
97 | ballot.write("[election]\n") | 103 | ballot.write("[election]\n") |
98 | ballot.write("TOPIC = mytopic\n") | 104 | ballot.write("TOPIC = mytopic\n") |
99 | ballot.write("THRESHOLD = 1\n") | 105 | ballot.write("THRESHOLD = 1\n") |
100 | ballot.write("CHOICES = yes//no\n") | 106 | ballot.write("CHOICES = yes//no//maybe\n") |
101 | ballot.write("GROUP = mygroup\n") | 107 | ballot.write("GROUP = mygroup\n") |
102 | ballot.write("CA_PUB = %s\n" % get_identity_pubkey("groupca", conf[0])) | 108 | ballot.write("CA_PUB = %s\n" % get_identity_pubkey("groupca", conf[0])) |
103 | ballot.write("TIMESTAMP_KEYGEN_START = %s\n" % TS_KEYGEN_START) | 109 | ballot.write("TIMESTAMP_KEYGEN_START = %s\n" % TS_KEYGEN_START) |
@@ -110,15 +116,17 @@ ballot.write("TIMESTAMP_END = %s\n" % TS_END) | |||
110 | 116 | ||
111 | ballot.close() | 117 | ballot.close() |
112 | 118 | ||
113 | groupcert_filename = os.path.join(testdir, "v0-cert") | 119 | # create group certs for all voters |
114 | groupcert_file = open(groupcert_filename, "w") | 120 | for 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 | ||
116 | v0_pub = get_identity_pubkey("voter0", conf[0]) | 124 | v_pub = get_identity_pubkey("voter"+str(vi), conf[0]) |
117 | 125 | ||
118 | subprocess.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 | ||
121 | groupcert_file.close() | 129 | groupcert_file.close() |
122 | 130 | ||
123 | # register the ballot with authorities | 131 | # register the ballot with authorities |
124 | subprocess.check_call(["gnunet-ballot", "-LINFO", "-i", ballot_filename, "-e", "issuer", "-c", conf[0]]) | 132 | subprocess.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 | ||
136 | print "threshold public key retrieved" | 144 | print "threshold public key retrieved" |
137 | 145 | ||
138 | exit() | 146 | # actually vote |
147 | for 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"]) |
141 | subprocess.check_call(["gnunet-ballot", "-g", groupcert_filename, ballot_filename, "-c", conf[0]]) | ||
142 | 155 | ||
143 | # actually vote ... | 156 | # actually vote ... |
144 | subprocess.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 | ||
146 | wait_for_after(TS_START) | 159 | wait_for_after(TS_START) |
147 | 160 | ||
148 | # submit the ballot with the vote | 161 | for vi in range(NUM_VOTERS): |
149 | subprocess.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 | ||
151 | wait_for_after(TS_QUERY) | 166 | wait_for_after(TS_QUERY) |
152 | 167 | ||