{-# LANGUAGE FlexibleContexts #-}
module Gen.Hedgehog.Roundtrip.CBOR
( roundtrip_CBOR
) where
import Bcc.Api
import Bcc.Prelude
import Hedgehog (Gen, Property)
import qualified Hedgehog as H
roundtrip_CBOR
:: (SerialiseAsCBOR a, Eq a, Show a)
=> AsType a -> Gen a -> Property
roundtrip_CBOR :: AsType a -> Gen a -> Property
roundtrip_CBOR AsType a
typeProxy Gen a
gen =
HasCallStack => PropertyT IO () -> Property
PropertyT IO () -> Property
H.property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
forall a b. (a -> b) -> a -> b
$ do
a
val <- Gen a -> PropertyT IO a
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
H.forAll Gen a
gen
a
-> (a -> ByteString)
-> (ByteString -> Either DecoderError a)
-> PropertyT IO ()
forall (m :: * -> *) (f :: * -> *) b a.
(MonadTest m, Applicative f, Show b, Show (f a), Eq (f a),
HasCallStack) =>
a -> (a -> b) -> (b -> f a) -> m ()
H.tripping a
val a -> ByteString
forall a. SerialiseAsCBOR a => a -> ByteString
serialiseToCBOR (AsType a -> ByteString -> Either DecoderError a
forall a.
SerialiseAsCBOR a =>
AsType a -> ByteString -> Either DecoderError a
deserialiseFromCBOR AsType a
typeProxy)