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

module Main where

import Cardano.Ledger.Allegra (AllegraEra)
import Cardano.Ledger.Core
import Cardano.Ledger.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 = TPraos.TICKN

type instance EraRule "TICKN" AllegraEra = 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, EraStake era, ChainProperty era,
 HasTrace (CHAIN era) (GenEnv MockCrypto era)) =>
Int -> TestTree
ClassifyTraces.relevantCasesAreCovered @AllegraEra (Args -> Int
maxSuccess Args
stdArgs))
      )
    , forall era ledger.
(EraGen era, EraStake era, TestingLedger era ledger,
 ChainProperty era, HasTrace (CHAIN era) (GenEnv MockCrypto era),
 GovState era ~ ShelleyGovState era) =>
Int -> TestTree
AdaPreservation.tests @AllegraEra @(ShelleyLEDGER AllegraEra) (Args -> Int
maxSuccess Args
stdArgs)
    , forall era.
(EraGen era, EraGov era, EraStake era,
 HasTrace (CHAIN era) (GenEnv MockCrypto era)) =>
TestTree
ClassifyTraces.onlyValidChainSignalsAreGenerated @AllegraEra
    , TestTree
WitVKeys.tests
    , 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, EraStake era, ChainProperty era,
 HasTrace (CHAIN era) (GenEnv MockCrypto era),
 HasTrace ledger (GenEnv MockCrypto 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 @AllegraEra @(ShelleyLEDGER AllegraEra))
    , String -> [TestTree] -> TestTree
testGroup
        String
"Mary Ledger - nightly"
        (forall era ledger.
(EraGen era, EraStake era, ChainProperty era,
 HasTrace (CHAIN era) (GenEnv MockCrypto era),
 HasTrace ledger (GenEnv MockCrypto 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 @MaryEra @(ShelleyLEDGER MaryEra))
    ]