packages feed

hjugement-protocol-0.0.0.20190511: tests/QuickCheck/Trustee.hs

{-# OPTIONS -fno-warn-orphans #-}
module QuickCheck.Trustee where

import Test.Tasty.QuickCheck

import Protocol.Arithmetic
import Protocol.Credential
import Protocol.Trustees.Simple

import Utils
import QuickCheck.Election ()

quickcheck :: TestTree
quickcheck =
	testGroup "Trustee"
	 [ testGroup "verifyTrusteePublicKey" $
		 [ testTrusteePublicKey @WeakParams
		 , testTrusteePublicKey @BeleniosParams
		 ]
	 ]

testTrusteePublicKey :: forall q. Params q => TestTree
testTrusteePublicKey  =
	testGroup (paramsName @q)
	 [ testProperty "Right" $ \seed ->
		isRight $ runExcept $
			(`evalStateT` mkStdGen seed) $ do
				trustSecKey :: SecretKey q <- randomSecretKey
				trustPubKey <- proveTrusteePublicKey trustSecKey
				lift $ verifyTrusteePublicKey trustPubKey
	 ]

instance SubGroup q => Arbitrary (TrusteePublicKey q) where
	arbitrary = do
		trustee_PublicKey <- arbitrary
		trustee_SecretKeyProof <- arbitrary
		return TrusteePublicKey{..}