{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.Core.Arbitrary (
  module Test.Cardano.Ledger.Binary.Arbitrary,
  genAddrBadPtr,
  genCompactAddrBadPtr,
  genBadPtr,
  genValidUMap,
  genValidUMapNonEmpty,
  genValidUMapWithCreds,
  genValidTuples,
  genValidTuplesNonEmpty,
  genInvariantNonEmpty,
  genRightPreferenceUMap,
  genInsertDeleteRoundtripRDPair,
  genInsertDeleteRoundtripPtr,
  genInsertDeleteRoundtripSPool,
  genInsertDeleteRoundtripDRep,

  -- * Plutus
  genValidAndUnknownCostModels,
  genValidCostModel,
  genValidCostModels,

  -- * Utils

  -- | Will need to find a better home in the future
  uniformSubSet,
  uniformSubMap,
  uniformSubMapElems,
)
where

import qualified Cardano.Chain.Common as Byron
import Cardano.Crypto.Hash.Class
import Cardano.Ledger.Address
import Cardano.Ledger.BaseTypes (
  ActiveSlotCoeff,
  BlocksMade (..),
  CertIx (..),
  DnsName,
  EpochInterval (..),
  Mismatch (..),
  Network (..),
  NonNegativeInterval,
  Nonce (..),
  Port (..),
  PositiveInterval,
  PositiveUnitInterval,
  ProtVer (..),
  SlotNo (..),
  StrictMaybe,
  TxIx (..),
  UnitInterval,
  Url,
  mkActiveSlotCoeff,
  mkCertIxPartial,
  mkNonceFromNumber,
  mkTxIxPartial,
  natVersion,
  promoteRatio,
  textToDns,
  textToUrl,
 )
import Cardano.Ledger.Binary (EncCBOR, Sized, mkSized)
import Cardano.Ledger.CertState (
  Anchor (..),
  CertState (..),
  CommitteeAuthorization (..),
  CommitteeState (..),
  DState (..),
  FutureGenDeleg (..),
  InstantaneousRewards (..),
  PState (..),
  VState (..),
 )
import Cardano.Ledger.Coin (Coin (..), CompactForm (..), DeltaCoin (..))
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential (..), Ptr (..), StakeReference (..))
import Cardano.Ledger.DRep (DRep (..), DRepState (..))
import Cardano.Ledger.EpochBoundary
import Cardano.Ledger.HKD (NoUpdate (..))
import Cardano.Ledger.Hashes (GenDelegPair (..), GenDelegs (..), unsafeMakeSafeHash)
import Cardano.Ledger.Keys (BootstrapWitness (..), ChainCode (..), VKey (..), WitVKey (..))
import Cardano.Ledger.Plutus.CostModels (
  CostModel,
  CostModels,
  costModelParamsCount,
  mkCostModel,
  mkCostModels,
  mkCostModelsLenient,
  updateCostModels,
 )
import Cardano.Ledger.Plutus.ExUnits (ExUnits (..), Prices (..))
import Cardano.Ledger.Plutus.Language (Language (..), nonNativeLanguages)
import Cardano.Ledger.PoolDistr (IndividualPoolStake (..), PoolDistr (..))
import Cardano.Ledger.PoolParams (
  PoolMetadata (..),
  PoolParams (..),
  SizeOfPoolOwners (..),
  SizeOfPoolRelays (..),
  StakePoolRelay (..),
 )
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
import Cardano.Ledger.UMap (
  RDPair (..),
  UMElem (UMElem),
  UMap (UMap, umElems, umPtrs),
  UView (RewDepUView),
  unUnify,
  unify,
 )
import Cardano.Ledger.UTxO (UTxO (..))
import Control.Monad (replicateM)
import Control.Monad.Identity (Identity)
import Control.Monad.Trans.Fail.String (errorFail)
import Data.GenValidity
import Data.Int (Int64)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Ratio ((%))
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Text as T
import Data.Typeable
import qualified Data.VMap as VMap
import Data.Word (Word16, Word32, Word64, Word8)
import GHC.Stack
import Generic.Random (genericArbitraryU)
import System.Random.Stateful (StatefulGen, uniformRM)
import qualified Test.Cardano.Chain.Common.Gen as Byron
import Test.Cardano.Ledger.Binary.Arbitrary
import Test.Cardano.Ledger.Binary.Random (QC (..))
import Test.Cardano.Ledger.Core.Utils (unsafeBoundRational)
import Test.QuickCheck
import Test.QuickCheck.Hedgehog (hedgehog)

maxDecimalsWord64 :: Int
maxDecimalsWord64 :: Int
maxDecimalsWord64 = Int
19

instance (Era era, EncCBOR (f era), Arbitrary (f era)) => Arbitrary (Sized (f era)) where
  arbitrary :: Gen (Sized (f era))
arbitrary = forall a. EncCBOR a => Version -> a -> Sized a
mkSized (forall era. Era era => Version
eraProtVerHigh @era) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

------------------------------------------------------------------------------------------
-- Cardano.Ledger.BaseTypes --------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary ActiveSlotCoeff where
  arbitrary :: Gen ActiveSlotCoeff
arbitrary = PositiveUnitInterval -> ActiveSlotCoeff
mkActiveSlotCoeff forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Validity ActiveSlotCoeff where
  validate :: ActiveSlotCoeff -> Validation
validate ActiveSlotCoeff
_ = forall a. Monoid a => a
mempty

instance GenValid ActiveSlotCoeff where
  genValid :: Gen ActiveSlotCoeff
genValid = PositiveUnitInterval -> ActiveSlotCoeff
mkActiveSlotCoeff forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. GenValid a => Gen a
genValid

instance Arbitrary BlocksMade where
  arbitrary :: Gen BlocksMade
arbitrary = Map (KeyHash 'StakePool) Nat -> BlocksMade
BlocksMade forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary Network where
  arbitrary :: Gen Network
arbitrary = forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum

genDnsName :: Int -> Gen T.Text
genDnsName :: Int -> Gen Text
genDnsName Int
n = do
  [Char]
str <- forall a. Int -> Gen a -> Gen [a]
vectorOf (Int
n forall a. Num a => a -> a -> a
- Int
4) forall a b. (a -> b) -> a -> b
$ forall a. HasCallStack => [a] -> Gen a
elements forall a b. (a -> b) -> a -> b
$ Char
'.' forall a. a -> [a] -> [a]
: Char
'-' forall a. a -> [a] -> [a]
: [Char
'A' .. Char
'Z'] forall a. [a] -> [a] -> [a]
++ [Char
'a' .. Char
'z'] forall a. [a] -> [a] -> [a]
++ [Char
'0' .. Char
'9']
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
str forall a. Semigroup a => a -> a -> a
<> Text
".com"

guardLength :: HasCallStack => Int -> T.Text -> Maybe a -> a
guardLength :: forall a. HasCallStack => Int -> Text -> Maybe a -> a
guardLength Int
n Text
txt = \case
  Maybe a
Nothing -> forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"Unexpected! Generated length: (" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Int
n forall a. [a] -> [a] -> [a]
++ [Char]
") " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Text
txt
  Just a
t -> a
t

instance Arbitrary DnsName where
  arbitrary :: Gen DnsName
arbitrary = do
    Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
5, Int
64)
    Text
txt <- Int -> Gen Text
genDnsName Int
n
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$! forall a. HasCallStack => Int -> Text -> Maybe a -> a
guardLength Int
n Text
txt forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadFail m => Int -> Text -> m DnsName
textToDns Int
64 Text
txt

instance Arbitrary Url where
  arbitrary :: Gen Url
arbitrary = do
    let prefix :: Text
