]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/tests/QuickCheck/Trustee.hs
protocol: work around to avoid ConstraintKinds
[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 Reifies c crypto => Group crypto => Key crypto =>
26 Proxy v -> Proxy c -> TestTree
27 testIndispensableTrusteePublicKey (_v::Proxy v) (c::Proxy c) = groupReify c $
28 testGroup (Text.unpack $ cryptoName (reflect c))
29 [ testProperty "Right" $ \seed ->
30 isRight $ runExcept $
31 (`evalStateT` mkStdGen seed) $ do
32 trusteeSecKey :: SecretKey crypto c <- randomSecretKey
33 trusteePubKey :: TrusteePublicKey crypto v c
34 <- proveIndispensableTrusteePublicKey trusteeSecKey
35 lift $ verifyIndispensableTrusteePublicKey trusteePubKey
36 ]
37
38 instance
39 ( Reifies v Version
40 , Reifies c crypto
41 , Group crypto
42 , Multiplicative (G crypto c)
43 , Invertible (G crypto c)
44 ) => Arbitrary (TrusteePublicKey crypto v c) where
45 arbitrary = do
46 trustee_PublicKey <- arbitrary
47 trustee_SecretKeyProof <- arbitrary
48 return TrusteePublicKey{..}