{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Ledger.Alonzo.Binary.CddlSpec (spec) where

import Cardano.Ledger.Allegra.Scripts
import Cardano.Ledger.Alonzo (AlonzoEra)
import Cardano.Ledger.Alonzo.Scripts (CostModels)
import Cardano.Ledger.Alonzo.TxWits (AlonzoTxWits, Redeemers)
import Cardano.Ledger.Core
import Cardano.Ledger.Plutus.Data (Data)
import Test.Cardano.Ledger.Alonzo.Binary.Cddl (readAlonzoCddlFiles)
import Test.Cardano.Ledger.Alonzo.CDDL (alonzoCDDL)
import Test.Cardano.Ledger.Binary.Cddl (
  beforeAllCddlFile,
  cddlRoundTripAnnCborSpec,
  cddlRoundTripCborSpec,
 )
import Test.Cardano.Ledger.Binary.Cuddle (
  huddleRoundTripAnnCborSpec,
  huddleRoundTripCborSpec,
  specWithHuddle,
 )
import Test.Cardano.Ledger.Common

spec :: Spec
spec :: Spec
spec =
  forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"CDDL" forall a b. (a -> b) -> a -> b
$ do
    let v :: Version
v = forall era. Era era => Version
eraProtVerHigh @AlonzoEra
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Ruby-based" forall a b. (a -> b) -> a -> b
$ HasCallStack => Int -> IO [ByteString] -> SpecWith CddlData -> Spec
beforeAllCddlFile Int
3 IO [ByteString]
readAlonzoCddlFiles forall a b. (a -> b) -> a -> b
$ do
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripCborSpec @(Value AlonzoEra) Version
v Text
"coin"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripAnnCborSpec @(TxBody AlonzoEra) Version
v Text
"transaction_body"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripAnnCborSpec @(TxAuxData AlonzoEra) Version
v Text
"auxiliary_data"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripAnnCborSpec @(Timelock AlonzoEra) Version
v Text
"native_script"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripAnnCborSpec @(Data AlonzoEra) Version
v Text
"plutus_data"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripCborSpec @(TxOut AlonzoEra) Version
v Text
"transaction_output"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripAnnCborSpec @(AlonzoTxWits AlonzoEra) Version
v Text
"transaction_witness_set"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripCborSpec @(PParamsUpdate AlonzoEra) Version
v Text
"protocol_param_update"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripAnnCborSpec @(Redeemers AlonzoEra) Version
v Text
"[* redeemer]"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripAnnCborSpec @(Tx AlonzoEra) Version
v Text
"transaction"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CddlData
cddlRoundTripCborSpec @CostModels Version
v Text
"cost_models"
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Huddle" forall a b. (a -> b) -> a -> b
$ Huddle -> Int -> SpecWith CuddleData -> Spec
specWithHuddle Huddle
alonzoCDDL Int
100 forall a b. (a -> b) -> a -> b
$ do
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripCborSpec @(Value AlonzoEra) Version
v Text
"coin"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripAnnCborSpec @(TxBody AlonzoEra) Version
v Text
"transaction_body"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripAnnCborSpec @(TxAuxData AlonzoEra) Version
v Text
"auxiliary_data"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripAnnCborSpec @(Timelock AlonzoEra) Version
v Text
"native_script"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripAnnCborSpec @(Data AlonzoEra) Version
v Text
"plutus_data"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripCborSpec @(TxOut AlonzoEra) Version
v Text
"transaction_output"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripAnnCborSpec @(AlonzoTxWits AlonzoEra) Version
v Text
"transaction_witness_set"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripCborSpec @(PParamsUpdate AlonzoEra) Version
v Text
"protocol_param_update"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripAnnCborSpec @(Redeemers AlonzoEra) Version
v Text
"redeemers"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripAnnCborSpec @(Tx AlonzoEra) Version
v Text
"transaction"
      forall a.
(HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) =>
Version -> Text -> SpecWith CuddleData
huddleRoundTripCborSpec @CostModels Version
v Text
"cost_models"