{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeApplications #-} module Test.Cardano.Ledger.Allegra.Translation ( allegraTranslationTests, allegraEncodeDecodeTests, ) where import Cardano.Ledger.Allegra (AllegraEra) import Cardano.Ledger.Binary (EncCBOR) import Cardano.Ledger.Core import Cardano.Ledger.Genesis (NoGenesis (..)) import Cardano.Ledger.Shelley (ShelleyEra) import qualified Cardano.Ledger.Shelley.API as S import Test.Cardano.Ledger.Binary.RoundTrip import Test.Cardano.Ledger.Mary.Binary.Annotator () import Test.Cardano.Ledger.Shelley.Generator.ShelleyEraGen () import Test.Cardano.Ledger.Shelley.Serialisation.Generators () import Test.Cardano.Ledger.TranslationTools (translateEraEncCBOR) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (Assertion) import Test.Tasty.QuickCheck (testProperty) allegraEncodeDecodeTests :: TestTree allegraEncodeDecodeTests :: TestTree allegraEncodeDecodeTests = String -> [TestTree] -> TestTree forall a. HasCallStack => String -> [SpecWith a] -> SpecWith a testGroup String "encoded shelley types can be decoded as allegra types" [ String -> (ShelleyTxAuxData ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "decoding auxiliary data (Annotator)" ( forall a b. (ToCBOR a, DecCBOR (Annotator b), HasCallStack) => Version -> Version -> (b -> a -> Assertion) -> a -> Assertion embedTripAnnExpectation @(TxAuxData ShelleyEra) @(TxAuxData AllegraEra) (forall era. Era era => Version eraProtVerLow @ShelleyEra) (forall era. Era era => Version eraProtVerLow @AllegraEra) (\TxAuxData AllegraEra _ TxAuxData ShelleyEra _ -> () -> Assertion forall a. a -> IO a forall (f :: * -> *) a. Applicative f => a -> f a pure ()) ) , String -> (ShelleyTxAuxData ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "decoding auxiliary data" ( forall a b. (Typeable b, Eq b, HasCallStack) => Version -> Version -> Trip a b -> (b -> a -> Assertion) -> a -> Assertion embedTripExpectation @(TxAuxData ShelleyEra) @(TxAuxData AllegraEra) (forall era. Era era => Version eraProtVerLow @ShelleyEra) (forall era. Era era => Version eraProtVerLow @AllegraEra) Trip (TxAuxData ShelleyEra) (TxAuxData AllegraEra) Trip (ShelleyTxAuxData ShelleyEra) (AllegraTxAuxData AllegraEra) forall a b. (EncCBOR a, DecCBOR b) => Trip a b cborTrip (\TxAuxData AllegraEra _ TxAuxData ShelleyEra _ -> () -> Assertion forall a. a -> IO a forall (f :: * -> *) a. Applicative f => a -> f a pure ()) ) ] allegraTranslationTests :: TestTree allegraTranslationTests :: TestTree allegraTranslationTests = String -> [TestTree] -> TestTree forall a. HasCallStack => String -> [SpecWith a] -> SpecWith a testGroup String "Allegra translation binary compatibiliby tests" [ String -> (Tx TopTx ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "Tx compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @(Tx TopTx)) , String -> (ProposedPPUpdates ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "ProposedPPUpdates compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.ProposedPPUpdates) , String -> (ShelleyGovState ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "ShelleyGovState compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.ShelleyGovState) , String -> (ShelleyTxOut ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "TxOut compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.ShelleyTxOut) , String -> (UTxO ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "UTxO compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.UTxO) , String -> (UTxOState ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "UTxOState compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.UTxOState) , String -> (LedgerState ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "LedgerState compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.LedgerState) , String -> (EpochState ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "EpochState compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.EpochState) , String -> (ShelleyTxWits ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "ShelleyTxWits compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.ShelleyTxWits) , String -> (Update ShelleyEra -> Assertion) -> TestTree forall prop. (HasCallStack, Testable prop) => String -> prop -> TestTree testProperty String "Update compatibility" (forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation @S.Update) ] testTranslation :: forall f. ( EncCBOR (f AllegraEra) , EncCBOR (f ShelleyEra) , TranslateEra AllegraEra f , Show (TranslationError AllegraEra f) ) => f ShelleyEra -> Assertion testTranslation :: forall (f :: * -> *). (EncCBOR (f AllegraEra), EncCBOR (f ShelleyEra), TranslateEra AllegraEra f, Show (TranslationError AllegraEra f)) => f ShelleyEra -> Assertion testTranslation = [AllegraEra] -> TranslationContext AllegraEra -> f (PreviousEra AllegraEra) -> Assertion forall (proxy :: * -> *) era (f :: * -> *). (HasCallStack, TranslateEra era f, EncCBOR (f era), EncCBOR (f (PreviousEra era)), Show (TranslationError era f)) => proxy era -> TranslationContext era -> f (PreviousEra era) -> Assertion translateEraEncCBOR ([] :: [AllegraEra]) TranslationContext AllegraEra NoGenesis AllegraEra forall era. NoGenesis era NoGenesis