]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/tests/QuickCheck/Trustee.hs
protocol: replace reifyCrypto by groupDict
[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)
28 | Dict <- groupDict (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 , Reifies c crypto
42 , Group crypto
43 , Multiplicative (G crypto c)
44 , Invertible (G crypto c)
45 ) => Arbitrary (TrusteePublicKey crypto v c) where
46 arbitrary = do
47 trustee_PublicKey <- arbitrary
48 trustee_SecretKeyProof <- arbitrary
49 return TrusteePublicKey{..}