summaryrefslogtreecommitdiff
path: root/tests/HUnit/Trustee/Indispensable.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/HUnit/Trustee/Indispensable.hs')
-rw-r--r--tests/HUnit/Trustee/Indispensable.hs64
1 files changed, 32 insertions, 32 deletions
diff --git a/tests/HUnit/Trustee/Indispensable.hs b/tests/HUnit/Trustee/Indispensable.hs
index 3de29c3..b035d5d 100644
--- a/tests/HUnit/Trustee/Indispensable.hs
+++ b/tests/HUnit/Trustee/Indispensable.hs
@@ -1,10 +1,10 @@
-{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
module HUnit.Trustee.Indispensable where
import Test.Tasty.HUnit
+import qualified Data.Text as Text
import qualified System.Random as Random
import qualified Text.Printf as Printf
@@ -15,53 +15,52 @@ import Utils
hunit :: TestTree
hunit = testGroup "Indispensable"
[ testGroup "verifyIndispensableTrusteePublicKey" $
- [ testsVerifyIndispensableTrusteePublicKey @WeakParams
+ [ testsVerifyIndispensableTrusteePublicKey weakFFC
]
, testGroup "verifyTally" $
- [ testsVerifyTally @WeakParams
- , testsVerifyTally @BeleniosParams
+ [ testsVerifyTally weakFFC
+ , testsVerifyTally beleniosFFC
]
]
-testsVerifyIndispensableTrusteePublicKey :: forall q. Params q => TestTree
-testsVerifyIndispensableTrusteePublicKey =
- testGroup (paramsName @q)
- [ testVerifyIndispensableTrusteePublicKey @q 0 (Right ())
+testsVerifyIndispensableTrusteePublicKey :: FFC -> TestTree
+testsVerifyIndispensableTrusteePublicKey ffc =
+ testGroup (Text.unpack $ ffc_name ffc)
+ [ testVerifyIndispensableTrusteePublicKey ffc 0 (Right ())
]
testVerifyIndispensableTrusteePublicKey ::
- forall q. Params q =>
- Int -> Either ErrorTrusteePublicKey () -> TestTree
-testVerifyIndispensableTrusteePublicKey seed exp =
+ FFC -> Int -> Either ErrorTrusteePublicKey () -> TestTree
+testVerifyIndispensableTrusteePublicKey ffc seed exp =
let got =
+ reify ffc $ \(Proxy::Proxy c) ->
runExcept $
(`evalStateT` Random.mkStdGen seed) $ do
- trusteeSecKey :: SecretKey q <- randomSecretKey
+ trusteeSecKey :: SecretKey c <- randomSecretKey
trusteePubKey <- proveIndispensableTrusteePublicKey trusteeSecKey
lift $ verifyIndispensableTrusteePublicKey trusteePubKey
in
- testCase (show (paramsName @q)) $
+ testCase (Text.unpack $ ffc_name ffc) $
got @?= exp
-testsVerifyTally :: forall q. Params q => TestTree
-testsVerifyTally =
- testGroup (paramsName @q)
- [ testVerifyTally @q 0 1 1 1
- , testVerifyTally @q 0 2 1 1
- , testVerifyTally @q 0 1 2 1
- , testVerifyTally @q 0 2 2 1
- , testVerifyTally @q 0 5 10 5
+testsVerifyTally :: FFC -> TestTree
+testsVerifyTally ffc =
+ testGroup (Text.unpack $ ffc_name ffc)
+ [ testVerifyTally ffc 0 1 1 1
+ , testVerifyTally ffc 0 2 1 1
+ , testVerifyTally ffc 0 1 2 1
+ , testVerifyTally ffc 0 2 2 1
+ , testVerifyTally ffc 0 5 10 5
]
-testVerifyTally ::
- forall q. Params q =>
- Int -> Natural -> Natural -> Natural -> TestTree
-testVerifyTally seed nTrustees nQuests nChoices =
+testVerifyTally :: FFC -> Int -> Natural -> Natural -> Natural -> TestTree
+testVerifyTally ffc seed nTrustees nQuests nChoices =
let clearTallyResult = dummyTallyResult nQuests nChoices in
- let decryptedTallyResult :: Either ErrorDecryptionShare [[Natural]] =
+ let decryptedTallyResult :: Either ErrorTally [[Natural]] =
+ reify ffc $ \(Proxy::Proxy c) ->
runExcept $
(`evalStateT` Random.mkStdGen seed) $ do
- secKeyByTrustee :: [SecretKey q] <-
+ secKeyByTrustee :: [SecretKey c] <-
replicateM (fromIntegral nTrustees) $ randomSecretKey
trusteePubKeys <- forM secKeyByTrustee $ proveIndispensableTrusteePublicKey
let pubKeyByTrustee = trustee_PublicKey <$> trusteePubKeys
@@ -71,12 +70,12 @@ testVerifyTally seed nTrustees nQuests nChoices =
lift $ verifyDecryptionShareByTrustee encTally pubKeyByTrustee decShareByTrustee
tally@Tally{..} <- lift $
proveTally (encTally, countMax) decShareByTrustee $
- combineIndispensableDecryptionShares pubKeyByTrustee encTally
+ combineIndispensableDecryptionShares pubKeyByTrustee
lift $ verifyTally tally $
- combineIndispensableDecryptionShares pubKeyByTrustee encTally
+ combineIndispensableDecryptionShares pubKeyByTrustee
return tally_countByChoiceByQuest
in
- testCase (Printf.printf "nT=%i,nQ=%i,nC=%i (%i maxCount)"
+ testCase (Printf.printf "#T=%i,#Q=%i,#C=%i (%i maxCount)"
nTrustees nQuests nChoices
(dummyTallyCount nQuests nChoices)) $
decryptedTallyResult @?= Right clearTallyResult
@@ -91,8 +90,9 @@ dummyTallyResult nQuests nChoices =
]
encryptTallyResult ::
- Monad m => RandomGen r => SubGroup q =>
- PublicKey q -> [[Natural]] -> StateT r m (EncryptedTally q, Natural)
+ Reifies c FFC =>
+ Monad m => RandomGen r =>
+ PublicKey c -> [[Natural]] -> StateT r m (EncryptedTally c, Natural)
encryptTallyResult pubKey countByChoiceByQuest =
(`runStateT` 0) $
forM countByChoiceByQuest $