{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Protocol.Binary.BinarySpec (spec) where

import Cardano.Ledger.Allegra (AllegraEra)
import Cardano.Ledger.Alonzo (AlonzoEra)
import Cardano.Ledger.Block
import Cardano.Ledger.Core
import Cardano.Ledger.Mary (MaryEra)
import Cardano.Ledger.Shelley (ShelleyEra)
import Cardano.Protocol.Crypto
import Cardano.Protocol.TPraos.BHeader (BHeader)
import Data.Proxy
import Data.Typeable (typeRep)
import Test.Cardano.Ledger.Allegra.Arbitrary ()
import Test.Cardano.Ledger.Alonzo.Arbitrary ()
import Test.Cardano.Ledger.Binary (decoderEquivalenceProp, decoderEquivalenceSpec)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Mary.Arbitrary ()
import Test.Cardano.Protocol.TPraos.Arbitrary ()

spec :: Spec
spec :: Spec
spec = do
  forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"DecCBOR instances equivalence" forall a b. (a -> b) -> a -> b
$ do
    forall t.
(Eq t, ToCBOR t, DecCBOR (Annotator t), Arbitrary t, Show t) =>
Version -> Version -> Spec
decoderEquivalenceSpec @(BHeader StandardCrypto) forall a. Bounded a => a
minBound forall a. Bounded a => a
maxBound
    forall era. (EraSegWits era, Arbitrary (Tx era)) => Spec
blockEraSpec @ShelleyEra
    forall era. (EraSegWits era, Arbitrary (Tx era)) => Spec
blockEraSpec @AllegraEra
    forall era. (EraSegWits era, Arbitrary (Tx era)) => Spec
blockEraSpec @MaryEra
    forall era. (EraSegWits era, Arbitrary (Tx era)) => Spec
blockEraSpec @AlonzoEra

blockEraSpec ::
  forall era.
  ( EraSegWits era
  , Arbitrary (Tx era)
  ) =>
  Spec
blockEraSpec :: forall era. (EraSegWits era, Arbitrary (Tx era)) => Spec
blockEraSpec =
  forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop (forall a. Show a => a -> String
show (forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @(Block (BHeader StandardCrypto) era))) forall a b. (a -> b) -> a -> b
$
    forall prop. Testable prop => Int -> prop -> Property
withMaxSuccess Int
3 forall a b. (a -> b) -> a -> b
$
      forall t.
(Eq t, ToCBOR t, DecCBOR (Annotator t), Show t) =>
Version -> Version -> t -> Property
decoderEquivalenceProp @(Block (BHeader StandardCrypto) era)
        (forall era. Era era => Version
eraProtVerLow @era)
        (forall era. Era era => Version
eraProtVerHigh @era)