gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r32616 - in gnunet-java/src/test/java/org/gnunet: . voting


From: gnunet
Subject: [GNUnet-SVN] r32616 - in gnunet-java/src/test/java/org/gnunet: . voting
Date: Tue, 11 Mar 2014 02:27:30 +0100

Author: dold
Date: 2014-03-11 02:27:30 +0100 (Tue, 11 Mar 2014)
New Revision: 32616

Added:
   gnunet-java/src/test/java/org/gnunet/voting/
   gnunet-java/src/test/java/org/gnunet/voting/TestVotingCrypto.java
Log:
add voting test

Added: gnunet-java/src/test/java/org/gnunet/voting/TestVotingCrypto.java
===================================================================
--- gnunet-java/src/test/java/org/gnunet/voting/TestVotingCrypto.java           
                (rev 0)
+++ gnunet-java/src/test/java/org/gnunet/voting/TestVotingCrypto.java   
2014-03-11 01:27:30 UTC (rev 32616)
@@ -0,0 +1,97 @@
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING.  If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnunet.voting;
+
+import org.gnunet.secretsharing.*;
+import org.gnunet.secretsharing.callbacks.DecryptCallback;
+import org.gnunet.secretsharing.callbacks.SecretReadyCallback;
+import org.gnunet.testing.TestingFixture;
+import org.gnunet.testing.TestingSubsystem;
+import org.gnunet.util.*;
+import org.gnunet.util.crypto.EcdhePrivateKey;
+import org.gnunet.util.crypto.EcdsaPrivateKey;
+import org.gnunet.util.crypto.EcdsaPublicKey;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestVotingCrypto extends TestingFixture {
+    @Test
+    public void testVoteTally() {
+        Configuration armConf = new Configuration();
+        armConf.setValueString("arm", "DEFAULTSERVICES", "consensus set");
+        Program.configureLogging("DEBUG");
+        // for testing, we vote with the same voter identity multiple times,
+        // does not matter here ...
+        final EcdsaPrivateKey privateKey = EcdsaPrivateKey.createRandom();
+        final EcdsaPublicKey publicKey = privateKey.getPublicKey();
+        final TestingSubsystem ts = new TestingSubsystem("arm", 
armConf.writeTemp().getAbsolutePath());
+        KeyGeneration kg = new KeyGeneration(ts.getConfiguration(), new 
PeerIdentity[0],
+                HashCode.random(), AbsoluteTime.now(), 
AbsoluteTime.now().add(RelativeTime.fromSeconds(5)),
+                1, new SecretReadyCallback() {
+            @Override
+            public void onSecretReady(Share share) {
+                Assert.assertNotNull(share);
+                EncryptedVote encryptedVote1 = EncryptedVote.fromChoice(1, 
share.publicKey, privateKey, publicKey);
+                EncryptedVote encryptedVote2 = EncryptedVote.fromChoice(0, 
share.publicKey, privateKey, publicKey);
+                EncryptedVote encryptedVote3 = EncryptedVote.fromChoice(0, 
share.publicKey, privateKey, publicKey);
+
+                Ciphertext sum = 
Ciphertext.identity().multiply(encryptedVote1.v.multiply(encryptedVote2.v).multiply(encryptedVote3.v));
+
+                Decryption decryption = new Decryption(ts.getConfiguration(), 
share, sum,
+                        AbsoluteTime.now(), 
AbsoluteTime.now().add(RelativeTime.fromSeconds(5)), new DecryptCallback() {
+
+                    @Override
+                    public void onResult(Plaintext plaintext) {
+                        Assert.assertNotNull(plaintext);
+                        long x = plaintext.bruteForceDiscreteLog(3);
+                        // one yes, two no
+                        Assert.assertEquals(-1, x);
+                    }
+                });
+            }
+        });
+    }
+
+    @Test
+    public void testSerialization() {
+        Configuration armConf = new Configuration();
+        armConf.setValueString("arm", "DEFAULTSERVICES", "consensus set");
+        Program.configureLogging("DEBUG");
+        final TestingSubsystem ts = new TestingSubsystem("arm", 
armConf.writeTemp().getAbsolutePath());
+        final EcdsaPrivateKey privateKey = EcdsaPrivateKey.createRandom();
+        final EcdsaPublicKey publicKey = privateKey.getPublicKey();
+        KeyGeneration kg = new KeyGeneration(ts.getConfiguration(), new 
PeerIdentity[0],
+                HashCode.random(), AbsoluteTime.now(), 
AbsoluteTime.now().add(RelativeTime.fromSeconds(5)),
+                1, new SecretReadyCallback() {
+            @Override
+            public void onSecretReady(Share share) {
+                Assert.assertNotNull(share);
+                EncryptedVote encryptedVote1 = EncryptedVote.fromChoice(1, 
share.publicKey, privateKey, publicKey);
+                Configuration c = new Configuration();
+                encryptedVote1.writeToConfiguration(c);
+                EncryptedVote encryptedVote2 = 
EncryptedVote.parseFromConfiguration(c, publicKey);
+                Assert.assertEquals(encryptedVote1, encryptedVote2);
+            }
+
+        });
+    }
+}
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]