{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}

module Byron.Spec.Ledger.Update.Test (
  coverUpiregFailures,
  coverUpivoteFailures,
)
where

import Byron.Spec.Ledger.Update
import Data.Data (Data)
import GHC.Stack (HasCallStack)
import Hedgehog (MonadTest)
import Hedgehog.Internal.Property (CoverPercentage)
import qualified Test.Control.State.Transition.Generator as Generator

-- | Check that all the relevant predicate failures are covered.
coverUpiregFailures ::
  forall m a.
  ( MonadTest m
  , HasCallStack
  , Data a
  ) =>
  -- | Minimum percentage that each failure must occur.
  CoverPercentage ->
  -- | Structure containing the failures
  a ->
  m ()
coverUpiregFailures :: forall (m :: * -> *) a.
(MonadTest m, HasCallStack, Data a) =>
CoverPercentage -> a -> m ()
coverUpiregFailures CoverPercentage
coverPercentage a
someData = do
  forall (m :: * -> *) s a.
(MonadTest m, HasCallStack, Data (PredicateFailure s), Data a) =>
CoverPercentage -> [PredicateFailure s] -> a -> m ()
Generator.coverFailures @_ @UPPVV
    CoverPercentage
coverPercentage
    [ UppvvPredicateFailure
CannotFollowPv
    , [UpdateConstraintViolation] -> UppvvPredicateFailure
CannotUpdatePv []
    , UppvvPredicateFailure
AlreadyProposedPv
    ]
    a
someData

  forall (m :: * -> *) s a.
(MonadTest m, HasCallStack, Data (PredicateFailure s), Data a) =>
CoverPercentage -> [PredicateFailure s] -> a -> m ()
Generator.coverFailures @_ @UPSVV
    CoverPercentage
coverPercentage
    [ UpsvvPredicateFailure
AlreadyProposedSv
    , UpsvvPredicateFailure
CannotFollowSv
    , UpsvvPredicateFailure
InvalidApplicationName
    , UpsvvPredicateFailure
InvalidSystemTags
    ]
    a
someData

  forall (m :: * -> *) s a.
(MonadTest m, HasCallStack, Data (PredicateFailure s), Data a) =>
CoverPercentage -> [PredicateFailure s] -> a -> m ()
Generator.coverFailures @_ @UPREG
    CoverPercentage
coverPercentage
    [ UpregPredicateFailure
NotGenesisDelegate
    , UpregPredicateFailure
DoesNotVerify
    ]
    a
someData

-- | See 'coverUpiregFailures'.
coverUpivoteFailures ::
  forall m a.
  ( MonadTest m
  , HasCallStack
  , Data a
  ) =>
  CoverPercentage ->
  a ->
  m ()
coverUpivoteFailures :: forall (m :: * -> *) a.
(MonadTest m, HasCallStack, Data a) =>
CoverPercentage -> a -> m ()
coverUpivoteFailures CoverPercentage
coverPercentage =
  forall (m :: * -> *) s a.
(MonadTest m, HasCallStack, Data (PredicateFailure s), Data a) =>
CoverPercentage -> [PredicateFailure s] -> a -> m ()
Generator.coverFailures @_ @ADDVOTE
    CoverPercentage
coverPercentage
    [ AddvotePredicateFailure
AVSigDoesNotVerify
    , UpId -> AddvotePredicateFailure
NoUpdateProposal (Int -> UpId
UpId Int
0) -- We need to pass a dummy update id here.
    ]