def test_new_product(self): illegal_vote = np.array([[3,-2],[-2,3]]) illegal_vote_partitions = util.partition_and_secret_share_vote(illegal_vote, local_servers) client_util.postvote("ic3", illegal_vote_partitions, local_servers) client_util.send_vote([1,2], 'c1', local_servers) client_util.send_vote([2,1], 'c2', local_servers) illegal_vote = np.array([[2, -1], [-1, 2]]) illegal_vote_partitions = util.partition_and_secret_share_vote(illegal_vote, local_servers) client_util.postvote("ic4", illegal_vote_partitions, local_servers) illegal_vote = np.array([[0, 0], [0, 0]]) illegal_vote_partitions = util.partition_and_secret_share_vote(illegal_vote, local_servers) client_util.postvote("ic5", illegal_vote_partitions, local_servers) for server in local_servers: util.get_url(server + "/zero_one_consistency") time.sleep(1) for server in local_servers: util.get_url(server + "/sumdifferenceshareforzeroone") time.sleep(1) for server in local_servers: util.get_url(server + '/check_votes') time.sleep(1) for server in local_servers: util.get_url(server + '/ensure_vote_agreement') time.sleep(1) for server in local_servers: util.get_url(server + '/add') time.sleep(1) for server in local_servers: response = util.get_url(server + '/compute_result') self.assertTrue(response.text=="ok") time.sleep(1) for server in local_servers: response = util.get_url(server + '/verify_result') result = util.string_to_vote(response.text) self.assertTrue(np.array_equal(np.array([1.5,1.5]),result))
def test_many_votes(self): reset_servers() for i in range(40): client = 'c' + str(i) client_util.send_vote([1, 2, 3, 4], client, local_servers) for server in local_servers: util.get_url(server + "/zero_one_consistency") time.sleep(1) for server in local_servers: util.get_url(server + "/sumdifferenceshareforzeroone") time.sleep(1) for server in local_servers: util.get_url(server + '/check_votes') time.sleep(1) for server in local_servers: util.get_url(server + '/ensure_vote_agreement') time.sleep(1) for server in local_servers: util.get_url(server + '/add') time.sleep(1) for server in local_servers: response = util.get_url(server + '/compute_result') self.assertTrue(response.text=="ok") time.sleep(1) v = np.array([[40, 0, 0, 0], [0, 40, 0, 0], [0, 0, 40, 0], [0, 0, 0, 40]]) for server in local_servers: response = util.get_url(server + '/verify_result') result = util.string_to_vote(response.text) self.assertTrue(np.array_equal(result, np.array( [sum([v[i][j] * (1 / (j + 1)) for j in range(v.shape[0])]) for i in range(v.shape[1])])))
def test_row_sum_neg(self): create_local_server(5003) time.sleep(1) client_util.send_vote([4, 2, 1, 3], 'c1', local_servers) client_util.send_vote([1, 2, 3, 4], 'c2', local_servers) for s in local_servers: response = util.get_url(s + '/check_votes') self.assertTrue(len(requests.get(mediator + "/test/printcomplaints").text) <= 2, msg=requests.get(mediator + "/test/printcomplaints").text)
def test_cheat_ensure_vote_agreement(self): create_local_cheating_server(5003, [0], util.Protocol.ensure_vote_agreement.value) client_util.send_vote([4, 2, 1, 3], 'c1', local_servers) client_util.send_vote([1, 2, 3, 4], 'c2', local_servers) for s in local_servers: response = util.get_url(s + '/check_votes') for s in local_servers: response = util.get_url(s + '/ensure_vote_agreement') self.assertTrue(len(requests.get(mediator + "/test/printcomplaints").text) > 2)
def test_adding_votes(self): client_util.send_vote([4, 2, 1, 3], 'c1', local_servers) client_util.send_vote([1, 2, 3, 4], 'c2', local_servers) # Bad vote client_util.send_vote([1, 1, 1, 1], 'c3', local_servers) client_util.send_vote([2, 2, 2, 2], 'c4', local_servers) for server in local_servers: util.get_url(server + "/zero_one_consistency") time.sleep(1) for server in local_servers: util.get_url(server + "/sumdifferenceshareforzeroone") time.sleep(1) for server in local_servers: util.get_url(server + '/check_votes') time.sleep(1) for server in local_servers: util.get_url(server + '/ensure_vote_agreement') time.sleep(1) for server in local_servers: util.get_url(server + '/add') time.sleep(1) for server in local_servers: response = util.get_url(server + '/compute_result') self.assertTrue(response.text=="ok") time.sleep(1) v = np.array([[1, 0, 0, 1],[0, 2, 0, 0],[1, 0, 1, 0],[0, 0, 1, 1]]) for server in local_servers: response = util.get_url(server + '/verify_result') result = util.string_to_vote(response.text) self.assertTrue(np.array_equal(result, np.array( [sum([v[i][j] * (1 / (j + 1)) for j in range(v.shape[0])]) for i in range(v.shape[1])])))
def test_cheat_product_sum_difference_partition(self): create_local_cheating_server(5003, [0], util.Protocol.sum_difference_zero_one_partition.value) client_util.send_vote([4, 2, 1, 3], 'c1', local_servers) for server in local_servers: util.get_url(server + "/zero_one_consistency") time.sleep(1) for server in local_servers: util.get_url(server + "/sumdifferenceshareforzeroone") time.sleep(1) for server in local_servers: util.get_url(server + '/check_votes') time.sleep(1) for server in local_servers: util.get_url(server + "/ensure_vote_agreement") time.sleep(20) self.assertTrue(len(requests.get(mediator + "/test/printcomplaints").text) > 2)
def test_cheat_final_result(self): create_local_cheating_server(5003, [0], util.Protocol.compute_result.value) client_util.send_vote([4, 2, 1, 3], 'c1', local_servers) client_util.send_vote([1, 2, 3, 4], 'c2', local_servers) for s in local_servers: response = util.get_url(s + '/check_votes') for s in local_servers: response = util.get_url(s + '/ensure_vote_agreement') for server in local_servers: util.get_url(server + '/add') time.sleep(.5) for s in local_servers: response = util.get_url(s + '/compute_result') time.sleep(.5) for s in local_servers: response = util.get_url(s + "/verify_result") self.assertFalse(response.ok, msg="Servers don't agree on result, " + response.text) self.assertTrue(len(requests.get(mediator + "/test/printcomplaints").text) > 2)