prefix = Text
"https://"
    Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
5, Int
64 forall a. Num a => a -> a -> a
- Text -> Int
T.length Text
prefix)
    Text
txt <- Int -> Gen Text
genDnsName Int
n
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$! forall a. HasCallStack => Int -> Text -> Maybe a -> a
guardLength Int
n Text
txt forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadFail m => Int -> Text -> m Url
textToUrl Int
64 (Text
prefix forall a. Semigroup a => a -> a -> a
<> Text
txt)

instance Arbitrary Port where
  arbitrary :: Gen Port
arbitrary = forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word16 @Port forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

-- JSON instances can't roundtrip, unless these are decimal.

-- | Decimal numbers only
instance Arbitrary UnitInterval where
  arbitrary :: Gen UnitInterval
arbitrary = do
    Int
p <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
maxDecimalsWord64)
    let y :: Word64
y = Word64
10 forall a b. (Num a, Integral b) => a -> b -> a
^ Int
p :: Word64
    Word64
x <- forall a. Random a => (a, a) -> Gen a
choose (Word64
0, Word64
y)
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)

-- | Decimal numbers only
instance Arbitrary PositiveUnitInterval where
  arbitrary :: Gen PositiveUnitInterval
arbitrary = do
    Int
p <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
maxDecimalsWord64)
    let y :: Word64
y = Word64
10 forall a b. (Num a, Integral b) => a -> b -> a
^ Int
p :: Word64
    Word64
x <- forall a. Random a => (a, a) -> Gen a
choose (Word64
1, Word64
y)
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)

-- | Decimal numbers only
instance Arbitrary PositiveInterval where
  arbitrary :: Gen PositiveInterval
arbitrary = do
    Int
p <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
maxDecimalsWord64)
    let y :: Word64
y = Word64
10 forall a b. (Num a, Integral b) => a -> b -> a
^ Int
p :: Word64
    Word64
x <- forall a. Random a => (a, a) -> Gen a
choose (Word64
1, Word64
10 forall a b. (Num a, Integral b) => a -> b -> a
^ (Int
maxDecimalsWord64 :: Int))
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)

-- | Decimal numbers only
instance Arbitrary NonNegativeInterval where
  arbitrary :: Gen NonNegativeInterval
arbitrary = do
    Int
p <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
maxDecimalsWord64)
    let y :: Word64
y = Word64
10 forall a b. (Num a, Integral b) => a -> b -> a
^ Int
p :: Word64
    Word64
x <- forall a. Random a => (a, a) -> Gen a
choose (Word64
0, Word64
10 forall a b. (Num a, Integral b) => a -> b -> a
^ (Int
maxDecimalsWord64 :: Int))
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)

instance Arbitrary (NoUpdate a) where
  arbitrary :: Gen (NoUpdate a)
arbitrary = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. NoUpdate a
NoUpdate

instance Validity UnitInterval where
  validate :: UnitInterval -> Validation
validate UnitInterval
_ = forall a. Monoid a => a
mempty

instance GenValid UnitInterval where
  genValid :: Gen UnitInterval
genValid = do
    Word64
x :: Word64 <- forall a. GenValid a => Gen a
genValid
    Positive (Word64
y :: Word64) <- forall a. Arbitrary a => Gen a
arbitrary
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (if Word64
x forall a. Ord a => a -> a -> Bool
> Word64
y then Word64
y forall a. Integral a => a -> a -> Ratio a
% Word64
x else Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)
  shrinkValid :: UnitInterval -> [UnitInterval]
shrinkValid UnitInterval
_ = []

instance Validity PositiveUnitInterval where
  validate :: PositiveUnitInterval -> Validation
validate PositiveUnitInterval
_ = forall a. Monoid a => a
mempty

instance GenValid PositiveUnitInterval where
  genValid :: Gen PositiveUnitInterval
genValid = do
    Positive (Word64
x :: Word64) <- forall a. Arbitrary a => Gen a
arbitrary
    Positive (Word64
y :: Word64) <- forall a. Arbitrary a => Gen a
arbitrary
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (if Word64
x forall a. Ord a => a -> a -> Bool
> Word64
y then Word64
y forall a. Integral a => a -> a -> Ratio a
% Word64
x else Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)
  shrinkValid :: PositiveUnitInterval -> [PositiveUnitInterval]
shrinkValid PositiveUnitInterval
_ = []

instance Validity PositiveInterval where
  validate :: PositiveInterval -> Validation
validate PositiveInterval
_ = forall a. Monoid a => a
mempty

instance GenValid PositiveInterval where
  genValid :: Gen PositiveInterval
genValid = do
    Positive (Word64
x :: Word64) <- forall a. Arbitrary a => Gen a
arbitrary
    Positive (Word64
y :: Word64) <- forall a. Arbitrary a => Gen a
arbitrary
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)
  shrinkValid :: PositiveInterval -> [PositiveInterval]
shrinkValid PositiveInterval
_ = []

instance Validity NonNegativeInterval where
  validate :: NonNegativeInterval -> Validation
validate NonNegativeInterval
_ = forall a. Monoid a => a
mempty

instance GenValid NonNegativeInterval where
  genValid :: Gen NonNegativeInterval
genValid = do
    Word64
x :: Word64 <- forall a. GenValid a => Gen a
genValid
    Positive (Word64
y :: Word64) <- forall a. Arbitrary a => Gen a
arbitrary
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ forall a. Integral a => Ratio a -> Rational
promoteRatio (Word64
x forall a. Integral a => a -> a -> Ratio a
% Word64
y)
  shrinkValid :: NonNegativeInterval -> [NonNegativeInterval]
shrinkValid NonNegativeInterval
_ = []

instance Arbitrary TxIx where
  -- starting with Conway, we only deserialize TxIx within Word16 range
  arbitrary :: Gen TxIx
arbitrary = Word64 -> TxIx
TxIx forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary @Word16

instance Arbitrary CertIx where
  -- starting with Conway, we only deserialize CertIx within Word16 range
  arbitrary :: Gen CertIx
arbitrary = Word64 -> CertIx
CertIx forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary @Word16

instance Arbitrary ProtVer where
  arbitrary :: Gen ProtVer
arbitrary = Version -> Nat -> ProtVer
ProtVer forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary Nonce where
  arbitrary :: Gen Nonce
arbitrary =
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ forall (m :: * -> *) a. Monad m => a -> m a
return Nonce
NeutralNonce
      , Word64 -> Nonce
mkNonceFromNumber forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      ]

instance Arbitrary EpochInterval where
  arbitrary :: Gen EpochInterval
arbitrary = Word32 -> EpochInterval
EpochInterval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

------------------------------------------------------------------------------------------
-- Cardano.Ledger.TxIn -------------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary TxId where
  arbitrary :: Gen TxId
arbitrary = SafeHash EraIndependentTxBody -> TxId
TxId forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary TxIn where
  arbitrary :: Gen TxIn
arbitrary = TxId -> TxIx -> TxIn
TxIn forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Credential --------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary Ptr where
  arbitrary :: Gen Ptr
arbitrary = Gen Ptr
genValidPtr

-- | Generate a Ptr that contains values that are allowed on the wire
genValidPtr :: Gen Ptr
genValidPtr :: Gen Ptr
genValidPtr =
  SlotNo -> TxIx -> CertIx -> Ptr
Ptr
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Word64 -> SlotNo
SlotNo forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (Integral a, Num b) => a -> b
fromIntegral :: Word32 -> Word64) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (HasCallStack => Integer -> TxIx
mkTxIxPartial forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. Arbitrary a => Gen a
arbitrary :: Gen Word16))
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (HasCallStack => Integer -> CertIx
mkCertIxPartial forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. Arbitrary a => Gen a
arbitrary :: Gen Word16))

