{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

-- | Deserializes `TranslationInstance`s from golden/translations.cbor file.
--
-- Each instance represents arguments passed to `ExtendedUTxO.txInfo` along with the produced result.
-- This test checks that calling `alonzoTxInfo` with the arguments from this file, produces the same result as in the file.
--
-- To regenerate the golden file (for example, if the logic in the translation changes),
-- run the following command from the root of the repository:
-- cabal run cardano-ledger-alonzo:gen-golden"
module Test.Cardano.Ledger.Alonzo.GoldenTranslation (
  tests,
)
where

import Cardano.Ledger.Alonzo (AlonzoEra)
import Paths_cardano_ledger_alonzo (getDataFileName)
import Test.Cardano.Ledger.Alonzo.Translation.Golden (assertTranslationResultsMatchGolden)
import Test.Cardano.Ledger.Common
import Test.HUnit (Assertion)

tests :: Spec
tests :: Spec
tests =
  forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Golden translation tests" forall a b. (a -> b) -> a -> b
$ do
    forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"golden/translations.cbor" forall a b. (a -> b) -> a -> b
$
      String -> Assertion
goldenAssertion String
"golden/translations.cbor"

goldenAssertion :: String -> Assertion
goldenAssertion :: String -> Assertion
goldenAssertion String
file = forall era.
(TranslatableGen era, Show (ContextError era), HasCallStack) =>
IO String -> Assertion
assertTranslationResultsMatchGolden @AlonzoEra (String -> IO String
getDataFileName String
file)