]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/tests/QuickCheck/Trustee.hs
cli: admin: directly use election_hash
[majurity.git] / hjugement-protocol / tests / QuickCheck / Trustee.hs
1 {-# OPTIONS -fno-warn-orphans #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE UndecidableInstances #-} -- for Reifies instances
4 module QuickCheck.Trustee where
5
6 import Test.Tasty.QuickCheck
7 import qualified Data.Text as Text
8
9 import Voting.Protocol
10
11 import Utils
12 import QuickCheck.Election ()
13
14 quickcheck :: Reifies v Version => Proxy v -> TestTree
15 quickcheck v =
16 testGroup "Trustee" $
17 [ testGroup "verifyIndispensableTrusteePublicKey" $
18 [ reify weakFFC $ testIndispensableTrusteePublicKey v
19 , reify beleniosFFC $ testIndispensableTrusteePublicKey v
20 ]
21 ]
22
23 testIndispensableTrusteePublicKey ::
24 Reifies v Version =>
25 CryptoParams crypto c =>
26 Key crypto =>
27 Proxy v -> Proxy c -> TestTree
28 testIndispensableTrusteePublicKey (_v::Proxy v) (c::Proxy c) =
29 testGroup (Text.unpack $ cryptoName (reflect c))
30 [ testProperty "Right" $ \seed ->
31 isRight $ runExcept $
32 (`evalStateT` mkStdGen seed) $ do
33 trusteeSecKey :: SecretKey crypto c <- randomSecretKey
34 trusteePubKey :: TrusteePublicKey crypto v c
35 <- proveIndispensableTrusteePublicKey trusteeSecKey
36 lift $ verifyIndispensableTrusteePublicKey trusteePubKey
37 ]
38
39 instance
40 ( Reifies v Version
41 , CryptoParams crypto c
42 ) => Arbitrary (TrusteePublicKey crypto v c) where
43 arbitrary = do
44 trustee_PublicKey <- arbitrary
45 trustee_SecretKeyProof <- arbitrary
46 return TrusteePublicKey{..}