summaryrefslogtreecommitdiff
path: root/tests/QuickCheck/Trustee.hs
blob: 586295c9a4aa4eca08d3d96eba901e60512d89dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# OPTIONS -fno-warn-orphans #-}
{-# LANGUAGE UndecidableInstances #-} -- for Reifies instances
module QuickCheck.Trustee where

import Test.Tasty.QuickCheck
import qualified Data.Text as Text

import Voting.Protocol

import Utils
import QuickCheck.Election ()

quickcheck :: TestTree
quickcheck =
	testGroup "Trustee"
	 [ testGroup "verifyIndispensableTrusteePublicKey" $
		 [ testIndispensableTrusteePublicKey weakFFC
		 , testIndispensableTrusteePublicKey beleniosFFC
		 ]
	 ]

testIndispensableTrusteePublicKey :: FFC -> TestTree
testIndispensableTrusteePublicKey ffc =
	reify ffc $ \(Proxy::Proxy c) ->
	testGroup (Text.unpack $ ffc_name ffc)
	 [ testProperty "Right" $ \seed ->
		isRight $ runExcept $
			(`evalStateT` mkStdGen seed) $ do
				trusteeSecKey :: SecretKey c <- randomSecretKey
				trusteePubKey <- proveIndispensableTrusteePublicKey trusteeSecKey
				lift $ verifyIndispensableTrusteePublicKey trusteePubKey
	 ]

instance Reifies c FFC => Arbitrary (TrusteePublicKey c) where
	arbitrary = do
		trustee_PublicKey <- arbitrary
		trustee_SecretKeyProof <- arbitrary
		return TrusteePublicKey{..}