chore(tests): ensure only valid CryptoIDs are generated
This commit is contained in:
parent
ee6fecb79e
commit
b36ddce3e3
@ -4,7 +4,6 @@ import TestImport
|
||||
|
||||
import ModelSpec ()
|
||||
|
||||
import qualified Data.CryptoID as CID
|
||||
import Yesod.EmbeddedStatic
|
||||
|
||||
instance Arbitrary (Route Auth) where
|
||||
@ -110,9 +109,6 @@ instance Arbitrary (Route UniWorX) where
|
||||
arbitrary = genericArbitrary
|
||||
shrink = genericShrink
|
||||
|
||||
instance Arbitrary a => Arbitrary (CID.CryptoID ns a) where
|
||||
arbitrary = CID.CryptoID <$> arbitrary
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
parallel $
|
||||
|
||||
@ -27,6 +27,8 @@ import Utils
|
||||
|
||||
import Data.CryptoID.Poly
|
||||
import qualified Data.CryptoID.Class.ImplicitNamespace as Implicit
|
||||
import qualified Data.CryptoID.Class as Explicit
|
||||
import Data.Binary.SerializationLength
|
||||
|
||||
import Control.Monad.Catch.Pure (Catch, runCatch)
|
||||
|
||||
@ -172,6 +174,15 @@ instance {-# OVERLAPS #-} (HasCryptoID ns ct pt (ReaderT CryptoIDKey Catch), Arb
|
||||
arbitrary = arbitrary <&> \pt -> (pt, either (error . show) id . runCatch $ runReaderT (Implicit.encrypt pt) tmpKey)
|
||||
where
|
||||
tmpKey = unsafePerformIO genKey
|
||||
|
||||
instance HasFixedSerializationLength () where
|
||||
type SerializationLength () = 0
|
||||
|
||||
instance HasCryptoID ns ct () (ReaderT CryptoIDKey Catch) => Arbitrary (CryptoID ns ct) where
|
||||
arbitrary = return . either (error . show) id . runCatch $ runReaderT (Explicit.encrypt ()) tmpKey
|
||||
where
|
||||
tmpKey = unsafePerformIO genKey
|
||||
|
||||
instance CoArbitrary ct => CoArbitrary (CryptoID ns ct)
|
||||
instance Function ct => Function (CryptoID ns ct)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user