{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Main where

import Cardano.Ledger.Allegra (Allegra, AllegraEra)
import Cardano.Ledger.Core
import Cardano.Ledger.Mary (Mary, MaryEra)
import Cardano.Ledger.Shelley.Rules (ShelleyLEDGER)
import qualified Cardano.Protocol.TPraos.Rules.Tickn as TPraos
import System.Environment (lookupEnv)
import Test.Cardano.Ledger.Allegra.ScriptTranslation (testScriptPostTranslation)
import Test.Cardano.Ledger.Allegra.Translation (allegraTranslationTests)
import Test.Cardano.Ledger.AllegraEraGen ()
import Test.Cardano.Ledger.Mary.Examples.MultiAssets (multiAssetsExample)
import Test.Cardano.Ledger.Mary.Golden (goldenScaledMinDeposit)
import Test.Cardano.Ledger.Mary.Translation (maryTranslationTests)
import Test.Cardano.Ledger.Mary.Value (valTests)
import Test.Cardano.Ledger.MaryEraGen ()
import qualified Test.Cardano.Ledger.Shelley.PropertyTests as Shelley (commonTests)
import qualified Test.Cardano.Ledger.Shelley.Rules.AdaPreservation as AdaPreservation
import qualified Test.Cardano.Ledger.Shelley.Rules.ClassifyTraces as ClassifyTraces (
  onlyValidChainSignalsAreGenerated,
  relevantCasesAreCovered,
 )
import qualified Test.Cardano.Ledger.Shelley.WitVKeys as WitVKeys (tests)
import qualified Test.Cardano.Ledger.ShelleyMA.Serialisation as Serialisation
import Test.QuickCheck (Args (maxSuccess), stdArgs)
import Test.Tasty
import qualified Test.Tasty.QuickCheck as TQC

type instance EraRule "TICKN" (MaryEra _c) = TPraos.TICKN

type instance EraRule "TICKN" (AllegraEra _c) = TPraos.TICKN

main :: IO ()
IO ()
main = do
  Maybe String
nightly <- String -> IO (Maybe String)
lookupEnv String
"NIGHTLY"
  TestTree -> IO ()
defaultMain forall a b. (a -> b) -> a -> b
$ case Maybe String
nightly of
    Maybe String
Nothing -> TestTree
defaultTests
    Just String
_ -> TestTree
nightlyTests

defaultTests :: TestTree
defaultTests :: TestTree
defaultTests =
  String -> [TestTree] -> TestTree
testGroup
    String
"ShelleyMA Ledger Tests"
    [ TestTree
allegraTests
    , TestTree
maryTests
    , String -> [TestTree] -> TestTree
testGroup
        String
"Mixed MA Ledger Tests"
        [ TestTree
Serialisation.tests
        ]
    ]

allegraTests :: TestTree
allegraTests :: TestTree
allegraTests =
  String -> [TestTree] -> TestTree
testGroup
    String
"Allegra Ledger Tests"
    [ TestTree
allegraTranslationTests
    , ( forall v. IsOption v => v -> TestTree -> TestTree
localOption
          (Int -> QuickCheckMaxRatio
TQC.QuickCheckMaxRatio Int
50)
          (forall era.
(EraGen era, ChainProperty era,
 HasTrace (CHAIN era) (GenEnv era)) =>
Int -> TestTree
ClassifyTraces.relevantCasesAreCovered @Allegra (Args -> Int
maxSuccess Args
stdArgs))
      )
    , forall era ledger.
(EraGen era, TestingLedger era ledger, ChainProperty era,
 HasTrace (CHAIN era) (GenEnv era),
 GovState era ~ ShelleyGovState era) =>
Int -> TestTree
AdaPreservation.tests @Allegra @(ShelleyLEDGER Allegra) (Args -> Int
maxSuccess Args
stdArgs)
    , forall era.
(EraGen era, HasTrace (CHAIN era) (GenEnv era), EraGov era) =>
TestTree
ClassifyTraces.onlyValidChainSignalsAreGenerated @Allegra
    , forall c.
(Crypto c, DSignable c (Hash c EraIndependentTxBody)) =>
TestTree
WitVKeys.tests @(EraCrypto Allegra)
    , TestTree
testScriptPostTranslation
    ]

maryTests :: TestTree
maryTests :: TestTree
maryTests =
  String -> [TestTree] -> TestTree
testGroup
    String
"Mary Ledger Tests"
    [ TestTree
maryTranslationTests
    , TestTree
valTests
    , TestTree
multiAssetsExample
    , TestTree
goldenScaledMinDeposit
    ]

nightlyTests :: TestTree
nightlyTests :: TestTree
nightlyTests =
  String -> [TestTree] -> TestTree
testGroup
    String
"ShelleyMA Ledger - nightly"
    [ String -> [TestTree] -> TestTree
testGroup
        String
"Allegra Ledger - nightly"
        (forall era ledger.
(EraGen era, ChainProperty era, HasTrace (CHAIN era) (GenEnv era),
 HasTrace ledger (GenEnv era), Embed (EraRule "DELEGS" era) ledger,
 Embed (EraRule "UTXOW" era) ledger,
 Environment ledger ~ LedgerEnv era, BaseEnv ledger ~ Globals,
 BaseM ledger ~ ReaderT Globals Identity,
 State ledger ~ LedgerState era, Signal ledger ~ Tx era,
 GovState era ~ ShelleyGovState era) =>
[TestTree]
Shelley.commonTests @Allegra @(ShelleyLEDGER Allegra))
    , String -> [TestTree] -> TestTree
testGroup
        String
"Mary Ledger - nightly"
        (forall era ledger.
(EraGen era, ChainProperty era, HasTrace (CHAIN era) (GenEnv era),
 HasTrace ledger (GenEnv era), Embed (EraRule "DELEGS" era) ledger,
 Embed (EraRule "UTXOW" era) ledger,
 Environment ledger ~ LedgerEnv era, BaseEnv ledger ~ Globals,
 BaseM ledger ~ ReaderT Globals Identity,
 State ledger ~ LedgerState era, Signal ledger ~ Tx era,
 GovState era ~ ShelleyGovState era) =>
[TestTree]
Shelley.commonTests @Mary @(ShelleyLEDGER Mary))
    ]