-- | Generate a Ptr with full 64bit range for values. Not allowed starting in Babbage
genBadPtr :: Gen Ptr
genBadPtr :: Gen Ptr
genBadPtr = SlotNo -> TxIx -> CertIx -> Ptr
Ptr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary (Credential r) where
  arbitrary :: Gen (Credential r)
arbitrary =
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ forall (kr :: KeyRole). ScriptHash -> Credential kr
ScriptHashObj forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      , forall (kr :: KeyRole). KeyHash kr -> Credential kr
KeyHashObj forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      ]

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Hashes -----------------------------------------------------------------
------------------------------------------------------------------------------------------

genHash :: forall h a. HashAlgorithm h => Gen (Hash h a)
genHash :: forall h a. HashAlgorithm h => Gen (Hash h a)
genHash = forall h a. HashAlgorithm h => ShortByteString -> Hash h a
UnsafeHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen ShortByteString
genShortByteString (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall h (proxy :: * -> *). HashAlgorithm h => proxy h -> Word
sizeHash (forall {k} (t :: k). Proxy t
Proxy @h)))

instance Arbitrary (SafeHash i) where
  arbitrary :: Gen (SafeHash i)
arbitrary = forall i. Hash HASH i -> SafeHash i
unsafeMakeSafeHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall h a. HashAlgorithm h => Gen (Hash h a)
genHash

instance Arbitrary ScriptHash where
  arbitrary :: Gen ScriptHash
arbitrary = Hash ADDRHASH EraIndependentScript -> ScriptHash
ScriptHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall h a. HashAlgorithm h => Gen (Hash h a)
genHash

------------------------------------------------------------------------------------------
-- Cardano.Ledger.AuxiliaryDataHash ------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary TxAuxDataHash where
  arbitrary :: Gen TxAuxDataHash
arbitrary = SafeHash EraIndependentTxAuxData -> TxAuxDataHash
TxAuxDataHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Keys -------------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary (KeyHash r) where
  arbitrary :: Gen (KeyHash r)
arbitrary = forall (r :: KeyRole).
Hash ADDRHASH (VerKeyDSIGN DSIGN) -> KeyHash r
KeyHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall h a. HashAlgorithm h => Gen (Hash h a)
genHash

instance Arbitrary (VRFVerKeyHash r) where
  arbitrary :: Gen (VRFVerKeyHash r)
arbitrary = forall (r :: KeyRoleVRF). Hash HASH KeyRoleVRF -> VRFVerKeyHash r
VRFVerKeyHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall h a. HashAlgorithm h => Gen (Hash h a)
genHash

instance Arbitrary (VKey kd) where
  arbitrary :: Gen (VKey kd)
arbitrary = forall (kd :: KeyRole). VerKeyDSIGN DSIGN -> VKey kd
VKey forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Typeable kr => Arbitrary (WitVKey kr) where
  arbitrary :: Gen (WitVKey kr)
arbitrary = forall (kr :: KeyRole).
Typeable kr =>
VKey kr
-> SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody) -> WitVKey kr
WitVKey forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary ChainCode where
  arbitrary :: Gen ChainCode
arbitrary = ByteString -> ChainCode
ChainCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary BootstrapWitness where
  arbitrary :: Gen BootstrapWitness
arbitrary = do
    VKey 'Witness
bwKey <- forall a. Arbitrary a => Gen a
arbitrary
    SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody)
bwSig <- forall a. Arbitrary a => Gen a
arbitrary
    ChainCode
bwChainCode <- forall a. Arbitrary a => Gen a
arbitrary
    ByteString
bwAttributes <- forall a. Arbitrary a => Gen a
arbitrary
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ BootstrapWitness {VKey 'Witness
bwKey :: VKey 'Witness
bwKey :: VKey 'Witness
bwKey, SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody)
bwSig :: SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody)
bwSig :: SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody)
bwSig, ChainCode
bwChainCode :: ChainCode
bwChainCode :: ChainCode
bwChainCode, ByteString
bwAttributes :: ByteString
bwAttributes :: ByteString
bwAttributes}

instance Arbitrary GenDelegPair where
  arbitrary :: Gen GenDelegPair
arbitrary = KeyHash 'GenesisDelegate
-> VRFVerKeyHash 'GenDelegVRF -> GenDelegPair
GenDelegPair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

deriving instance Arbitrary GenDelegs

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Coin -------------------------------------------------------------------
------------------------------------------------------------------------------------------
deriving instance Arbitrary (CompactForm Coin)

instance Arbitrary Coin where
  -- Cannot be negative even though it is an 'Integer'
  arbitrary :: Gen Coin
arbitrary = Integer -> Coin
Coin forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Random a => (a, a) -> Gen a
choose (Integer
0, Integer
1000000)
  shrink :: Coin -> [Coin]
shrink (Coin Integer
i) = Integer -> Coin
Coin forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
shrink Integer
i

instance Arbitrary DeltaCoin where
  arbitrary :: Gen DeltaCoin
arbitrary = Integer -> DeltaCoin
DeltaCoin forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Random a => (a, a) -> Gen a
choose (-Integer
1000000, Integer
1000000)
  shrink :: DeltaCoin -> [DeltaCoin]
shrink (DeltaCoin Integer
i) = Integer -> DeltaCoin
DeltaCoin forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => a -> [a]
shrink Integer
i

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Address ----------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary BootstrapAddress where
  arbitrary :: Gen BootstrapAddress
arbitrary = Address -> BootstrapAddress
BootstrapAddress forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Gen a -> Gen a
hedgehog Gen Address
Byron.genAddress

instance Arbitrary Byron.Address where
  arbitrary :: Gen Address
arbitrary = forall a. Gen a -> Gen a
hedgehog Gen Address
Byron.genAddress

instance Arbitrary Byron.AddrAttributes where
  arbitrary :: Gen AddrAttributes
arbitrary = forall a. Gen a -> Gen a
hedgehog Gen AddrAttributes
Byron.genAddrAttributes

instance Arbitrary (Byron.Attributes Byron.AddrAttributes) where
  arbitrary :: Gen (Attributes AddrAttributes)
arbitrary = forall a. Gen a -> Gen a
hedgehog forall a b. (a -> b) -> a -> b
$ forall a. Gen a -> Gen (Attributes a)
Byron.genAttributes Gen AddrAttributes
Byron.genAddrAttributes

instance Arbitrary Addr where
  arbitrary :: Gen Addr
arbitrary = Gen Ptr -> Gen Addr
genAddrWith forall a. Arbitrary a => Gen a
arbitrary
  shrink :: Addr -> [Addr]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

genAddrWith :: Gen Ptr -> Gen Addr
genAddrWith :: Gen Ptr -> Gen Addr
genAddrWith Gen Ptr
genPtr =
  forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency
    [ (Int
8, Network -> PaymentCredential -> StakeReference -> Addr
Addr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Ptr -> Gen StakeReference
genStakeRefWith Gen Ptr
genPtr)
    , (Int
2, BootstrapAddress -> Addr
AddrBootstrap forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary)
    ]

genAddrBadPtr :: Gen Addr
genAddrBadPtr :: Gen Addr
genAddrBadPtr = Gen Ptr -> Gen Addr
genAddrWith Gen Ptr
genBadPtr

genCompactAddrBadPtr :: Gen CompactAddr
genCompactAddrBadPtr :: Gen CompactAddr
genCompactAddrBadPtr = Addr -> CompactAddr
compactAddr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Addr
genAddrBadPtr

instance Arbitrary CompactAddr where
  arbitrary :: Gen CompactAddr
