{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}

module Test.Gen.Cardano.Api.Byron
  ( tests
  )
where

import           Cardano.Api hiding (txIns)
import           Cardano.Api.Byron

import           Data.Proxy

import           Test.Gen.Cardano.Api.Typed

import           Hedgehog
import           Test.Hedgehog.Roundtrip.CBOR
import           Test.Tasty
import           Test.Tasty.Hedgehog

prop_byron_roundtrip_txbody_CBOR :: Property
prop_byron_roundtrip_txbody_CBOR :: Property
prop_byron_roundtrip_txbody_CBOR = HasCallStack => PropertyT IO () -> Property
PropertyT IO () -> Property
property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
forall a b. (a -> b) -> a -> b
$ do
  ATxAux ByteString
x <- Gen (ATxAux ByteString) -> PropertyT IO (ATxAux ByteString)
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll (Gen (ATxAux ByteString) -> PropertyT IO (ATxAux ByteString))
-> Gen (ATxAux ByteString) -> PropertyT IO (ATxAux ByteString)
forall a b. (a -> b) -> a -> b
$ [KeyWitness Any] -> Annotated Tx ByteString -> ATxAux ByteString
forall era.
[KeyWitness era] -> Annotated Tx ByteString -> ATxAux ByteString
makeSignedByronTransaction [] (Annotated Tx ByteString -> ATxAux ByteString)
-> GenT Identity (Annotated Tx ByteString)
-> Gen (ATxAux ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity (Annotated Tx ByteString)
HasCallStack => GenT Identity (Annotated Tx ByteString)
genTxBodyByron
  ATxAux ByteString
-> (ATxAux ByteString -> TextEnvelope)
-> (TextEnvelope
    -> Either TextEnvelopeCddlError (ATxAux ByteString))
-> 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 ()
tripping ATxAux ByteString
x ATxAux ByteString -> TextEnvelope
serializeByronTx TextEnvelope -> Either TextEnvelopeCddlError (ATxAux ByteString)
deserialiseByronTxCddl

prop_byron_roundtrip_witness_CBOR :: Property
prop_byron_roundtrip_witness_CBOR :: Property
prop_byron_roundtrip_witness_CBOR = HasCallStack => PropertyT IO () -> Property
PropertyT IO () -> Property
property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
forall a b. (a -> b) -> a -> b
$ do
  let byron :: CardanoEra ByronEra
byron = CardanoEra ByronEra
ByronEra
  KeyWitness ByronEra
x <- Gen (KeyWitness ByronEra) -> PropertyT IO (KeyWitness ByronEra)
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll Gen (KeyWitness ByronEra)
genByronKeyWitness
  CardanoEra ByronEra
-> (CardanoEraConstraints ByronEra => PropertyT IO ())
-> PropertyT IO ()
forall era a.
CardanoEra era -> (CardanoEraConstraints era => a) -> a
cardanoEraConstraints CardanoEra ByronEra
byron ((CardanoEraConstraints ByronEra => PropertyT IO ())
 -> PropertyT IO ())
-> (CardanoEraConstraints ByronEra => PropertyT IO ())
-> PropertyT IO ()
forall a b. (a -> b) -> a -> b
$ AsType (KeyWitness ByronEra)
-> KeyWitness ByronEra -> PropertyT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTest m, Show a, Eq a, SerialiseAsCBOR a) =>
AsType a -> a -> m ()
trippingCbor (AsType ByronEra -> AsType (KeyWitness ByronEra)
forall era. AsType era -> AsType (KeyWitness era)
AsKeyWitness (Proxy ByronEra -> AsType ByronEra
forall t. HasTypeProxy t => Proxy t -> AsType t
proxyToAsType Proxy ByronEra
forall {k} (t :: k). Proxy t
Proxy)) KeyWitness ByronEra
x

prop_byron_roundtrip_Tx_Cddl :: Property
prop_byron_roundtrip_Tx_Cddl :: Property
prop_byron_roundtrip_Tx_Cddl = HasCallStack => PropertyT IO () -> Property
PropertyT IO () -> Property
property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
forall a b. (a -> b) -> a -> b
$ do
  ATxAux ByteString
x <- Gen (ATxAux ByteString) -> PropertyT IO (ATxAux ByteString)
forall (m :: * -> *) a.
(Monad m, Show a, HasCallStack) =>
Gen a -> PropertyT m a
forAll Gen (ATxAux ByteString)
genTxByron
  ATxAux ByteString
-> (ATxAux ByteString -> TextEnvelope)
-> (TextEnvelope
    -> Either TextEnvelopeCddlError (ATxAux ByteString))
-> 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 ()
tripping ATxAux ByteString
x ATxAux ByteString -> TextEnvelope
serializeByronTx TextEnvelope -> Either TextEnvelopeCddlError (ATxAux ByteString)
deserialiseByronTxCddl

tests :: TestTree
tests :: TestTree
tests =
  TestName -> [TestTree] -> TestTree
testGroup
    TestName
"Test.Gen.Cardano.Api.Byron"
    [ TestName -> Property -> TestTree
testProperty TestName
"Byron roundtrip txbody CBOR" Property
prop_byron_roundtrip_txbody_CBOR
    , TestName -> Property -> TestTree
testProperty TestName
"Byron roundtrip witness CBOR" Property
prop_byron_roundtrip_witness_CBOR
    , TestName -> Property -> TestTree
testProperty TestName
"Byron roundtrip tx CBOR" Property
prop_byron_roundtrip_Tx_Cddl
    ]