summaryrefslogtreecommitdiff
path: root/tests/HUnit/Election.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/HUnit/Election.hs')
-rw-r--r--tests/HUnit/Election.hs53
1 files changed, 28 insertions, 25 deletions
diff --git a/tests/HUnit/Election.hs b/tests/HUnit/Election.hs
index 465f910..5e193eb 100644
--- a/tests/HUnit/Election.hs
+++ b/tests/HUnit/Election.hs
@@ -1,11 +1,12 @@
-{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
module HUnit.Election where
import Test.Tasty.HUnit
+import qualified Data.Aeson as JSON
import qualified Data.List as List
+import qualified Data.Text as Text
import qualified System.Random as Random
import Voting.Protocol
@@ -16,54 +17,56 @@ hunit :: TestTree
hunit = testGroup "Election"
[ testGroup "groupGenInverses"
[ testCase "WeakParams" $
- List.take 10 (groupGenInverses @WeakParams) @?=
- [groupGen^neg (fromNatural n) | n <- [0..9]]
+ reify weakFFC $ \(Proxy::Proxy c) ->
+ List.take 10 (groupGenInverses @c) @?=
+ [groupGen^neg (fromNatural n) | n <- [0..9]]
, testCase "BeleniosParams" $
- List.take 10 (groupGenInverses @BeleniosParams) @?=
- [groupGen^neg (fromNatural n) | n <- [0..9]]
+ reify beleniosFFC $ \(Proxy::Proxy c) ->
+ List.take 10 (groupGenInverses @c) @?=
+ [groupGen^neg (fromNatural n) | n <- [0..9]]
]
, testGroup "encryptBallot" $
- [ testsEncryptBallot @WeakParams
- , testsEncryptBallot @BeleniosParams
+ [ testsEncryptBallot weakFFC
+ , testsEncryptBallot beleniosFFC
]
]
-testsEncryptBallot :: forall q. Params q => TestTree
-testsEncryptBallot =
- testGroup (paramsName @q)
- [ testEncryptBallot @q 0
+testsEncryptBallot :: FFC -> TestTree
+testsEncryptBallot ffc =
+ testGroup (Text.unpack $ ffc_name ffc)
+ [ testEncryptBallot ffc 0
[Question "q1" ["a1","a2","a3"] zero one]
[[True, False, False]]
(Right True)
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[Question "q1" ["a1","a2","a3"] zero one]
[[False, False, False]]
(Right True)
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[Question "q1" ["a1","a2","a3"] zero one]
[[False, False, False]]
(Right True)
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[Question "q1" [] zero one]
[]
(Left (ErrorBallot_WrongNumberOfAnswers 0 1))
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[Question "q1" ["a1","a2"] one one]
[[True]]
(Left (ErrorBallot_Answer (ErrorAnswer_WrongNumberOfOpinions 1 2)))
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[Question "q1" ["a1","a2","a3"] zero one]
[[True, True, False]]
(Left (ErrorBallot_Answer (ErrorAnswer_WrongSumOfOpinions 2 0 1)))
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[Question "q1" ["a1","a2","a3"] one one]
[[False, False, False]]
(Left (ErrorBallot_Answer (ErrorAnswer_WrongSumOfOpinions 0 1 1)))
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[Question "q1" ["a1","a2"] one one]
[[False, False, True]]
(Left (ErrorBallot_Answer (ErrorAnswer_WrongNumberOfOpinions 3 2)))
- , testEncryptBallot @q 0
+ , testEncryptBallot ffc 0
[ Question "q1" ["a11","a12","a13"] zero (one+one)
, Question "q2" ["a21","a22","a23"] one one
]
@@ -73,25 +76,25 @@ testsEncryptBallot =
]
testEncryptBallot ::
- forall q. SubGroup q =>
- Int -> [Question q] -> [[Bool]] ->
+ FFC -> Int -> [Question] -> [[Bool]] ->
Either ErrorBallot Bool ->
TestTree
-testEncryptBallot seed quests opins exp =
+testEncryptBallot ffc seed quests opins exp =
let got =
+ reify ffc $ \(Proxy::Proxy c) ->
runExcept $
(`evalStateT` Random.mkStdGen seed) $ do
uuid <- randomUUID
cred <- randomCredential
- let ballotSecKey = credentialSecretKey @q uuid cred
+ let ballotSecKey = credentialSecretKey @c uuid cred
elecPubKey <- publicKey <$> randomSecretKey
let elec = Election
{ election_name = "election"
, election_description = "description"
- , election_PublicKey = elecPubKey
+ , election_crypto = ElectionCrypto_FFC ffc elecPubKey
, election_questions = quests
, election_uuid = uuid
- , election_hash = Hash "" -- FIXME: when implemented
+ , election_hash = hashJSON JSON.Null
}
verifyBallot elec
<$> encryptBallot elec (Just ballotSecKey) opins