arbitrary = Addr -> CompactAddr
compactAddr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary StakeReference where
  arbitrary :: Gen StakeReference
arbitrary = Gen Ptr -> Gen StakeReference
genStakeRefWith forall a. Arbitrary a => Gen a
arbitrary
  shrink :: StakeReference -> [StakeReference]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

genStakeRefWith :: Gen Ptr -> Gen StakeReference
genStakeRefWith :: Gen Ptr -> Gen StakeReference
genStakeRefWith Gen Ptr
genPtr =
  forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency
    [ (Int
80, Credential 'Staking -> StakeReference
StakeRefBase forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary)
    , (Int
5, Ptr -> StakeReference
StakeRefPtr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Ptr
genPtr)
    , (Int
15, forall (f :: * -> *) a. Applicative f => a -> f a
pure StakeReference
StakeRefNull)
    ]

instance Arbitrary RewardAccount where
  arbitrary :: Gen RewardAccount
arbitrary = Network -> Credential 'Staking -> RewardAccount
RewardAccount forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
  shrink :: RewardAccount -> [RewardAccount]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Arbitrary Withdrawals where
  arbitrary :: Gen Withdrawals
arbitrary = forall a. (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a
genericArbitraryU
  shrink :: Withdrawals -> [Withdrawals]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Reward -----------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary RewardType where
  arbitrary :: Gen RewardType
arbitrary = forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum
  shrink :: RewardType -> [RewardType]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Arbitrary Reward where
  arbitrary :: Gen Reward
arbitrary = RewardType -> KeyHash 'StakePool -> Coin -> Reward
Reward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
  shrink :: Reward -> [Reward]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

------------------------------------------------------------------------------------------
-- Cardano.Ledger.PoolParams -------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary PoolParams where
  arbitrary :: Gen PoolParams
arbitrary =
    KeyHash 'StakePool
-> VRFVerKeyHash 'StakePoolVRF
-> Coin
-> Coin
-> UnitInterval
-> RewardAccount
-> Set (KeyHash 'Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> PoolParams
PoolParams
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary PoolMetadata where
  arbitrary :: Gen PoolMetadata
arbitrary = Url -> ByteString -> PoolMetadata
PoolMetadata forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary StakePoolRelay where
  arbitrary :: Gen StakePoolRelay
arbitrary = forall a. (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a
genericArbitraryU
  shrink :: StakePoolRelay -> [StakePoolRelay]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Arbitrary SizeOfPoolRelays where
  arbitrary :: Gen SizeOfPoolRelays
arbitrary = forall (f :: * -> *) a. Applicative f => a -> f a
pure SizeOfPoolRelays
SizeOfPoolRelays

instance Arbitrary SizeOfPoolOwners where
  arbitrary :: Gen SizeOfPoolOwners
arbitrary = forall (f :: * -> *) a. Applicative f => a -> f a
pure SizeOfPoolOwners
SizeOfPoolOwners

------------------------------------------------------------------------------------------
-- Cardano.Ledger.PoolDistr --------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary PoolDistr where
  arbitrary :: Gen PoolDistr
arbitrary = do
    Positive Word64
denominator <- forall a. Arbitrary a => Gen a
arbitrary
    Map (KeyHash 'StakePool) IndividualPoolStake
-> CompactForm Coin -> PoolDistr
PoolDistr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word64 -> CompactForm Coin
CompactCoin Word64
denominator)

instance Arbitrary IndividualPoolStake where
  arbitrary :: Gen IndividualPoolStake
arbitrary = Rational
-> CompactForm Coin
-> VRFVerKeyHash 'StakePoolVRF
-> IndividualPoolStake
IndividualPoolStake forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

------------------------------------------------------------------------------------------
-- Cardano.Ledger.DRepDistr --------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary DRepState where
  arbitrary :: Gen DRepState
arbitrary = EpochNo
-> StrictMaybe Anchor
-> Coin
-> Set (Credential 'Staking)
-> DRepState
DRepState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

------------------------------------------------------------------------------------------
-- Cardano.Ledger.UTxO -------------------------------------------------------------------
------------------------------------------------------------------------------------------

deriving instance (EraTxOut era, Arbitrary (TxOut era)) => Arbitrary (UTxO era)

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Core.PParams -----------------------------------------------------------
------------------------------------------------------------------------------------------

deriving instance (Era era, Arbitrary (PParamsHKD Identity era)) => Arbitrary (PParams era)

deriving instance (Era era, Arbitrary (PParamsHKD StrictMaybe era)) => Arbitrary (PParamsUpdate era)

------------------------------------------------------------------------------------------
-- Cardano.Ledger.UMap -------------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary RDPair where
  arbitrary :: Gen RDPair
arbitrary = CompactForm Coin -> CompactForm Coin -> RDPair
RDPair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
  shrink :: RDPair -> [RDPair]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Arbitrary UMElem where
  arbitrary :: Gen UMElem
arbitrary = StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
  shrink :: UMElem -> [UMElem]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Arbitrary UMap where
  arbitrary :: Gen UMap
arbitrary = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary DRep where
  arbitrary :: Gen DRep
arbitrary =
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ Credential 'DRepRole -> DRep
DRepCredential forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      , forall (f :: * -> *) a. Applicative f => a -> f a
pure DRep
DRepAlwaysAbstain
      , forall (f :: * -> *) a. Applicative f => a -> f a
pure DRep
DRepAlwaysNoConfidence
      ]

-- | Used for testing UMap operations
genValidTuples ::
  Gen
    ( Map (Credential 'Staking) RDPair
    , Map Ptr (Credential 'Staking)
    , Map (Credential 'Staking) (KeyHash 'StakePool)
    , Map (Credential 'Staking) DRep
    )
genValidTuples :: Gen
  (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
   Map (Credential 'Staking) (KeyHash 'StakePool),
   Map (Credential 'Staking) DRep)
genValidTuples = forall a. (Int -> Int) -> Gen a -> Gen a
scale (forall a. Num a => a -> a -> a
* Int
2) forall a b. (a -> b) -> a -> b
$ do
  [Credential 'Staking]
creds :: [Credential 'Staking] <- forall a. Arbitrary a => Gen a
arbitrary
  let nCreds :: Int
nCreds = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Credential 'Staking]
creds
  [RDPair]
rdPairs :: [RDPair] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nCreds forall a. Arbitrary a => Gen a
arbitrary
  [Ptr]
ptrs :: [Ptr] <- forall a. Arbitrary a => Gen a
arbitrary
  [KeyHash 'StakePool]
sPools :: [KeyHash 'StakePool] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nCreds forall a. Arbitrary a => Gen a
arbitrary
  [DRep]
dReps :: [DRep] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nCreds forall a. Arbitrary a => Gen a
arbitrary
  forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ( forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'Staking]
creds [RDPair]
rdPairs
    , forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Ptr]
ptrs [Credential 'Staking]
creds
    , forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'Staking]
creds [KeyHash 'StakePool]
sPools
    , forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'Staking]
creds [DRep]
dReps
    )

genValidTuplesNonEmpty ::
  Gen
    ( Map (Credential 'Staking) RDPair
    , Map Ptr (Credential 'Staking)
    , Map (Credential 'Staking) (KeyHash 'StakePool)
    , Map (Credential 'Staking) DRep
    )
genValidTuplesNonEmpty :: Gen
  (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
   Map (Credential 'Staking) (KeyHash 'StakePool),
   Map (Credential 'Staking) DRep)
genValidTuplesNonEmpty = forall a. (Int -> Int) -> Gen a -> Gen a
scale (forall a. Num a => a -> a -> a
* Int
2) forall a b. (a -> b) -> a -> b
$ do
  Positive Int
nCreds <- forall a. Arbitrary a => Gen a
arbitrary
  Int
nPtrs <- (Int, Int) -> Gen Int
chooseInt (Int
1, Int
nCreds)
  [Credential 'Staking]
creds :: [Credential 'Staking] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nCreds forall a. Arbitrary a => Gen a
arbitrary
  [RDPair]
rdPairs :: [RDPair] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nCreds forall a. Arbitrary a => Gen a
arbitrary
  [Ptr]
ptrs :: [Ptr] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nPtrs forall a. Arbitrary a => Gen a
arbitrary
  [KeyHash 'StakePool]
sPools :: [KeyHash 'StakePool] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nCreds forall a. Arbitrary a => Gen a
arbitrary
  [DRep]
dReps :: [DRep] <- forall a. Int -> Gen a -> Gen [a]
vectorOf Int
nCreds forall a. Arbitrary a => Gen a
arbitrary
  forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ( forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'Staking]
creds [RDPair]
rdPairs
    , forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Ptr]
ptrs [Credential 'Staking]
creds
    , forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'Staking]
creds [KeyHash 'StakePool]
sPools
    , forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'Staking]
creds [DRep]
dReps
    )

genValidUMap :: Gen UMap
genValidUMap :: Gen UMap
genValidUMap = do
  (Map (Credential 'Staking) RDPair
rdPairs, Map Ptr (Credential 'Staking)
ptrs, Map (Credential 'Staking) (KeyHash 'StakePool)
sPools, Map (Credential 'Staking) DRep
dReps) <- Gen
  (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
   Map (Credential 'Staking) (KeyHash 'StakePool),
   Map (Credential 'Staking) DRep)
genValidTuples
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Map (Credential 'Staking) RDPair
-> Map Ptr (Credential 'Staking)
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> UMap
unify Map (Credential 'Staking) RDPair
rdPairs Map Ptr (Credential 'Staking)
ptrs Map (Credential 'Staking) (KeyHash 'StakePool)
sPools Map (Credential 'Staking) DRep
dReps

genValidUMapNonEmpty :: Gen UMap
genValidUMapNonEmpty :: Gen UMap
genValidUMapNonEmpty = do
  (Map (Credential 'Staking) RDPair
rdPairs, Map Ptr (Credential 'Staking)
ptrs, Map (Credential 'Staking) (KeyHash 'StakePool)
sPools, Map (Credential 'Staking) DRep
dReps) <- Gen
  (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
   Map (Credential 'Staking) (KeyHash 'StakePool),
   Map (Credential 'Staking) DRep)
genValidTuplesNonEmpty
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Map (Credential 'Staking) RDPair
-> Map Ptr (Credential 'Staking)
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> UMap
unify Map (Credential 'Staking) RDPair
rdPairs Map Ptr (Credential 'Staking)
ptrs Map (Credential 'Staking) (KeyHash 'StakePool)
sPools Map (Credential 'Staking) DRep
dReps

-- | Either clamp requested size to the range of @[0, actualSize]@ or generate at random
-- in the same range when requested size is not supplied.
uniformSubSize ::
  StatefulGen g m =>
  -- | Requested size
  Maybe Int ->
  -- | Actual size
  Int ->
  g ->
  m Int
uniformSubSize :: forall g (m :: * -> *).
StatefulGen g m =>
Maybe Int -> Int -> g -> m Int
uniformSubSize Maybe Int
mReqSize Int
actualSize g
gen =
  case Maybe Int
mReqSize of
    Maybe Int
Nothing -> forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
uniformRM (Int
0, Int
actualSize) g
gen
    Just Int
reqSize -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
max Int
0 forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
min Int
actualSize Int
reqSize

uniformSubSet ::
  (StatefulGen g m, Ord k) =>
  -- | Size of the subset. If supplied will be clamped to @[0, Set.size s]@ interval,
  -- otherwise will be generated randomly.
  Maybe Int ->
  Set k ->
  g ->
  m (Set k)
uniformSubSet :: forall g (m :: * -> *) k.
(StatefulGen g m, Ord k) =>
Maybe Int -> Set k -> g -> m (Set k)
uniformSubSet Maybe Int
mSubSetSize Set k
inputSet g
gen = do
  Int
subSetSize <- forall g (m :: * -> *).
StatefulGen g m =>
Maybe Int -> Int -> g -> m Int
uniformSubSize Maybe Int
mSubSetSize (forall a. Set a -> Int
Set.size Set k
inputSet) g
gen
  if Int
subSetSize forall a. Ord a => a -> a -> Bool
< forall a. Set a -> Int
Set.size Set k
inputSet forall a. Integral a => a -> a -> a
`div` Int
2
    then
      forall {t} {f :: * -> *} {a}.
(Num t, StatefulGen g f, Ord t, Ord a) =>
Set a -> Set a -> t -> f (Set a)
goAdd Set k
inputSet forall a. Set a
Set.empty Int
subSetSize
    else
      forall {t} {f :: * -> *} {a}.
(Ord t, Num t, StatefulGen g f) =>
Set a -> t -> f (Set a)
goDelete Set k
inputSet (forall a. Set a -> Int
Set.size Set k
inputSet forall a. Num a => a -> a -> a
- Int
subSetSize)
  where
    -- Constructing a new Set is faster when less then a half of original Set will be used
    goAdd :: Set a -> Set a -> t -> f (Set a)
goAdd !Set a
s !Set a
acc !t
i
      | t
i forall a. Ord a => a -> a -> Bool
<= t
0 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Set a
acc
      | Bool
otherwise = do
          Int
ix <- forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
uniformRM (Int
0, forall a. Set a -> Int
Set.size Set a
s forall a. Num a => a -> a -> a
- Int
1) g
gen
          Set a -> Set a -> t -> f (Set a)
goAdd (forall a. Int -> Set a -> Set a
Set.deleteAt Int
ix Set a
s) (forall a. Ord a => a -> Set a -> Set a
Set.insert (forall a. Int -> Set a -> a
Set.elemAt Int
ix Set a
s) Set a
acc) (t
i forall a. Num a => a -> a -> a
- t
1)
    -- Deleting is faster when more items need to be retained in the Set
    goDelete :: Set a -> t -> f (Set a)
goDelete !Set a
acc !t
i
      | t
i forall a. Ord a => a -> a -> Bool
<= t
0 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Set a
acc
      | Bool
otherwise = do
          Int
ix <- forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
uniformRM (Int
0, forall a. Set a -> Int
Set.size Set a
acc forall a. Num a => a -> a -> a
- Int
1) g
gen
          Set a -> t -> f (Set a)
goDelete (forall a. Int -> Set a -> Set a
Set.deleteAt Int
ix Set a
acc) (t
i forall a. Num a => a -> a -> a
- t
1)

uniformSubMap ::
  (StatefulGen g m, Ord k) =>
  -- | Size of the subMap. If supplied will be clamped to @[0, Map.size s]@ interval,
  -- otherwise will be generated randomly.
  Maybe Int ->
  Map k v ->
  g ->
  m (Map k v)
uniformSubMap :: forall g (m :: * -> *) k v.
(StatefulGen g m, Ord k) =>
Maybe Int -> Map k v -> g -> m (Map k v)
uniformSubMap Maybe Int
mSubMapSize Map k v
inputMap g
gen = do
  Int
subMapSize <- forall g (m :: * -> *).
StatefulGen g m =>
Maybe Int -> Int -> g -> m Int
uniformSubSize Maybe Int
mSubMapSize (forall k a. Map k a -> Int
Map.size Map k v
inputMap) g
gen
  if Int
subMapSize forall a. Ord a => a -> a -> Bool
< forall k a. Map k a -> Int
Map.size Map k v
inputMap forall a. Integral a => a -> a -> a
`div` Int
2
    then
      -- Constructing a new Map is faster when less then a half of original Map will be used
      forall g (m :: * -> *) f k v.
(StatefulGen g m, Monoid f) =>
(k -> v -> f -> f) -> Maybe Int -> Map k v -> g -> m f
uniformSubMapElems forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert (forall a. a -> Maybe a
Just Int
subMapSize) Map k v
inputMap g
gen
    else
      -- Deleting is faster when more items need to be retained in the Map
      forall {t} {f :: * -> *} {k} {a}.
(Ord t, Num t, StatefulGen g f) =>
Map k a -> t -> f (Map k a)
goDelete Map k v
inputMap (forall k a. Map k a -> Int
Map.size Map k v
inputMap forall a. Num a => a -> a -> a
- Int
subMapSize)
  where
    goDelete :: Map k a -> t -> f (Map k a)
goDelete !Map k a
acc !t
i
      | t
i forall a. Ord a => a -> a -> Bool
<= t
0 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Map k a
acc
      | Bool
otherwise = do
          Int
ix <- forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
uniformRM (Int
0, forall k a. Map k a -> Int
Map.size Map k a
acc forall a. Num a => a -> a -> a
- Int
1) g
gen
          Map k a -> t -> f (Map k a)
goDelete (forall k a. Int -> Map k a -> Map k a
Map.deleteAt Int
ix Map k a
acc) (t
i forall a. Num a => a -> a -> a
- t
1)

uniformSubMapElems ::
  (StatefulGen g m, Monoid f) =>
  (k -> v -> f -> f) ->
  -- | Size of the subMap. If supplied will be clamped to @[0, Map.size s]@ interval,
  -- otherwise will be generated randomly.
  Maybe Int ->
  Map k v ->
  g ->
  m f
uniformSubMapElems :: forall g (m :: * -> *) f k v.
(StatefulGen g m, Monoid f) =>
(k -> v -> f -> f) -> Maybe Int -> Map k v -> g -> m f
uniformSubMapElems k -> v -> f -> f
insert Maybe Int
mSubMapSize Map k v
inputMap g
gen = do
  Int
subMapSize <- forall g (m :: * -> *).
StatefulGen g m =>
Maybe Int -> Int -> g -> m Int
uniformSubSize Maybe Int
mSubMapSize (forall k a. Map k a -> Int
Map.size Map k v
inputMap) g
gen
  forall {t} {f :: * -> *}.
(Ord t, Num t, StatefulGen g f) =>
Map k v -> f -> t -> f f
go Map k v
inputMap forall a. Monoid a => a
mempty Int
subMapSize
  where
    go :: Map k v -> f -> t -> f f
go !Map k v
s !f
acc !t
i
      | t
i forall a. Ord a => a -> a -> Bool
<= t
0 = forall (f :: * -> *) a. Applicative f => a -> f a
pure f
acc
      | Bool
otherwise = do
          Int
ix <- forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
uniformRM (Int
0, forall k a. Map k a -> Int
Map.size Map k v
s forall a. Num a => a -> a -> a
- Int
1) g
gen
          let (k
k, v
v) = forall k a. Int -> Map k a -> (k, a)
Map.elemAt Int
ix Map k v
s
          Map k v -> f -> t -> f f
go (forall k a. Int -> Map k a -> Map k a
Map.deleteAt Int
ix Map k v
s) (k -> v -> f -> f
insert k
k v
v f
acc) (t
i forall a. Num a => a -> a -> a
- t
1)

genValidUMapWithCreds :: Gen (UMap, Set (Credential 'Staking))
genValidUMapWithCreds :: Gen (UMap, Set (Credential 'Staking))
genValidUMapWithCreds = do
  UMap
umap <- Gen UMap
genValidUMap
  Set (Credential 'Staking)
creds <- forall g (m :: * -> *) k.
(StatefulGen g m, Ord k) =>
Maybe Int -> Set k -> g -> m (Set k)
uniformSubSet forall a. Maybe a
Nothing (forall k a. Map k a -> Set k
Map.keysSet forall a b. (a -> b) -> a -> b
$ UMap -> Map (Credential 'Staking) UMElem
umElems UMap
umap) QC
QC
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (UMap
umap, Set (Credential 'Staking)
creds)

genExcludingKey :: (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey :: forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map k a
ks = do
  k
k <- forall a. Arbitrary a => Gen a
arbitrary
  if k
k forall k a. Ord k => k -> Map k a -> Bool
`Map.member` Map k a
ks
    then forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map k a
ks
    else forall (f :: * -> *) a. Applicative f => a -> f a
pure k
k

genInsertDeleteRoundtripRDPair ::
  Gen (UMap, Credential 'Staking, RDPair)
genInsertDeleteRoundtripRDPair :: Gen (UMap, Credential 'Staking, RDPair)
genInsertDeleteRoundtripRDPair = do
  umap :: UMap
umap@UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} <- Gen UMap
genValidUMap
  Credential 'Staking
k <- forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map (Credential 'Staking) UMElem
umElems
  RDPair
v <- forall a. Arbitrary a => Gen a
arbitrary
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (UMap
umap, Credential 'Staking
k, RDPair
v)

genInsertDeleteRoundtripPtr :: Gen (UMap, Ptr, Credential 'Staking)
genInsertDeleteRoundtripPtr :: Gen (UMap, Ptr, Credential 'Staking)
genInsertDeleteRoundtripPtr = do
  umap :: UMap
umap@UMap {Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs} <- Gen UMap
genValidUMap
  Ptr
k <- forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map Ptr (Credential 'Staking)
umPtrs
  Credential 'Staking
v <- forall a. Arbitrary a => Gen a
arbitrary
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (UMap
umap, Ptr
k, Credential 'Staking
v)

genInsertDeleteRoundtripSPool :: Gen (UMap, Credential 'Staking, KeyHash 'StakePool)
genInsertDeleteRoundtripSPool :: Gen (UMap, Credential 'Staking, KeyHash 'StakePool)
genInsertDeleteRoundtripSPool = do
  umap :: UMap
umap@UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} <- Gen UMap
genValidUMap
  Credential 'Staking
k <- forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map (Credential 'Staking) UMElem
umElems
  KeyHash 'StakePool
v <- forall a. Arbitrary a => Gen a
arbitrary
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (UMap
umap, Credential 'Staking
k, KeyHash 'StakePool
v)

genInsertDeleteRoundtripDRep :: Gen (UMap, Credential 'Staking, DRep)
genInsertDeleteRoundtripDRep :: Gen (UMap, Credential 'Staking, DRep)
genInsertDeleteRoundtripDRep = do
  umap :: UMap
umap@UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems} <- Gen UMap
genValidUMap
  Credential 'Staking
k <- forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map (Credential 'Staking) UMElem
umElems
  DRep
v <- forall a. Arbitrary a => Gen a
arbitrary
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (UMap
umap, Credential 'Staking
k, DRep
v)

genInvariantNonEmpty :: Gen (Credential 'Staking, Ptr, UMap)
genInvariantNonEmpty :: Gen (Credential 'Staking, Ptr, UMap)
genInvariantNonEmpty = do
  umap :: UMap
umap@(UMap Map (Credential 'Staking) UMElem
tripmap Map Ptr (Credential 'Staking)
ptrmap) <- Gen UMap
genValidUMapNonEmpty
  Credential 'Staking
cred <-
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ forall a. HasCallStack => [a] -> Gen a
elements forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [k]
Map.keys Map (Credential 'Staking) UMElem
tripmap
      , forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map (Credential 'Staking) UMElem
tripmap
      ]
  Ptr
ptr <-
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ forall a. HasCallStack => [a] -> Gen a
elements forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [k]
Map.keys Map Ptr (Credential 'Staking)
ptrmap
      , forall k a. (Ord k, Arbitrary k) => Map k a -> Gen k
genExcludingKey Map Ptr (Credential 'Staking)
ptrmap
      ]
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (Credential 'Staking
cred, Ptr
ptr, UMap
umap)

genRightPreferenceUMap :: Gen (UMap, Map (Credential 'Staking) RDPair)
genRightPreferenceUMap :: Gen (UMap, Map (Credential 'Staking) RDPair)
genRightPreferenceUMap = do
  UMap
umap <- Gen UMap
genValidUMap
  let rdMap :: Map (Credential 'Staking) RDPair
rdMap = forall k v. UView k v -> Map k v
unUnify forall a b. (a -> b) -> a -> b
$ UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap
  [Credential 'Staking]
subdomain <- forall a. [a] -> Gen [a]
sublistOf forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [k]
Map.keys Map (Credential 'Staking) RDPair
rdMap
  [RDPair]
coins <- forall a. Int -> Gen a -> Gen [a]
vectorOf (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Credential 'Staking]
subdomain) forall a. Arbitrary a => Gen a
arbitrary
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (UMap
umap, forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'Staking]
subdomain [RDPair]
coins)

------------------------------------------------------------------------------------------
-- Cardano.Ledger.CertState -------------------------------------------------------------------
------------------------------------------------------------------------------------------

instance Era era => Arbitrary (CertState era) where
  arbitrary :: Gen (CertState era)
arbitrary = forall era. VState era -> PState era -> DState era -> CertState era
CertState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
  shrink :: CertState era -> [CertState era]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Era era => Arbitrary (DState era) where
  arbitrary :: Gen (DState era)
arbitrary =
    if forall era. Era era => Version
eraProtVerLow @era forall a. Ord a => a -> a -> Bool
>= forall (v :: Nat). (KnownNat v, 0 <= v, v <= MaxVersion) => Version
natVersion @9
      then forall era.
UMap
-> Map FutureGenDeleg GenDelegPair
-> GenDelegs
-> InstantaneousRewards
-> DState era
DState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen UMap
genConwayUMap forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      else forall era.
UMap
-> Map FutureGenDeleg GenDelegPair
-> GenDelegs
-> InstantaneousRewards
-> DState era
DState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

genConwayUMap :: Gen UMap
genConwayUMap :: Gen UMap
genConwayUMap = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Map (Credential 'Staking) UMElem)
genElems forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
  where
    genElems :: Gen (Map (Credential 'Staking) UMElem)
    genElems :: Gen (Map (Credential 'Staking) UMElem)
genElems = forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Gen a -> Gen [a]
listOf ((,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UMElem
genElem)
    genElem :: Gen UMElem
    genElem :: Gen UMElem
genElem = StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary (PState era) where
  arbitrary :: Gen (PState era)
arbitrary = forall era.
Map (KeyHash 'StakePool) PoolParams
-> Map (KeyHash 'StakePool) PoolParams
-> Map (KeyHash 'StakePool) EpochNo
-> Map (KeyHash 'StakePool) Coin
-> PState era
PState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary Anchor where
  arbitrary :: Gen Anchor
arbitrary = Url -> SafeHash AnchorData -> Anchor
Anchor forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary a => Arbitrary (Mismatch r a) where
  arbitrary :: Gen (Mismatch r a)
arbitrary = forall (r :: Relation) a. a -> a -> Mismatch r a
Mismatch forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CommitteeAuthorization where
  arbitrary :: Gen CommitteeAuthorization
arbitrary =
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ Credential 'HotCommitteeRole -> CommitteeAuthorization
CommitteeHotCredential forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      , StrictMaybe Anchor -> CommitteeAuthorization
CommitteeMemberResigned forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      ]

deriving instance Arbitrary (CommitteeState era)

instance Arbitrary (VState era) where
  arbitrary :: Gen (VState era)
arbitrary = forall era.
Map (Credential 'DRepRole) DRepState
-> CommitteeState era -> EpochNo -> VState era
VState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary InstantaneousRewards where
  arbitrary :: Gen InstantaneousRewards
arbitrary = Map (Credential 'Staking) Coin
-> Map (Credential 'Staking) Coin
-> DeltaCoin
-> DeltaCoin
-> InstantaneousRewards
InstantaneousRewards forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
  shrink :: InstantaneousRewards -> [InstantaneousRewards]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Arbitrary FutureGenDeleg where
  arbitrary :: Gen FutureGenDeleg
arbitrary = SlotNo -> KeyHash 'Genesis -> FutureGenDeleg
FutureGenDeleg forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
  shrink :: FutureGenDeleg -> [FutureGenDeleg]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

------------------------------------------------------------------------------------------
-- Cardano.Ledger.EpochBoundary ----------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary SnapShot where
  arbitrary :: Gen SnapShot
arbitrary =
    Stake
-> VMap VB VB (Credential 'Staking) (KeyHash 'StakePool)
-> VMap VB VB (KeyHash 'StakePool) PoolParams
-> SnapShot
SnapShot
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary SnapShots where
  arbitrary :: Gen SnapShots
arbitrary = do
    SnapShot
ssStakeMark <- forall a. Arbitrary a => Gen a
arbitrary
    SnapShot
ssStakeSet <- forall a. Arbitrary a => Gen a
arbitrary
    SnapShot
ssStakeGo <- forall a. Arbitrary a => Gen a
arbitrary
    Coin
ssFee <- forall a. Arbitrary a => Gen a
arbitrary
    let ssStakeMarkPoolDistr :: PoolDistr
ssStakeMarkPoolDistr = SnapShot -> PoolDistr
calculatePoolDistr SnapShot
ssStakeMark
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ SnapShots {SnapShot
PoolDistr
Coin
$sel:ssStakeMark:SnapShots :: SnapShot
$sel:ssStakeMarkPoolDistr:SnapShots :: PoolDistr
$sel:ssStakeSet:SnapShots :: SnapShot
$sel:ssStakeGo:SnapShots :: SnapShot
$sel:ssFee:SnapShots :: Coin
ssStakeMarkPoolDistr :: PoolDistr
ssFee :: Coin
ssStakeGo :: SnapShot
ssStakeSet :: SnapShot
ssStakeMark :: SnapShot
..}

-- | In the system, Stake never contains more than the sum of all Ada (which is constant).
-- This makes it safe to store individual Coins (in CompactForm) as Word64. But we must
-- be careful that we never generate Stake where the sum of all the coins exceeds (maxBound :: Word64)
-- There will never be a real Stake in the system with that many Ada, because total Ada is constant.
-- So using a restricted Arbitrary Generator is OK.
instance Arbitrary Stake where
  arbitrary :: Gen Stake
arbitrary = VMap VB VP (Credential 'Staking) (CompactForm Coin) -> Stake
Stake forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Map k v -> VMap kv vv k v
VMap.fromMap forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Map (Credential 'Staking) (CompactForm Coin))
theMap)
    where
      genWord64 :: Int -> Gen Word64
      genWord64 :: Int -> Gen Word64
genWord64 Int
n =
        forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency
          [ (Int
3, forall a. Random a => (a, a) -> Gen a
choose (Word64
1, Word64
100))
          , (Int
2, forall a. Random a => (a, a) -> Gen a
choose (Word64
101, Word64
10000))
          , (Int
1, forall a. Random a => (a, a) -> Gen a
choose (Word64
1, forall a. Bounded a => a
maxBound forall a. Integral a => a -> a -> a
`div` forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n))
          ]
      theMap :: Gen (Map (Credential 'Staking) (CompactForm Coin))
theMap = do
        Int
n <- forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency [(Int
3, (Int, Int) -> Gen Int
chooseInt (Int
1, Int
20)), (Int
2, (Int, Int) -> Gen Int
chooseInt (Int
21, Int
150)), (Int
1, (Int, Int) -> Gen Int
chooseInt (Int
151, Int
1000))]
        let pair :: Gen (Credential 'Staking, CompactForm Coin)
pair = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Word64 -> CompactForm Coin
CompactCoin forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen Word64
genWord64 Int
n)
        [(Credential 'Staking, CompactForm Coin)]
list <- forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency [(Int
1, forall (f :: * -> *) a. Applicative f => a -> f a
pure []), (Int
99, forall a. Int -> Gen a -> Gen [a]
vectorOf Int
n Gen (Credential 'Staking, CompactForm Coin)
pair)]
        forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Credential 'Staking, CompactForm Coin)]
list)

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Core.TxCert ----------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary PoolCert where
  arbitrary :: Gen PoolCert
arbitrary =
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ PoolParams -> PoolCert
RegPool forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      , KeyHash 'StakePool -> EpochNo -> PoolCert
RetirePool forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      ]
  shrink :: PoolCert -> [PoolCert]
shrink = forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

------------------------------------------------------------------------------------------
-- Cardano.Ledger.Plutus ----------------------------------------------------------
------------------------------------------------------------------------------------------

instance Arbitrary Language where
  arbitrary :: Gen Language
arbitrary = forall a. HasCallStack => [a] -> Gen a
elements [Language]
nonNativeLanguages

instance Arbitrary ExUnits where
  arbitrary :: Gen ExUnits
arbitrary = Nat -> Nat -> ExUnits
ExUnits forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Nat
genUnit forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Nat
genUnit
    where
      genUnit :: Gen Nat
genUnit = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Random a => (a, a) -> Gen a
choose (Int64
0, forall a. Bounded a => a
maxBound :: Int64)

instance Arbitrary Prices where
  arbitrary :: Gen Prices
arbitrary = NonNegativeInterval -> NonNegativeInterval -> Prices
Prices forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CostModel where
  arbitrary :: Gen CostModel
arbitrary = forall a. HasCallStack => [a] -> Gen a
elements [Language]
nonNativeLanguages forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Language -> Gen CostModel
genValidCostModel

genValidCostModel :: Language -> Gen CostModel
genValidCostModel :: Language -> Gen CostModel
genValidCostModel Language
lang = do
  [Int64]
newParamValues <- forall a. Int -> Gen a -> Gen [a]
vectorOf (Language -> Int
costModelParamsCount Language
lang) forall a. Arbitrary a => Gen a
arbitrary
  forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\CostModelApplyError
err -> forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"Corrupt cost model: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show CostModelApplyError
err) forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
    Language -> [Int64] -> Either CostModelApplyError CostModel
mkCostModel Language
lang [Int64]
newParamValues

genValidCostModels :: Set.Set Language -> Gen CostModels
genValidCostModels :: Set Language -> Gen CostModels
genValidCostModels = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Language CostModel -> CostModels
mkCostModels forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet Language -> Gen CostModel
genValidCostModel

genValidAndUnknownCostModels :: Gen CostModels
genValidAndUnknownCostModels :: Gen CostModels
genValidAndUnknownCostModels = do
  [Language]
langs <- forall a. [a] -> Gen [a]
sublistOf [Language]
nonNativeLanguages
  CostModels
validCms <- Set Language -> Gen CostModels
genValidCostModels forall a b. (a -> b) -> a -> b
$ forall a. Ord a => [a] -> Set a
Set.fromList [Language]
langs
  CostModels
unknownCms <- forall a. HasCallStack => Fail a -> a
errorFail forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
MonadFail m =>
Map Word8 [Int64] -> m CostModels
mkCostModelsLenient forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Map Word8 [Int64])
genUnknownCostModels
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ CostModels -> CostModels -> CostModels
updateCostModels CostModels
validCms CostModels
unknownCms

-- | This Arbitrary instance assumes the inflexible deserialization
-- scheme prior to version 9.
instance Arbitrary CostModels where
  arbitrary :: Gen CostModels
arbitrary = do
    Map Word8 [Int64]
known <- Gen (Map Word8 [Int64])
genKnownCostModels
    Map Word8 [Int64]
unknown <- Gen (Map Word8 [Int64])
genUnknownCostModels
    let cms :: Map Word8 [Int64]
cms = Map Word8 [Int64]
known forall k a. Ord k => Map k a -> Map k a -> Map k a
`Map.union` Map Word8 [Int64]
unknown
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasCallStack => Fail a -> a
errorFail forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadFail m =>
Map Word8 [Int64] -> m CostModels
mkCostModelsLenient Map Word8 [Int64]
cms

genUnknownCostModels :: Gen (Map Word8 [Int64])
genUnknownCostModels :: Gen (Map Word8 [Int64])
genUnknownCostModels = forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Gen a -> Gen [a]
listOf Gen (Word8, [Int64])
genUnknownCostModelValues

genKnownCostModels :: Gen (Map Word8 [Int64])
genKnownCostModels :: Gen (Map Word8 [Int64])
genKnownCostModels = do
  [Language]
langs <- forall a. [a] -> Gen [a]
sublistOf [Language]
nonNativeLanguages
  [(Word8, [Int64])]
cms <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Language -> Gen (Word8, [Int64])
genCostModelValues [Language]
langs
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Word8, [Int64])]
cms

genUnknownCostModelValues :: Gen (Word8, [Int64])
genUnknownCostModelValues :: Gen (Word8, [Int64])
genUnknownCostModelValues = do
  Int
lang <- (Int, Int) -> Gen Int
chooseInt (Int
firstInvalid, forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
maxBound :: Word8))
  [Int64]
vs <- forall a. Arbitrary a => Gen a
arbitrary
  forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => a -> Int
fromEnum forall a b. (a -> b) -> a -> b
$ Int
lang, [Int64]
vs)
  where
    firstInvalid :: Int
firstInvalid = forall a. Enum a => a -> Int
fromEnum (forall a. Bounded a => a
maxBound :: Language) forall a. Num a => a -> a -> a
+ Int
1

genCostModelValues :: Language -> Gen (Word8, [Int64])
genCostModelValues :: Language -> Gen (Word8, [Int64])
genCostModelValues Language
lang = do
  Positive Int
sub <- forall a. Arbitrary a => Gen a
arbitrary
  (,) Word8
lang'
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ Int -> Gen [Int64]
listAtLeast (Language -> Int
costModelParamsCount Language
lang) -- Valid Cost Model for known language
      , forall a. Int -> [a] -> [a]
take (Int -> Int
tooFew Int
sub) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary -- Invalid Cost Model for known language
      ]
  where
    lang' :: Word8
lang' = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Enum a => a -> Int
fromEnum Language
lang)
    tooFew :: Int -> Int
tooFew Int
sub = Language -> Int
costModelParamsCount Language
lang forall a. Num a => a -> a -> a
- Int
sub
    listAtLeast :: Int -> Gen [Int64]
    listAtLeast :: Int -> Gen [Int64]
listAtLeast Int
x = do
      NonNegative Int
y <- forall a. Arbitrary a => Gen a
arbitrary
      forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Int
x forall a. Num a => a -> a -> a
+ Int
y) forall a. Arbitrary a => Gen a
arbitrary