{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Cardano.Api.Gen
    ( genAddressAny
    , genAddressByron
    , genAddressInEra
    , genAddressShelley
    , genAlphaNum
    , genAssetIdNoAda
    , genAssetName
    , genByronKeyWitness
    , genCertIx
    , genCostModel
    , genCostModels
    , genEncodingBoundaryLovelace
    , genEpochNo
    , genExecutionUnitPrices
    , genExecutionUnits
    , genExtraKeyWitnesses
    , genLovelace
    , genMIRPot
    , genMIRTarget
    , genNat
    , genNetworkId
    , genNetworkMagic
    , genPaymentCredential
    , genPlutusScript
    , genPolicyId
    , genPoolId
    , genProtocolParameters
    , genProtocolParametersUpdate
    , genPtr
    , genRational
    , genRationalInt64
    , genScript
    , genScriptData
    , genScriptHash
    , genScriptInAnyLang
    , genScriptInEra
    , genScriptValidity
    , genScriptWitnessStake
    , genSeed
    , genShelleyHash
    , genShelleyWitnessSigningKey
    , genSignedQuantity
    , genSignedValue
    , genSigningKey
    , genSimpleScript
    , genSlotNo
    , genSlotNo32
    , genStakeAddress
    , genStakeAddressReference
    , genStakeCredential
    , genStakePoolMetadata
    , genStakePoolMetadataReference
    , genStakePoolParameters
    , genStakePoolRelay
    , genTtl
    , genTx
    , genTxAuxScripts
    , genTxBody
    , genTxBodyContent
    , genTxBodyForBalancing
    , genTxCertificate
    , genTxCertificates
    , genTxFee
    , genTxForBalancing
    , genTxId
    , genTxIn
    , genTxIndex
    , genTxInEra
    , genTxInsCollateral
    , genTxIx
    , genTxMetadata
    , genTxMetadataInEra
    , genTxMetadataValue
    , genTxMintValue
    , genTxOut
    , genTxOutDatum
    , genTxOutValue
    , genTxReturnCollateral
    , genTxScriptValidity
    , genTxTotalCollateral
    , genTxValidityLowerBound
    , genTxValidityRange
    , genTxValidityUpperBound
    , genTxWithdrawals
    , genUnsignedQuantity
    , genUpdateProposal
    , genValueForMinting
    , genValueForTxOut
    , genVerificationKey
    , genVerificationKeyHash
    , genWithdrawalInfo
    , genWitness
    , genWitnesses
    , genWitnessNetworkIdOrByronAddress
    , genWitnessStake
    ) where

import Prelude

import Cardano.Api hiding
    ( txIns )
import Cardano.Api.Byron
    ( KeyWitness (ByronKeyWitness), WitnessNetworkIdOrByronAddress (..) )
import Cardano.Api.Shelley
    ( Hash (..)
    , PlutusScript (..)
    , PlutusScriptOrReferenceInput (..)
    , PoolId
    , ProtocolParameters (..)
    , ReferenceScript (..)
    , SimpleScriptOrReferenceInput (..)
    , StakeCredential (..)
    , StakePoolMetadata (..)
    , StakePoolMetadataReference (..)
    , StakePoolParameters (..)
    , StakePoolRelay (..)
    , refInsScriptsAndInlineDatsSupportedInEra
    )
import Cardano.Ledger.Credential.Safe
    ( Ptr, SlotNo32 (..), safePtr )
import Cardano.Ledger.SafeHash
    ( unsafeMakeSafeHash )
import Cardano.Ledger.Shelley.API
    ( MIRPot (..) )
import Data.Aeson
    ( ToJSON (..), (.=) )
import Data.ByteString
    ( ByteString )
import Data.Coerce
    ( coerce )
import Data.Int
    ( Int64 )
import Data.IntCast
    ( intCast )
import Data.Map
    ( Map )
import Data.Maybe
    ( maybeToList )
import Data.Maybe.Strict
    ( strictMaybeToMaybe )
import Data.Ratio
    ( Ratio, (%) )
import Data.Set
    ( Set )
import Data.String
    ( fromString )
import Data.Text
    ( Text )
import Data.Word
    ( Word16, Word32, Word64 )
import Network.Socket
    ( PortNumber )
import Numeric.Natural
    ( Natural )
import System.Random
    ( Random )
import Test.Cardano.Chain.UTxO.Gen
    ( genVKWitness )
import Test.Cardano.Crypto.Gen
    ( genProtocolMagicId )
import Test.QuickCheck
    ( Gen
    , Large (..)
    , NonNegative (..)
    , Positive (..)
    , arbitrary
    , choose
    , chooseInt
    , chooseInteger
    , elements
    , frequency
    , infiniteListOf
    , liftArbitrary
    , listOf
    , listOf1
    , oneof
    , scale
    , sized
    , vector
    , vectorOf
    )
import Test.QuickCheck.Hedgehog
    ( hedgehog )

import qualified Cardano.Api as Api
import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash as Crypto
import qualified Cardano.Crypto.Seed as Crypto
import qualified Cardano.Ledger.BaseTypes as Ledger
    ( CertIx (..), Port, TxIx (..), dnsToText )
import qualified Cardano.Ledger.Shelley.API as Ledger
    ( StakePoolRelay (..), portToWord16 )
import qualified Cardano.Ledger.Shelley.TxBody as Ledger
    ( EraIndependentTxBody )
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Short as SBS
import Data.List
    ( nub )
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified PlutusCore as Plutus
import qualified Test.Cardano.Ledger.Shelley.Serialisation.Generators.Genesis as Ledger
    ( genStakePoolRelay )

--------------------------------------------------------------------------------
-- Constants
--------------------------------------------------------------------------------

-- | The smallest quantity of lovelace that can appear in a transaction output's
--   value map.
--
-- In practice, the protocol parameters may require this value to be higher, so
-- this is an absolute minimum.
--
txOutMinLovelace :: Lovelace
txOutMinLovelace :: Lovelace
txOutMinLovelace = Lovelace
0

-- | The greatest quantity of lovelace that can appear in a transaction output's
--   value map.
--
-- In practice, this is limited by the total available supply of lovelace.
--
txOutMaxLovelace :: Lovelace
txOutMaxLovelace :: Lovelace
txOutMaxLovelace = Lovelace
45_000_000_000_000_000

--------------------------------------------------------------------------------
-- Generators
--------------------------------------------------------------------------------

genShelleyHash
    :: Gen (Crypto.Hash Crypto.Blake2b_256 Ledger.EraIndependentTxBody)
genShelleyHash :: Gen (Hash Blake2b_256 EraIndependentTxBody)
genShelleyHash = Hash Blake2b_256 EraIndependentTxBody
-> Gen (Hash Blake2b_256 EraIndependentTxBody)
forall (m :: * -> *) a. Monad m => a -> m a
return (Hash Blake2b_256 EraIndependentTxBody
 -> Gen (Hash Blake2b_256 EraIndependentTxBody))
-> (Hash Blake2b_256 () -> Hash Blake2b_256 EraIndependentTxBody)
-> Hash Blake2b_256 ()
-> Gen (Hash Blake2b_256 EraIndependentTxBody)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash Blake2b_256 () -> Hash Blake2b_256 EraIndependentTxBody
forall h a b. Hash h a -> Hash h b
Crypto.castHash (Hash Blake2b_256 ()
 -> Gen (Hash Blake2b_256 EraIndependentTxBody))
-> Hash Blake2b_256 ()
-> Gen (Hash Blake2b_256 EraIndependentTxBody)
forall a b. (a -> b) -> a -> b
$ (() -> ByteString) -> () -> Hash Blake2b_256 ()
forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a
Crypto.hashWith () -> ByteString
forall a. ToCBOR a => a -> ByteString
CBOR.serialize' ()

genTxIn :: Gen TxIn
genTxIn :: Gen TxIn
genTxIn = TxId -> TxIx -> TxIn
TxIn (TxId -> TxIx -> TxIn) -> Gen TxId -> Gen (TxIx -> TxIn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxId
genTxId Gen (TxIx -> TxIn) -> Gen TxIx -> Gen TxIn
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen TxIx
genTxIndex

genTxId :: Gen TxId
genTxId :: Gen TxId
genTxId = Hash Blake2b_256 EraIndependentTxBody -> TxId
Hash StandardCrypto EraIndependentTxBody -> TxId
TxId (Hash Blake2b_256 EraIndependentTxBody -> TxId)
-> Gen (Hash Blake2b_256 EraIndependentTxBody) -> Gen TxId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Hash Blake2b_256 EraIndependentTxBody)
genShelleyHash

genTxIndex :: Gen TxIx
genTxIndex :: Gen TxIx
genTxIndex = [Gen TxIx] -> Gen TxIx
forall a. [Gen a] -> Gen a
oneof
    [ (Word -> TxIx
TxIx (Word -> TxIx) -> (Word16 -> Word) -> Word16 -> TxIx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Word
forall a b.
(Integral a, Integral b, IsIntSubType a b ~ 'True) =>
a -> b
intCast) (Word16 -> TxIx) -> Gen Word16 -> Gen TxIx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Arbitrary Word16 => Gen Word16
forall a. Arbitrary a => Gen a
arbitrary @Word16)
      -- FIXME: cardano-api uses a full Word here, yet the ledger uses Word16
      -- and we'll fail to construct a tx unless we constrain ourselves to
      -- Word16 here.
    , Word -> TxIx
TxIx (Word -> TxIx)
-> (NonNegative Int -> Word) -> NonNegative Int -> TxIx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word)
-> (NonNegative Int -> Int) -> NonNegative Int -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonNegative Int -> Int
forall a. NonNegative a -> a
getNonNegative (NonNegative Int -> TxIx) -> Gen (NonNegative Int) -> Gen TxIx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Arbitrary (NonNegative Int) => Gen (NonNegative Int)
forall a. Arbitrary a => Gen a
arbitrary @(NonNegative Int))
    -- For some bias towards small values
    ]

genTxInsCollateral :: CardanoEra era -> Gen (TxInsCollateral era)
genTxInsCollateral :: CardanoEra era -> Gen (TxInsCollateral era)
genTxInsCollateral CardanoEra era
era =
    case CardanoEra era -> Maybe (CollateralSupportedInEra era)
forall era. CardanoEra era -> Maybe (CollateralSupportedInEra era)
collateralSupportedInEra CardanoEra era
era of
      Maybe (CollateralSupportedInEra era)
Nothing        -> TxInsCollateral era -> Gen (TxInsCollateral era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
      Just CollateralSupportedInEra era
supported -> [Gen (TxInsCollateral era)] -> Gen (TxInsCollateral era)
forall a. [Gen a] -> Gen a
oneof
                          [ TxInsCollateral era -> Gen (TxInsCollateral era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
                          , CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
forall era.
CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
TxInsCollateral CollateralSupportedInEra era
supported
                            ([TxIn] -> TxInsCollateral era)
-> Gen [TxIn] -> Gen (TxInsCollateral era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [TxIn] -> Gen [TxIn]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen TxIn -> Gen [TxIn]
forall a. Gen a -> Gen [a]
listOf Gen TxIn
genTxIn)
                          ]

genSlotNo :: Gen SlotNo
genSlotNo :: Gen SlotNo
genSlotNo = do
    Word64
boundary <- Gen Word64
genBoundary
    [(Int, Gen SlotNo)] -> Gen SlotNo
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
20, SlotNo -> Gen SlotNo
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SlotNo -> Gen SlotNo) -> SlotNo -> Gen SlotNo
forall a b. (a -> b) -> a -> b
$ Word64 -> SlotNo
SlotNo Word64
boundary)
        , (Int
20, SlotNo -> Gen SlotNo
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SlotNo -> Gen SlotNo) -> SlotNo -> Gen SlotNo
forall a b. (a -> b) -> a -> b
$ Word64 -> SlotNo
SlotNo (Bounded Word64 => Word64
forall a. Bounded a => a
maxBound @Word64 Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
boundary) )
        , (Int
60, Word64 -> SlotNo
SlotNo (Word64 -> SlotNo) -> Gen Word64 -> Gen SlotNo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Arbitrary Word64 => Gen Word64
forall a. Arbitrary a => Gen a
arbitrary @Word64)
        ]
  where
    genBoundary :: Gen Word64
genBoundary = (Word64, Word64) -> Gen Word64
forall a. Random a => (a, a) -> Gen a
choose (Word64
0, Word64
10_000)

genSlotNo32 :: Gen SlotNo32
genSlotNo32 :: Gen SlotNo32
genSlotNo32 = do
    Word32
offset <- Gen Word32
genOffset
    [(Int, Gen SlotNo32)] -> Gen SlotNo32
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
20, SlotNo32 -> Gen SlotNo32
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SlotNo32 -> Gen SlotNo32) -> SlotNo32 -> Gen SlotNo32
forall a b. (a -> b) -> a -> b
$ Word32 -> SlotNo32
SlotNo32 Word32
offset)
        , (Int
20, SlotNo32 -> Gen SlotNo32
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SlotNo32 -> Gen SlotNo32) -> SlotNo32 -> Gen SlotNo32
forall a b. (a -> b) -> a -> b
$ Word32 -> SlotNo32
SlotNo32 (Bounded Word32 => Word32
forall a. Bounded a => a
maxBound @Word32 Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
offset) )
        , (Int
60, Word32 -> SlotNo32
SlotNo32 (Word32 -> SlotNo32) -> Gen Word32 -> Gen SlotNo32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Arbitrary Word32 => Gen Word32
forall a. Arbitrary a => Gen a
arbitrary @Word32)
        ]
  where
    genOffset :: Gen Word32
genOffset = (Word32, Word32) -> Gen Word32
forall a. Random a => (a, a) -> Gen a
choose (Word32
0, Word32
10_000)

genLovelace :: Gen Lovelace
genLovelace :: Gen Lovelace
genLovelace = [(Int, Gen Lovelace)] -> Gen Lovelace
forall a. [(Int, Gen a)] -> Gen a
frequency
    [ (Int
10, Integer -> Lovelace
Lovelace (Integer -> Lovelace)
-> (NonNegative Int -> Integer) -> NonNegative Int -> Lovelace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a b.
(Integral a, Integral b, IsIntSubType a b ~ 'True) =>
a -> b
intCast (Int -> Integer)
-> (NonNegative Int -> Int) -> NonNegative Int -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonNegative Int -> Int
forall a. NonNegative a -> a
getNonNegative @Int (NonNegative Int -> Lovelace)
-> Gen (NonNegative Int) -> Gen Lovelace
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (NonNegative Int)
forall a. Arbitrary a => Gen a
arbitrary)
    , (Int
50, (Lovelace, Lovelace) -> Gen Lovelace
forall a. Random a => (a, a) -> Gen a
choose (Lovelace
1_000_000, Lovelace
1_000_000_000))
    , (Int
10, (Lovelace, Lovelace) -> Gen Lovelace
forall a. Random a => (a, a) -> Gen a
choose (Lovelace
txOutMinLovelace, Lovelace
txOutMaxLovelace))
    , (Int
30, Gen Lovelace
genEncodingBoundaryLovelace)
    ]

genEncodingBoundaryLovelace :: Gen Lovelace
genEncodingBoundaryLovelace :: Gen Lovelace
genEncodingBoundaryLovelace = do
    -- https://json.nlohmann.me/features/binary_formats/cbor/
    -- Generate a point near a boundary
    -- However, the three first ones are below the minimum utxo value on
    -- mainnet, and are less useful to generate (in that context).
    Integer
boundary <- [(Int, Gen Integer)] -> Gen Integer
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ ( Int
1, Integer -> Gen Integer
forall (f :: * -> *) a. Applicative f => a -> f a
pure            Integer
24)
        , ( Int
1, Integer -> Gen Integer
forall (f :: * -> *) a. Applicative f => a -> f a
pure           Integer
256) -- 2^ 8
        , ( Int
8, Integer -> Gen Integer
forall (f :: * -> *) a. Applicative f => a -> f a
pure        Integer
65_536) -- 2^16
        , (Int
90, Integer -> Gen Integer
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
4_294_967_296) -- 2^32
        ]

    Integer
offset <- [(Int, Gen Integer)] -> Gen Integer
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
1, (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (-Integer
10, Integer
10))

        -- Either offset by -1 (just below boundary), or 0 (just above boundary)
        , (Int
1, (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (-Integer
1, Integer
0))

        -- Offset by values close to common fee values, in both the positive
        -- and negative direction, with the hope that this helps find
        -- corner-cases.
        , (Int
1, (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (-Integer
220_000, -Integer
150_000))
        , (Int
1, (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (Integer
150_000, Integer
220_000))

        , (Int
1, (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (-Integer
1_000_000, Integer
1_000_000))
        ]
    Lovelace -> Gen Lovelace
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Lovelace -> Gen Lovelace) -> Lovelace -> Gen Lovelace
forall a b. (a -> b) -> a -> b
$ Integer -> Lovelace
Lovelace (Integer -> Lovelace)
-> (Integer -> Integer) -> Integer -> Lovelace
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Integer -> Integer -> Integer
forall a. Ord a => a -> a -> a
max Integer
0 (Integer -> Lovelace) -> Integer -> Lovelace
forall a b. (a -> b) -> a -> b
$ Integer
boundary Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
offset


genTxFee :: CardanoEra era -> Gen (TxFee era)
genTxFee :: CardanoEra era -> Gen (TxFee era)
genTxFee CardanoEra era
era =
  case CardanoEra era
-> Either (TxFeesImplicitInEra era) (TxFeesExplicitInEra era)
forall era.
CardanoEra era
-> Either (TxFeesImplicitInEra era) (TxFeesExplicitInEra era)
txFeesExplicitInEra CardanoEra era
era of
    Left  TxFeesImplicitInEra era
implicit -> TxFee era -> Gen (TxFee era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxFeesImplicitInEra era -> TxFee era
forall era. TxFeesImplicitInEra era -> TxFee era
TxFeeImplicit TxFeesImplicitInEra era
implicit)
    Right TxFeesExplicitInEra era
explicit -> TxFeesExplicitInEra era -> Lovelace -> TxFee era
forall era. TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit TxFeesExplicitInEra era
explicit (Lovelace -> TxFee era) -> Gen Lovelace -> Gen (TxFee era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace

genTtl :: Gen SlotNo
genTtl :: Gen SlotNo
genTtl = Gen SlotNo
genSlotNo

genTxValidityLowerBound :: CardanoEra era -> Gen (TxValidityLowerBound era)
genTxValidityLowerBound :: CardanoEra era -> Gen (TxValidityLowerBound era)
genTxValidityLowerBound CardanoEra era
era =
  case CardanoEra era -> Maybe (ValidityLowerBoundSupportedInEra era)
forall era.
CardanoEra era -> Maybe (ValidityLowerBoundSupportedInEra era)
validityLowerBoundSupportedInEra CardanoEra era
era of
    Maybe (ValidityLowerBoundSupportedInEra era)
Nothing        -> TxValidityLowerBound era -> Gen (TxValidityLowerBound era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
    Just ValidityLowerBoundSupportedInEra era
supported -> ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
forall era.
ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
TxValidityLowerBound ValidityLowerBoundSupportedInEra era
supported (SlotNo -> TxValidityLowerBound era)
-> Gen SlotNo -> Gen (TxValidityLowerBound era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SlotNo
genTtl

genTxValidityUpperBound :: CardanoEra era -> Gen (TxValidityUpperBound era)
genTxValidityUpperBound :: CardanoEra era -> Gen (TxValidityUpperBound era)
genTxValidityUpperBound CardanoEra era
era =
  case (CardanoEra era -> Maybe (ValidityUpperBoundSupportedInEra era)
forall era.
CardanoEra era -> Maybe (ValidityUpperBoundSupportedInEra era)
validityUpperBoundSupportedInEra CardanoEra era
era,
       CardanoEra era -> Maybe (ValidityNoUpperBoundSupportedInEra era)
forall era.
CardanoEra era -> Maybe (ValidityNoUpperBoundSupportedInEra era)
validityNoUpperBoundSupportedInEra CardanoEra era
era) of
    (Just ValidityUpperBoundSupportedInEra era
supported, Maybe (ValidityNoUpperBoundSupportedInEra era)
_) ->
      ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
forall era.
ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
TxValidityUpperBound ValidityUpperBoundSupportedInEra era
supported (SlotNo -> TxValidityUpperBound era)
-> Gen SlotNo -> Gen (TxValidityUpperBound era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SlotNo
genTtl

    (Maybe (ValidityUpperBoundSupportedInEra era)
Nothing, Just ValidityNoUpperBoundSupportedInEra era
supported) ->
      TxValidityUpperBound era -> Gen (TxValidityUpperBound era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
forall era.
ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra era
supported)

    (Maybe (ValidityUpperBoundSupportedInEra era)
Nothing, Maybe (ValidityNoUpperBoundSupportedInEra era)
Nothing) ->
      [Char] -> Gen (TxValidityUpperBound era)
forall a. HasCallStack => [Char] -> a
error [Char]
"genTxValidityUpperBound: unexpected era support combination"

genTxValidityRange
  :: CardanoEra era
  -> Gen (TxValidityLowerBound era, TxValidityUpperBound era)
genTxValidityRange :: CardanoEra era
-> Gen (TxValidityLowerBound era, TxValidityUpperBound era)
genTxValidityRange CardanoEra era
era =
  (,)
    (TxValidityLowerBound era
 -> TxValidityUpperBound era
 -> (TxValidityLowerBound era, TxValidityUpperBound era))
-> Gen (TxValidityLowerBound era)
-> Gen
     (TxValidityUpperBound era
      -> (TxValidityLowerBound era, TxValidityUpperBound era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era -> Gen (TxValidityLowerBound era)
forall era. CardanoEra era -> Gen (TxValidityLowerBound era)
genTxValidityLowerBound CardanoEra era
era
    Gen
  (TxValidityUpperBound era
   -> (TxValidityLowerBound era, TxValidityUpperBound era))
-> Gen (TxValidityUpperBound era)
-> Gen (TxValidityLowerBound era, TxValidityUpperBound era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra era -> Gen (TxValidityUpperBound era)
forall era. CardanoEra era -> Gen (TxValidityUpperBound era)
genTxValidityUpperBound CardanoEra era
era

genTxScriptValidity :: CardanoEra era -> Gen (TxScriptValidity era)
genTxScriptValidity :: CardanoEra era -> Gen (TxScriptValidity era)
genTxScriptValidity CardanoEra era
era = case CardanoEra era -> Maybe (TxScriptValiditySupportedInEra era)
forall era.
CardanoEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInCardanoEra CardanoEra era
era of
  Maybe (TxScriptValiditySupportedInEra era)
Nothing -> TxScriptValidity era -> Gen (TxScriptValidity era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
  Just TxScriptValiditySupportedInEra era
witness -> TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
forall era.
TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
TxScriptValidity TxScriptValiditySupportedInEra era
witness (ScriptValidity -> TxScriptValidity era)
-> Gen ScriptValidity -> Gen (TxScriptValidity era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ScriptValidity
genScriptValidity

genScriptValidity :: Gen ScriptValidity
genScriptValidity :: Gen ScriptValidity
genScriptValidity = [ScriptValidity] -> Gen ScriptValidity
forall a. [a] -> Gen a
elements [ScriptValidity
ScriptInvalid, ScriptValidity
ScriptValid]

genSeed :: Int -> Gen Crypto.Seed
genSeed :: Int -> Gen Seed
genSeed Int
n = (ByteString -> Seed
Crypto.mkSeedFromBytes (ByteString -> Seed) -> ([Word8] -> ByteString) -> [Word8] -> Seed
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
BS.pack) ([Word8] -> Seed) -> Gen [Word8] -> Gen Seed
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Word8]
forall a. Arbitrary a => Int -> Gen [a]
vector Int
n

genSigningKey :: Key keyrole => AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey :: AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType keyrole
roletoken = do
    Seed
seed <- Int -> Gen Seed
genSeed (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
seedSize)
    let sk :: SigningKey keyrole
sk = AsType keyrole -> Seed -> SigningKey keyrole
forall keyrole.
Key keyrole =>
AsType keyrole -> Seed -> SigningKey keyrole
deterministicSigningKey AsType keyrole
roletoken Seed
seed
    SigningKey keyrole -> Gen (SigningKey keyrole)
forall (m :: * -> *) a. Monad m => a -> m a
return SigningKey keyrole
sk

    where
        seedSize :: Word
        seedSize :: Word
seedSize = AsType keyrole -> Word
forall keyrole. Key keyrole => AsType keyrole -> Word
deterministicSigningKeySeedSize AsType keyrole
roletoken

genVerificationKey
    :: Key keyrole
    => AsType keyrole
    -> Gen (VerificationKey keyrole)
genVerificationKey :: AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey AsType keyrole
roletoken = SigningKey keyrole -> VerificationKey keyrole
forall keyrole.
Key keyrole =>
SigningKey keyrole -> VerificationKey keyrole
getVerificationKey (SigningKey keyrole -> VerificationKey keyrole)
-> Gen (SigningKey keyrole) -> Gen (VerificationKey keyrole)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType keyrole -> Gen (SigningKey keyrole)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType keyrole
roletoken

genVerificationKeyHash :: Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash :: AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType keyrole
roletoken =
  VerificationKey keyrole -> Hash keyrole
forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash (VerificationKey keyrole -> Hash keyrole)
-> Gen (VerificationKey keyrole) -> Gen (Hash keyrole)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType keyrole -> Gen (VerificationKey keyrole)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey AsType keyrole
roletoken

genExtraKeyWitnesses :: CardanoEra era -> Gen (TxExtraKeyWitnesses era)
genExtraKeyWitnesses :: CardanoEra era -> Gen (TxExtraKeyWitnesses era)
genExtraKeyWitnesses CardanoEra era
era =
    case CardanoEra era -> Maybe (TxExtraKeyWitnessesSupportedInEra era)
forall era.
CardanoEra era -> Maybe (TxExtraKeyWitnessesSupportedInEra era)
extraKeyWitnessesSupportedInEra CardanoEra era
era of
        Maybe (TxExtraKeyWitnessesSupportedInEra era)
Nothing -> TxExtraKeyWitnesses era -> Gen (TxExtraKeyWitnesses era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
        Just TxExtraKeyWitnessesSupportedInEra era
supported -> [Gen (TxExtraKeyWitnesses era)] -> Gen (TxExtraKeyWitnesses era)
forall a. [Gen a] -> Gen a
oneof
            [ TxExtraKeyWitnesses era -> Gen (TxExtraKeyWitnesses era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
            , TxExtraKeyWitnessesSupportedInEra era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
forall era.
TxExtraKeyWitnessesSupportedInEra era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
TxExtraKeyWitnesses TxExtraKeyWitnessesSupportedInEra era
supported
              ([Hash PaymentKey] -> TxExtraKeyWitnesses era)
-> Gen [Hash PaymentKey] -> Gen (TxExtraKeyWitnesses era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [Hash PaymentKey] -> Gen [Hash PaymentKey]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen (Hash PaymentKey) -> Gen [Hash PaymentKey]
forall a. Gen a -> Gen [a]
listOf (AsType PaymentKey -> Gen (Hash PaymentKey)
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType PaymentKey
AsPaymentKey))
            ]

genTxTotalCollateral :: CardanoEra era -> Gen (TxTotalCollateral era)
genTxTotalCollateral :: CardanoEra era -> Gen (TxTotalCollateral era)
genTxTotalCollateral CardanoEra era
era =
    case CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra CardanoEra era
era of
        Maybe (TxTotalAndReturnCollateralSupportedInEra era)
Nothing -> TxTotalCollateral era -> Gen (TxTotalCollateral era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone
        Just TxTotalAndReturnCollateralSupportedInEra era
supported -> [Gen (TxTotalCollateral era)] -> Gen (TxTotalCollateral era)
forall a. [Gen a] -> Gen a
oneof
            [ TxTotalCollateral era -> Gen (TxTotalCollateral era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone
            , TxTotalAndReturnCollateralSupportedInEra era
-> Lovelace -> TxTotalCollateral era
forall era.
TxTotalAndReturnCollateralSupportedInEra era
-> Lovelace -> TxTotalCollateral era
TxTotalCollateral TxTotalAndReturnCollateralSupportedInEra era
supported (Lovelace -> TxTotalCollateral era)
-> Gen Lovelace -> Gen (TxTotalCollateral era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace
            ]

genTxReturnCollateral :: CardanoEra era -> Gen (TxReturnCollateral ctx era)
genTxReturnCollateral :: CardanoEra era -> Gen (TxReturnCollateral ctx era)
genTxReturnCollateral CardanoEra era
era =
    case CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra CardanoEra era
era of
        Maybe (TxTotalAndReturnCollateralSupportedInEra era)
Nothing -> TxReturnCollateral ctx era -> Gen (TxReturnCollateral ctx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxReturnCollateral ctx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone
        Just TxTotalAndReturnCollateralSupportedInEra era
supported -> [Gen (TxReturnCollateral ctx era)]
-> Gen (TxReturnCollateral ctx era)
forall a. [Gen a] -> Gen a
oneof
            [ TxReturnCollateral ctx era -> Gen (TxReturnCollateral ctx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxReturnCollateral ctx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone
            , TxTotalAndReturnCollateralSupportedInEra era
-> TxOut ctx era -> TxReturnCollateral ctx era
forall era ctx.
TxTotalAndReturnCollateralSupportedInEra era
-> TxOut ctx era -> TxReturnCollateral ctx era
TxReturnCollateral TxTotalAndReturnCollateralSupportedInEra era
supported (TxOut ctx era -> TxReturnCollateral ctx era)
-> Gen (TxOut ctx era) -> Gen (TxReturnCollateral ctx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era -> Gen (TxOut ctx era)
forall era ctx. CardanoEra era -> Gen (TxOut ctx era)
genTxOut CardanoEra era
era
            ]

genPlutusScript :: PlutusScriptVersion lang -> Gen (PlutusScript lang)
genPlutusScript :: PlutusScriptVersion lang -> Gen (PlutusScript lang)
genPlutusScript PlutusScriptVersion lang
_ =
    -- We make no attempt to create a valid script
    ShortByteString -> PlutusScript lang
forall lang. ShortByteString -> PlutusScript lang
PlutusScriptSerialised (ShortByteString -> PlutusScript lang)
-> (ByteString -> ShortByteString)
-> ByteString
-> PlutusScript lang
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ShortByteString
SBS.toShort (ByteString -> PlutusScript lang)
-> Gen ByteString -> Gen (PlutusScript lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ByteString
forall a. Arbitrary a => Gen a
arbitrary

genPlutusScriptOrReferenceInput
    :: PlutusScriptVersion lang
    -> Gen (PlutusScriptOrReferenceInput lang)
genPlutusScriptOrReferenceInput :: PlutusScriptVersion lang -> Gen (PlutusScriptOrReferenceInput lang)
genPlutusScriptOrReferenceInput PlutusScriptVersion lang
lang =
    -- TODO add proper generator, perhaps as part of ADP-1655
    PlutusScript lang -> PlutusScriptOrReferenceInput lang
forall lang. PlutusScript lang -> PlutusScriptOrReferenceInput lang
PScript (PlutusScript lang -> PlutusScriptOrReferenceInput lang)
-> Gen (PlutusScript lang)
-> Gen (PlutusScriptOrReferenceInput lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PlutusScriptVersion lang -> Gen (PlutusScript lang)
forall lang. PlutusScriptVersion lang -> Gen (PlutusScript lang)
genPlutusScript PlutusScriptVersion lang
lang

genSimpleScript :: SimpleScriptVersion lang -> Gen (SimpleScript lang)
genSimpleScript :: SimpleScriptVersion lang -> Gen (SimpleScript lang)
genSimpleScript SimpleScriptVersion lang
lang =
    (Int -> Gen (SimpleScript lang)) -> Gen (SimpleScript lang)
forall a. (Int -> Gen a) -> Gen a
sized Int -> Gen (SimpleScript lang)
genTerm
  where
    genTerm :: Int -> Gen (SimpleScript lang)
genTerm Int
0 = [Gen (SimpleScript lang)] -> Gen (SimpleScript lang)
forall a. [Gen a] -> Gen a
oneof [Gen (SimpleScript lang)]
nonRecursive
    genTerm Int
n = [(Int, Gen (SimpleScript lang))] -> Gen (SimpleScript lang)
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
3, [Gen (SimpleScript lang)] -> Gen (SimpleScript lang)
forall a. [Gen a] -> Gen a
oneof (Int -> [Gen (SimpleScript lang)]
recursive Int
n))
        , (Int
1, [Gen (SimpleScript lang)] -> Gen (SimpleScript lang)
forall a. [Gen a] -> Gen a
oneof [Gen (SimpleScript lang)]
nonRecursive)
        ]

    -- Non-recursive generators
    nonRecursive :: [Gen (SimpleScript lang)]
nonRecursive =
        (Hash PaymentKey -> SimpleScript lang
forall lang. Hash PaymentKey -> SimpleScript lang
RequireSignature (Hash PaymentKey -> SimpleScript lang)
-> (VerificationKey PaymentKey -> Hash PaymentKey)
-> VerificationKey PaymentKey
-> SimpleScript lang
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerificationKey PaymentKey -> Hash PaymentKey
forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash (VerificationKey PaymentKey -> SimpleScript lang)
-> Gen (VerificationKey PaymentKey) -> Gen (SimpleScript lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
            AsType PaymentKey -> Gen (VerificationKey PaymentKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey AsType PaymentKey
AsPaymentKey)

      Gen (SimpleScript lang)
-> [Gen (SimpleScript lang)] -> [Gen (SimpleScript lang)]
forall a. a -> [a] -> [a]
: [ TimeLocksSupported lang -> SlotNo -> SimpleScript lang
forall lang. TimeLocksSupported lang -> SlotNo -> SimpleScript lang
RequireTimeBefore TimeLocksSupported lang
supported (SlotNo -> SimpleScript lang)
-> Gen SlotNo -> Gen (SimpleScript lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SlotNo
genSlotNo
        | TimeLocksSupported lang
supported <- Maybe (TimeLocksSupported lang) -> [TimeLocksSupported lang]
forall a. Maybe a -> [a]
maybeToList (SimpleScriptVersion lang -> Maybe (TimeLocksSupported lang)
forall lang.
SimpleScriptVersion lang -> Maybe (TimeLocksSupported lang)
timeLocksSupported SimpleScriptVersion lang
lang) ]

     [Gen (SimpleScript lang)]
-> [Gen (SimpleScript lang)] -> [Gen (SimpleScript lang)]
forall a. [a] -> [a] -> [a]
++ [ TimeLocksSupported lang -> SlotNo -> SimpleScript lang
forall lang. TimeLocksSupported lang -> SlotNo -> SimpleScript lang
RequireTimeAfter TimeLocksSupported lang
supported (SlotNo -> SimpleScript lang)
-> Gen SlotNo -> Gen (SimpleScript lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SlotNo
genSlotNo
        | TimeLocksSupported lang
supported <- Maybe (TimeLocksSupported lang) -> [TimeLocksSupported lang]
forall a. Maybe a -> [a]
maybeToList (SimpleScriptVersion lang -> Maybe (TimeLocksSupported lang)
forall lang.
SimpleScriptVersion lang -> Maybe (TimeLocksSupported lang)
timeLocksSupported SimpleScriptVersion lang
lang) ]

    -- Recursive generators
    recursive :: Int -> [Gen (SimpleScript lang)]
recursive Int
n =
        [ [SimpleScript lang] -> SimpleScript lang
forall lang. [SimpleScript lang] -> SimpleScript lang
RequireAllOf ([SimpleScript lang] -> SimpleScript lang)
-> Gen [SimpleScript lang] -> Gen (SimpleScript lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [SimpleScript lang] -> Gen [SimpleScript lang]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
10) (Gen (SimpleScript lang) -> Gen [SimpleScript lang]
forall a. Gen a -> Gen [a]
listOf (Gen (SimpleScript lang) -> Gen [SimpleScript lang])
-> Gen (SimpleScript lang) -> Gen [SimpleScript lang]
forall a b. (a -> b) -> a -> b
$ Int -> Gen (SimpleScript lang)
recurse Int
n)

        , [SimpleScript lang] -> SimpleScript lang
forall lang. [SimpleScript lang] -> SimpleScript lang
RequireAnyOf ([SimpleScript lang] -> SimpleScript lang)
-> Gen [SimpleScript lang] -> Gen (SimpleScript lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [SimpleScript lang] -> Gen [SimpleScript lang]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
10) (Gen (SimpleScript lang) -> Gen [SimpleScript lang]
forall a. Gen a -> Gen [a]
listOf (Gen (SimpleScript lang) -> Gen [SimpleScript lang])
-> Gen (SimpleScript lang) -> Gen [SimpleScript lang]
forall a b. (a -> b) -> a -> b
$ Int -> Gen (SimpleScript lang)
recurse Int
n)

        , do [SimpleScript lang]
ts <- (Int -> Int) -> Gen [SimpleScript lang] -> Gen [SimpleScript lang]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
10) (Gen [SimpleScript lang] -> Gen [SimpleScript lang])
-> Gen [SimpleScript lang] -> Gen [SimpleScript lang]
forall a b. (a -> b) -> a -> b
$ Gen (SimpleScript lang) -> Gen [SimpleScript lang]
forall a. Gen a -> Gen [a]
listOf (Gen (SimpleScript lang) -> Gen [SimpleScript lang])
-> Gen (SimpleScript lang) -> Gen [SimpleScript lang]
forall a b. (a -> b) -> a -> b
$ Int -> Gen (SimpleScript lang)
recurse Int
n
             Int
m  <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, [SimpleScript lang] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [SimpleScript lang]
ts)
             SimpleScript lang -> Gen (SimpleScript lang)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> [SimpleScript lang] -> SimpleScript lang
forall lang. Int -> [SimpleScript lang] -> SimpleScript lang
RequireMOf Int
m [SimpleScript lang]
ts)
        ]

    recurse :: Int -> Gen (SimpleScript lang)
recurse Int
n = do
        (Positive Int
m) <- Gen (Positive Int)
forall a. Arbitrary a => Gen a
arbitrary
        Int -> Gen (SimpleScript lang)
genTerm (Int
n Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3))

genReferenceInput :: Gen TxIn
genReferenceInput :: Gen TxIn
genReferenceInput = Gen TxIn
genTxIn

genSimpleScriptOrReferenceInput
    :: SimpleScriptVersion lang
    -> Gen (SimpleScriptOrReferenceInput lang)
genSimpleScriptOrReferenceInput :: SimpleScriptVersion lang -> Gen (SimpleScriptOrReferenceInput lang)
genSimpleScriptOrReferenceInput SimpleScriptVersion lang
lang =
    [Gen (SimpleScriptOrReferenceInput lang)]
-> Gen (SimpleScriptOrReferenceInput lang)
forall a. [Gen a] -> Gen a
oneof [ SimpleScript lang -> SimpleScriptOrReferenceInput lang
forall lang. SimpleScript lang -> SimpleScriptOrReferenceInput lang
SScript
            (SimpleScript lang -> SimpleScriptOrReferenceInput lang)
-> Gen (SimpleScript lang)
-> Gen (SimpleScriptOrReferenceInput lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleScriptVersion lang -> Gen (SimpleScript lang)
forall lang. SimpleScriptVersion lang -> Gen (SimpleScript lang)
genSimpleScript SimpleScriptVersion lang
lang
          , TxIn -> Maybe ScriptHash -> SimpleScriptOrReferenceInput lang
forall lang.
TxIn -> Maybe ScriptHash -> SimpleScriptOrReferenceInput lang
SReferenceScript
            (TxIn -> Maybe ScriptHash -> SimpleScriptOrReferenceInput lang)
-> Gen TxIn
-> Gen (Maybe ScriptHash -> SimpleScriptOrReferenceInput lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxIn
genReferenceInput
            Gen (Maybe ScriptHash -> SimpleScriptOrReferenceInput lang)
-> Gen (Maybe ScriptHash)
-> Gen (SimpleScriptOrReferenceInput lang)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ScriptHash -> Gen (Maybe ScriptHash)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ScriptHash
genScriptHash
          ]

genScript :: ScriptLanguage lang -> Gen (Script lang)
genScript :: ScriptLanguage lang -> Gen (Script lang)
genScript (SimpleScriptLanguage SimpleScriptVersion lang
lang) =
    SimpleScriptVersion lang -> SimpleScript lang -> Script lang
forall lang.
SimpleScriptVersion lang -> SimpleScript lang -> Script lang
SimpleScript SimpleScriptVersion lang
lang (SimpleScript lang -> Script lang)
-> Gen (SimpleScript lang) -> Gen (Script lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleScriptVersion lang -> Gen (SimpleScript lang)
forall lang. SimpleScriptVersion lang -> Gen (SimpleScript lang)
genSimpleScript SimpleScriptVersion lang
lang
genScript (PlutusScriptLanguage PlutusScriptVersion lang
lang) =
    PlutusScriptVersion lang -> PlutusScript lang -> Script lang
forall lang.
PlutusScriptVersion lang -> PlutusScript lang -> Script lang
PlutusScript PlutusScriptVersion lang
lang (PlutusScript lang -> Script lang)
-> Gen (PlutusScript lang) -> Gen (Script lang)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PlutusScriptVersion lang -> Gen (PlutusScript lang)
forall lang. PlutusScriptVersion lang -> Gen (PlutusScript lang)
genPlutusScript PlutusScriptVersion lang
lang

genScriptInAnyLang :: Gen ScriptInAnyLang
genScriptInAnyLang :: Gen ScriptInAnyLang
genScriptInAnyLang =
    [Gen ScriptInAnyLang] -> Gen ScriptInAnyLang
forall a. [Gen a] -> Gen a
oneof
      [ ScriptLanguage lang -> Script lang -> ScriptInAnyLang
forall lang. ScriptLanguage lang -> Script lang -> ScriptInAnyLang
ScriptInAnyLang ScriptLanguage lang
lang (Script lang -> ScriptInAnyLang)
-> Gen (Script lang) -> Gen ScriptInAnyLang
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptLanguage lang -> Gen (Script lang)
forall lang. ScriptLanguage lang -> Gen (Script lang)
genScript ScriptLanguage lang
lang
      | AnyScriptLanguage ScriptLanguage lang
lang <- [AnyScriptLanguage
forall a. Bounded a => a
minBound..AnyScriptLanguage
forall a. Bounded a => a
maxBound] ]

genScriptInEra :: CardanoEra era -> Gen (ScriptInEra era)
genScriptInEra :: CardanoEra era -> Gen (ScriptInEra era)
genScriptInEra CardanoEra era
era =
    [Gen (ScriptInEra era)] -> Gen (ScriptInEra era)
forall a. [Gen a] -> Gen a
oneof
      [ ScriptLanguageInEra lang era -> Script lang -> ScriptInEra era
forall lang era.
ScriptLanguageInEra lang era -> Script lang -> ScriptInEra era
ScriptInEra ScriptLanguageInEra lang era
langInEra (Script lang -> ScriptInEra era)
-> Gen (Script lang) -> Gen (ScriptInEra era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptLanguage lang -> Gen (Script lang)
forall lang. ScriptLanguage lang -> Gen (Script lang)
genScript ScriptLanguage lang
lang
      | AnyScriptLanguage ScriptLanguage lang
lang <- [AnyScriptLanguage
forall a. Bounded a => a
minBound..AnyScriptLanguage
forall a. Bounded a => a
maxBound]
      , Just ScriptLanguageInEra lang era
langInEra <- [CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
forall era lang.
CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
scriptLanguageSupportedInEra CardanoEra era
era ScriptLanguage lang
lang] ]

genScriptHash :: Gen ScriptHash
genScriptHash :: Gen ScriptHash
genScriptHash = do
    ScriptInAnyLang ScriptLanguage lang
_ Script lang
script <- Gen ScriptInAnyLang
genScriptInAnyLang
    ScriptHash -> Gen ScriptHash
forall (m :: * -> *) a. Monad m => a -> m a
return (Script lang -> ScriptHash
forall lang. Script lang -> ScriptHash
hashScript Script lang
script)

genAssetName :: Gen AssetName
genAssetName :: Gen AssetName
genAssetName =
  [(Int, Gen AssetName)] -> Gen AssetName
forall a. [(Int, Gen a)] -> Gen a
frequency
    -- mostly from a small number of choices, so we get plenty of repetition
    [ (Int
9, [AssetName] -> Gen AssetName
forall a. [a] -> Gen a
elements [AssetName
"", AssetName
"a", AssetName
"b", AssetName
"c"])
    , (Int
1, ByteString -> AssetName
AssetName (ByteString -> AssetName)
-> ([Char] -> ByteString) -> [Char] -> AssetName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
forall a. IsString a => [Char] -> a
fromString ([Char] -> AssetName) -> Gen [Char] -> Gen AssetName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Int -> Int) -> Gen [Char] -> Gen [Char]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
32) (Gen Char -> Gen [Char]
forall a. Gen a -> Gen [a]
listOf Gen Char
genAlphaNum)))
    , (Int
1, ByteString -> AssetName
AssetName (ByteString -> AssetName)
-> ([Char] -> ByteString) -> [Char] -> AssetName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
forall a. IsString a => [Char] -> a
fromString ([Char] -> AssetName) -> Gen [Char] -> Gen AssetName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Gen Char -> Gen [Char]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
1 Gen Char
genAlphaNum))
    , (Int
1, ByteString -> AssetName
AssetName (ByteString -> AssetName)
-> ([Char] -> ByteString) -> [Char] -> AssetName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
forall a. IsString a => [Char] -> a
fromString ([Char] -> AssetName) -> Gen [Char] -> Gen AssetName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Gen Char -> Gen [Char]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
32 Gen Char
genAlphaNum))
    ]

genAlphaNum :: Gen Char
genAlphaNum :: Gen Char
genAlphaNum = [Char] -> Gen Char
forall a. [a] -> Gen a
elements
    [Char]
"abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

genPolicyId :: Gen PolicyId
genPolicyId :: Gen PolicyId
genPolicyId = [(Int, Gen PolicyId)] -> Gen PolicyId
forall a. [(Int, Gen a)] -> Gen a
frequency
      -- Mostly from a small number of choices, so we get plenty of repetition.
      --
      -- And because of the additional choice of asset name we repeat ourselves
      -- even more here.
    [ (Int
80, PolicyId -> Gen PolicyId
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PolicyId -> Gen PolicyId) -> PolicyId -> Gen PolicyId
forall a b. (a -> b) -> a -> b
$ [Char] -> PolicyId
forall a. IsString a => [Char] -> a
fromString (Char
'a' Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int -> Char -> [Char]
forall a. Int -> a -> [a]
replicate Int
55 Char
'0'))
    , (Int
18, [PolicyId] -> Gen PolicyId
forall a. [a] -> Gen a
elements [ [Char] -> PolicyId
forall a. IsString a => [Char] -> a
fromString (Char
x Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int -> Char -> [Char]
forall a. Int -> a -> [a]
replicate Int
55 Char
'0') | Char
x <- [Char
'a'..Char
'c'] ])
       -- and some from the full range of the type
    , (Int
2, ScriptHash -> PolicyId
PolicyId (ScriptHash -> PolicyId) -> Gen ScriptHash -> Gen PolicyId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ScriptHash
genScriptHash)
    ]

genAssetIdNoAda :: Gen AssetId
genAssetIdNoAda :: Gen AssetId
genAssetIdNoAda = PolicyId -> AssetName -> AssetId
AssetId (PolicyId -> AssetName -> AssetId)
-> Gen PolicyId -> Gen (AssetName -> AssetId)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen PolicyId
genPolicyId Gen (AssetName -> AssetId) -> Gen AssetName -> Gen AssetId
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen AssetName
genAssetName

-- | Generate a positive or negative quantity.
genSignedQuantity :: Gen Quantity
genSignedQuantity :: Gen Quantity
genSignedQuantity = do
    (Large (Int64
n :: Int64)) <- Gen (Large Int64)
forall a. Arbitrary a => Gen a
arbitrary
    Quantity -> Gen Quantity
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Quantity -> Gen Quantity) -> Quantity -> Gen Quantity
forall a b. (a -> b) -> a -> b
$ Int64 -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
n

-- | Generate a 'Value' suitable for usage in a transaction output, i.e. any
-- asset ID and a positive quantity.
genValueForTxOut :: Gen Value
genValueForTxOut :: Gen Value
genValueForTxOut = do
    [AssetId]
assetIds <- [Gen [AssetId]] -> Gen [AssetId]
forall a. [Gen a] -> Gen a
oneof
        [ [AssetId] -> [AssetId]
forall a. Eq a => [a] -> [a]
nub ([AssetId] -> [AssetId]) -> Gen [AssetId] -> Gen [AssetId]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [AssetId] -> Gen [AssetId]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4) (Gen AssetId -> Gen [AssetId]
forall a. Gen a -> Gen [a]
listOf Gen AssetId
genAssetIdNoAda)
        , [AssetId] -> Gen [AssetId]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        ]
    [Quantity]
assetQuantities <- Gen Quantity -> Gen [Quantity]
forall a. Gen a -> Gen [a]
infiniteListOf Gen Quantity
genUnsignedQuantity
    Quantity
ada <- Integer -> Quantity
forall a. Num a => Integer -> a
fromInteger (Integer -> Quantity)
-> (Lovelace -> Integer) -> Lovelace -> Quantity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lovelace -> Integer
unLovelace (Lovelace -> Quantity) -> Gen Lovelace -> Gen Quantity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace
    Value -> Gen Value
forall (m :: * -> *) a. Monad m => a -> m a
return (Value -> Gen Value) -> Value -> Gen Value
forall a b. (a -> b) -> a -> b
$ [(AssetId, Quantity)] -> Value
valueFromList ([(AssetId, Quantity)] -> Value) -> [(AssetId, Quantity)] -> Value
forall a b. (a -> b) -> a -> b
$ (AssetId
AdaAssetId, Quantity
ada) (AssetId, Quantity)
-> [(AssetId, Quantity)] -> [(AssetId, Quantity)]
forall a. a -> [a] -> [a]
: [AssetId] -> [Quantity] -> [(AssetId, Quantity)]
forall a b. [a] -> [b] -> [(a, b)]
zip [AssetId]
assetIds [Quantity]
assetQuantities
  where
    unLovelace :: Lovelace -> Integer
unLovelace (Lovelace Integer
l) = Integer
l

-- | Generate a 'Value' which could represent the balance of a partial
-- transaction, where both ada and other assets can be included, and quantities
-- can be both positive and negative.
genSignedValue :: Gen Value
genSignedValue :: Gen Value
genSignedValue = do
    [AssetId]
assetIds <- [Gen [AssetId]] -> Gen [AssetId]
forall a. [Gen a] -> Gen a
oneof
        [ [AssetId] -> [AssetId]
forall a. Eq a => [a] -> [a]
nub ([AssetId] -> [AssetId]) -> Gen [AssetId] -> Gen [AssetId]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [AssetId] -> Gen [AssetId]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4) (Gen AssetId -> Gen [AssetId]
forall a. Gen a -> Gen [a]
listOf Gen AssetId
genAssetIdNoAda)
        , [AssetId] -> Gen [AssetId]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        ]
    [Quantity]
assetQuantities <- Gen Quantity -> Gen [Quantity]
forall a. Gen a -> Gen [a]
infiniteListOf Gen Quantity
genSignedQuantity
    Quantity
ada <- Integer -> Quantity
forall a. Num a => Integer -> a
fromInteger (Integer -> Quantity)
-> (Lovelace -> Integer) -> Lovelace -> Quantity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lovelace -> Integer
unLovelace (Lovelace -> Quantity) -> Gen Lovelace -> Gen Quantity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Gen Lovelace] -> Gen Lovelace
forall a. [Gen a] -> Gen a
oneof
        [ Gen Lovelace
genLovelace
        , Lovelace -> Lovelace
forall a. Num a => a -> a
negate (Lovelace -> Lovelace) -> Gen Lovelace -> Gen Lovelace
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace
        ]
    Value -> Gen Value
forall (m :: * -> *) a. Monad m => a -> m a
return (Value -> Gen Value) -> Value -> Gen Value
forall a b. (a -> b) -> a -> b
$ [(AssetId, Quantity)] -> Value
valueFromList ([(AssetId, Quantity)] -> Value) -> [(AssetId, Quantity)] -> Value
forall a b. (a -> b) -> a -> b
$ (AssetId
AdaAssetId, Quantity
ada) (AssetId, Quantity)
-> [(AssetId, Quantity)] -> [(AssetId, Quantity)]
forall a. a -> [a] -> [a]
: [AssetId] -> [Quantity] -> [(AssetId, Quantity)]
forall a b. [a] -> [b] -> [(a, b)]
zip [AssetId]
assetIds [Quantity]
assetQuantities
  where
    unLovelace :: Lovelace -> Integer
unLovelace (Lovelace Integer
l) = Integer
l

-- | Generate a 'Value' suitable for minting, i.e. non-ADA asset ID and a
-- positive or negative quantity.
genValueForMinting :: Gen Value
genValueForMinting :: Gen Value
genValueForMinting =
  [(AssetId, Quantity)] -> Value
valueFromList ([(AssetId, Quantity)] -> Value)
-> Gen [(AssetId, Quantity)] -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (AssetId, Quantity) -> Gen [(AssetId, Quantity)]
forall a. Gen a -> Gen [a]
listOf ((,) (AssetId -> Quantity -> (AssetId, Quantity))
-> Gen AssetId -> Gen (Quantity -> (AssetId, Quantity))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen AssetId
genAssetIdNoAda Gen (Quantity -> (AssetId, Quantity))
-> Gen Quantity -> Gen (AssetId, Quantity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Quantity
genSignedQuantity)

genTxMintValue :: forall era. CardanoEra era -> Gen (TxMintValue BuildTx era)
genTxMintValue :: CardanoEra era -> Gen (TxMintValue BuildTx era)
genTxMintValue CardanoEra era
era =
  case CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra era
era of
    Left OnlyAdaSupportedInEra era
_ -> TxMintValue BuildTx era -> Gen (TxMintValue BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxMintValue BuildTx era
forall build era. TxMintValue build era
TxMintNone
    Right MultiAssetSupportedInEra era
supported -> do
      let
          scriptWitnessGenerators :: [Gen (ScriptWitness WitCtxMint era)]
          scriptWitnessGenerators :: [Gen (ScriptWitness WitCtxMint era)]
scriptWitnessGenerators =
              [ ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxMint era)
forall lang era.
ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxMint era)
genScriptWitnessMint ScriptLanguageInEra lang era
langInEra
              | AnyScriptLanguage ScriptLanguage lang
lang <- [AnyScriptLanguage
forall a. Bounded a => a
minBound..AnyScriptLanguage
forall a. Bounded a => a
maxBound]
              , Just ScriptLanguageInEra lang era
langInEra <- [CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
forall era lang.
CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
scriptLanguageSupportedInEra CardanoEra era
era ScriptLanguage lang
lang]
              ]
      [Gen (TxMintValue BuildTx era)] -> Gen (TxMintValue BuildTx era)
forall a. [Gen a] -> Gen a
oneof
        [ TxMintValue BuildTx era -> Gen (TxMintValue BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxMintValue BuildTx era
forall build era. TxMintValue build era
TxMintNone
        , MultiAssetSupportedInEra era
-> Value
-> BuildTxWith
     BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
-> TxMintValue BuildTx era
forall era build.
MultiAssetSupportedInEra era
-> Value
-> BuildTxWith build (Map PolicyId (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MultiAssetSupportedInEra era
supported
          (Value
 -> BuildTxWith
      BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
 -> TxMintValue BuildTx era)
-> Gen Value
-> Gen
     (BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
      -> TxMintValue BuildTx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genValueForMinting
          Gen
  (BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
   -> TxMintValue BuildTx era)
-> Gen
     (BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era)))
-> Gen (TxMintValue BuildTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( (Map PolicyId (ScriptWitness WitCtxMint era)
-> BuildTxWith
     BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Map PolicyId (ScriptWitness WitCtxMint era)
 -> BuildTxWith
      BuildTx (Map PolicyId (ScriptWitness WitCtxMint era)))
-> ([(PolicyId, ScriptWitness WitCtxMint era)]
    -> Map PolicyId (ScriptWitness WitCtxMint era))
-> [(PolicyId, ScriptWitness WitCtxMint era)]
-> BuildTxWith
     BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(PolicyId, ScriptWitness WitCtxMint era)]
-> Map PolicyId (ScriptWitness WitCtxMint era)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList)
                ([(PolicyId, ScriptWitness WitCtxMint era)]
 -> BuildTxWith
      BuildTx (Map PolicyId (ScriptWitness WitCtxMint era)))
-> Gen [(PolicyId, ScriptWitness WitCtxMint era)]
-> Gen
     (BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int)
-> Gen [(PolicyId, ScriptWitness WitCtxMint era)]
-> Gen [(PolicyId, ScriptWitness WitCtxMint era)]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen (PolicyId, ScriptWitness WitCtxMint era)
-> Gen [(PolicyId, ScriptWitness WitCtxMint era)]
forall a. Gen a -> Gen [a]
listOf ( (,)
                             (PolicyId
 -> ScriptWitness WitCtxMint era
 -> (PolicyId, ScriptWitness WitCtxMint era))
-> Gen PolicyId
-> Gen
     (ScriptWitness WitCtxMint era
      -> (PolicyId, ScriptWitness WitCtxMint era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen PolicyId
genPolicyId
                             Gen
  (ScriptWitness WitCtxMint era
   -> (PolicyId, ScriptWitness WitCtxMint era))
-> Gen (ScriptWitness WitCtxMint era)
-> Gen (PolicyId, ScriptWitness WitCtxMint era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Gen (ScriptWitness WitCtxMint era)]
-> Gen (ScriptWitness WitCtxMint era)
forall a. [Gen a] -> Gen a
oneof [Gen (ScriptWitness WitCtxMint era)]
scriptWitnessGenerators
                           ))
              )
        ]

genNetworkMagic :: Gen NetworkMagic
genNetworkMagic :: Gen NetworkMagic
genNetworkMagic = do
    (Large Word32
n) <- Gen (Large Word32)
forall a. Arbitrary a => Gen a
arbitrary
    NetworkMagic -> Gen NetworkMagic
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NetworkMagic -> Gen NetworkMagic)
-> NetworkMagic -> Gen NetworkMagic
forall a b. (a -> b) -> a -> b
$ Word32 -> NetworkMagic
NetworkMagic Word32
n

genNetworkId :: Gen NetworkId
genNetworkId :: Gen NetworkId
genNetworkId =
    [(Int, Gen NetworkId)] -> Gen NetworkId
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
95, NetworkId -> Gen NetworkId
forall (f :: * -> *) a. Applicative f => a -> f a
pure NetworkId
Mainnet)
        , (Int
5, NetworkMagic -> NetworkId
Testnet (NetworkMagic -> NetworkId) -> Gen NetworkMagic -> Gen NetworkId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen NetworkMagic
genNetworkMagic)
        ]

genStakeCredential :: Gen StakeCredential
genStakeCredential :: Gen StakeCredential
genStakeCredential =
  [Gen StakeCredential] -> Gen StakeCredential
forall a. [Gen a] -> Gen a
oneof
    [ Gen StakeCredential
byKey
    , Gen StakeCredential
byScript
    ]

  where
      byKey :: Gen StakeCredential
byKey = do
          VerificationKey StakeKey
vKey <- AsType StakeKey -> Gen (VerificationKey StakeKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey AsType StakeKey
AsStakeKey
          StakeCredential -> Gen StakeCredential
forall (m :: * -> *) a. Monad m => a -> m a
return (StakeCredential -> Gen StakeCredential)
-> (Hash StakeKey -> StakeCredential)
-> Hash StakeKey
-> Gen StakeCredential
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash StakeKey -> StakeCredential
StakeCredentialByKey (Hash StakeKey -> Gen StakeCredential)
-> Hash StakeKey -> Gen StakeCredential
forall a b. (a -> b) -> a -> b
$ VerificationKey StakeKey -> Hash StakeKey
forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash VerificationKey StakeKey
vKey

      byScript :: Gen StakeCredential
byScript = ScriptHash -> StakeCredential
StakeCredentialByScript (ScriptHash -> StakeCredential)
-> Gen ScriptHash -> Gen StakeCredential
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ScriptHash
genScriptHash

genStakeAddress :: Gen StakeAddress
genStakeAddress :: Gen StakeAddress
genStakeAddress = NetworkId -> StakeCredential -> StakeAddress
makeStakeAddress (NetworkId -> StakeCredential -> StakeAddress)
-> Gen NetworkId -> Gen (StakeCredential -> StakeAddress)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen NetworkId
genNetworkId Gen (StakeCredential -> StakeAddress)
-> Gen StakeCredential -> Gen StakeAddress
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen StakeCredential
genStakeCredential

genScriptData :: Gen ScriptData
genScriptData :: Gen ScriptData
genScriptData =
    (Int -> Gen ScriptData) -> Gen ScriptData
forall a. (Int -> Gen a) -> Gen a
sized Int -> Gen ScriptData
genTerm

    where
        genTerm :: Int -> Gen ScriptData
genTerm Int
0 = [Gen ScriptData] -> Gen ScriptData
forall a. [Gen a] -> Gen a
oneof [Gen ScriptData]
nonRecursive
        genTerm Int
n = [(Int, Gen ScriptData)] -> Gen ScriptData
forall a. [(Int, Gen a)] -> Gen a
frequency
            [ (Int
1, Int -> Gen ScriptData
recursive Int
n)
            , (Int
3, [Gen ScriptData] -> Gen ScriptData
forall a. [Gen a] -> Gen a
oneof [Gen ScriptData]
nonRecursive)
            ]

        -- Non-recursive generators
        nonRecursive :: [Gen ScriptData]
nonRecursive =
            [ do
                 (Large (Int64
n :: Int64)) <- Gen (Large Int64)
forall a. Arbitrary a => Gen a
arbitrary
                 ScriptData -> Gen ScriptData
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScriptData -> Gen ScriptData) -> ScriptData -> Gen ScriptData
forall a b. (a -> b) -> a -> b
$ Integer -> ScriptData
ScriptDataNumber (Integer -> ScriptData) -> Integer -> ScriptData
forall a b. (a -> b) -> a -> b
$ Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
n
            , do
                 Int
n <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
64)
                 (ByteString -> ScriptData
ScriptDataBytes (ByteString -> ScriptData)
-> ([Word8] -> ByteString) -> [Word8] -> ScriptData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
BS.pack) ([Word8] -> ScriptData) -> Gen [Word8] -> Gen ScriptData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Word8]
forall a. Arbitrary a => Int -> Gen [a]
vector Int
n
            ]

        recursive :: Int -> Gen ScriptData
recursive Int
n = do
            Int
k <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
n)
            let smallerGen :: Gen ScriptData
smallerGen = Int -> Gen ScriptData
genTerm (Int
n Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
k Int
1))
            [Gen ScriptData] -> Gen ScriptData
forall a. [Gen a] -> Gen a
oneof
                [ [ScriptData] -> ScriptData
ScriptDataList ([ScriptData] -> ScriptData) -> Gen [ScriptData] -> Gen ScriptData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen ScriptData -> Gen [ScriptData]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
k Gen ScriptData
smallerGen
                , [(ScriptData, ScriptData)] -> ScriptData
ScriptDataMap ([(ScriptData, ScriptData)] -> ScriptData)
-> Gen [(ScriptData, ScriptData)] -> Gen ScriptData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> Gen (ScriptData, ScriptData) -> Gen [(ScriptData, ScriptData)]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
k ((,) (ScriptData -> ScriptData -> (ScriptData, ScriptData))
-> Gen ScriptData -> Gen (ScriptData -> (ScriptData, ScriptData))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ScriptData
smallerGen Gen (ScriptData -> (ScriptData, ScriptData))
-> Gen ScriptData -> Gen (ScriptData, ScriptData)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ScriptData
smallerGen)
                , Integer -> [ScriptData] -> ScriptData
ScriptDataConstructor (Integer -> [ScriptData] -> ScriptData)
-> Gen Integer -> Gen ([ScriptData] -> ScriptData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Integer
forall a. Arbitrary a => Gen a
arbitrary Gen ([ScriptData] -> ScriptData)
-> Gen [ScriptData] -> Gen ScriptData
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen ScriptData -> Gen [ScriptData]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
k Gen ScriptData
smallerGen
                ]

genExecutionUnits :: Gen ExecutionUnits
genExecutionUnits :: Gen ExecutionUnits
genExecutionUnits = do
    Large Word64
steps <- Gen (Large Word64)
forall a. Arbitrary a => Gen a
arbitrary
    Large Word64
mem <- Gen (Large Word64)
forall a. Arbitrary a => Gen a
arbitrary
    let fromWord64 :: Word64 -> Natural
fromWord64 = forall b. (Integral Word64, Num b) => Word64 -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64
    ExecutionUnits -> Gen ExecutionUnits
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ExecutionUnits -> Gen ExecutionUnits)
-> ExecutionUnits -> Gen ExecutionUnits
forall a b. (a -> b) -> a -> b
$ Natural -> Natural -> ExecutionUnits
ExecutionUnits (Word64 -> Natural
fromWord64 Word64
steps) (Word64 -> Natural
fromWord64 Word64
mem)

genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals BuildTx era)
genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals BuildTx era)
genTxWithdrawals CardanoEra era
era =
  case CardanoEra era -> Maybe (WithdrawalsSupportedInEra era)
forall era. CardanoEra era -> Maybe (WithdrawalsSupportedInEra era)
withdrawalsSupportedInEra CardanoEra era
era of
    Maybe (WithdrawalsSupportedInEra era)
Nothing ->
        TxWithdrawals BuildTx era -> Gen (TxWithdrawals BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxWithdrawals BuildTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
    Just WithdrawalsSupportedInEra era
supported -> do
        [(Int, Gen (TxWithdrawals BuildTx era))]
-> Gen (TxWithdrawals BuildTx era)
forall a. [(Int, Gen a)] -> Gen a
frequency
          [ ( Int
1 , TxWithdrawals BuildTx era -> Gen (TxWithdrawals BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxWithdrawals BuildTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone )
          , ( Int
1 , TxWithdrawals BuildTx era -> Gen (TxWithdrawals BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxWithdrawals BuildTx era -> Gen (TxWithdrawals BuildTx era))
-> TxWithdrawals BuildTx era -> Gen (TxWithdrawals BuildTx era)
forall a b. (a -> b) -> a -> b
$ WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> TxWithdrawals BuildTx era
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra era
supported [] )
          , ( Int
3 , WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> TxWithdrawals BuildTx era
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra era
supported
                  ([(StakeAddress, Lovelace,
   BuildTxWith BuildTx (Witness WitCtxStake era))]
 -> TxWithdrawals BuildTx era)
-> Gen
     [(StakeAddress, Lovelace,
       BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Gen (TxWithdrawals BuildTx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int)
-> Gen
     [(StakeAddress, Lovelace,
       BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Gen
     [(StakeAddress, Lovelace,
       BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen
  (StakeAddress, Lovelace,
   BuildTxWith BuildTx (Witness WitCtxStake era))
-> Gen
     [(StakeAddress, Lovelace,
       BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a. Gen a -> Gen [a]
listOf (CardanoEra era
-> Gen
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
forall era.
CardanoEra era
-> Gen
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
genWithdrawalInfo CardanoEra era
era))
            )
          ]

genWithdrawalInfo
    :: CardanoEra era
    -> Gen ( StakeAddress
           , Lovelace
           , BuildTxWith BuildTx (Witness WitCtxStake era)
           )
genWithdrawalInfo :: CardanoEra era
-> Gen
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
genWithdrawalInfo CardanoEra era
era = do
    StakeAddress
stakeAddr <- Gen StakeAddress
genStakeAddress
    Lovelace
amt <- Gen Lovelace
genLovelace
    BuildTxWith BuildTx (Witness WitCtxStake era)
wit <- Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxStake era
 -> BuildTxWith BuildTx (Witness WitCtxStake era))
-> Gen (Witness WitCtxStake era)
-> Gen (BuildTxWith BuildTx (Witness WitCtxStake era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era -> Gen (Witness WitCtxStake era)
forall era. CardanoEra era -> Gen (Witness WitCtxStake era)
genWitnessStake CardanoEra era
era
    (StakeAddress, Lovelace,
 BuildTxWith BuildTx (Witness WitCtxStake era))
-> Gen
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StakeAddress
stakeAddr, Lovelace
amt, BuildTxWith BuildTx (Witness WitCtxStake era)
wit)

genWitnessStake :: CardanoEra era -> Gen (Witness WitCtxStake era)
genWitnessStake :: CardanoEra era -> Gen (Witness WitCtxStake era)
genWitnessStake CardanoEra era
era = [Gen (Witness WitCtxStake era)] -> Gen (Witness WitCtxStake era)
forall a. [Gen a] -> Gen a
oneof ([Gen (Witness WitCtxStake era)] -> Gen (Witness WitCtxStake era))
-> [Gen (Witness WitCtxStake era)] -> Gen (Witness WitCtxStake era)
forall a b. (a -> b) -> a -> b
$
    [ Witness WitCtxStake era -> Gen (Witness WitCtxStake era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Witness WitCtxStake era -> Gen (Witness WitCtxStake era))
-> Witness WitCtxStake era -> Gen (Witness WitCtxStake era)
forall a b. (a -> b) -> a -> b
$ KeyWitnessInCtx WitCtxStake -> Witness WitCtxStake era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxStake
KeyWitnessForStakeAddr ]
    [Gen (Witness WitCtxStake era)]
-> [Gen (Witness WitCtxStake era)]
-> [Gen (Witness WitCtxStake era)]
forall a. Semigroup a => a -> a -> a
<> [ ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr
         (ScriptWitness WitCtxStake era -> Witness WitCtxStake era)
-> Gen (ScriptWitness WitCtxStake era)
-> Gen (Witness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxStake era)
forall lang era.
ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxStake era)
genScriptWitnessStake ScriptLanguageInEra lang era
langInEra
       | AnyScriptLanguage ScriptLanguage lang
lang <- [AnyScriptLanguage
forall a. Bounded a => a
minBound..AnyScriptLanguage
forall a. Bounded a => a
maxBound]
       , Just ScriptLanguageInEra lang era
langInEra <- [CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
forall era lang.
CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
scriptLanguageSupportedInEra CardanoEra era
era ScriptLanguage lang
lang]
       ]

genWitnessSpend :: CardanoEra era -> Gen (Witness WitCtxTxIn era)
genWitnessSpend :: CardanoEra era -> Gen (Witness WitCtxTxIn era)
genWitnessSpend CardanoEra era
era = [Gen (Witness WitCtxTxIn era)] -> Gen (Witness WitCtxTxIn era)
forall a. [Gen a] -> Gen a
oneof ([Gen (Witness WitCtxTxIn era)] -> Gen (Witness WitCtxTxIn era))
-> [Gen (Witness WitCtxTxIn era)] -> Gen (Witness WitCtxTxIn era)
forall a b. (a -> b) -> a -> b
$
    [ Witness WitCtxTxIn era -> Gen (Witness WitCtxTxIn era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Witness WitCtxTxIn era -> Gen (Witness WitCtxTxIn era))
-> Witness WitCtxTxIn era -> Gen (Witness WitCtxTxIn era)
forall a b. (a -> b) -> a -> b
$ KeyWitnessInCtx WitCtxTxIn -> Witness WitCtxTxIn era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxTxIn
KeyWitnessForSpending ]
    [Gen (Witness WitCtxTxIn era)]
-> [Gen (Witness WitCtxTxIn era)] -> [Gen (Witness WitCtxTxIn era)]
forall a. Semigroup a => a -> a -> a
<> [ ScriptWitnessInCtx WitCtxTxIn
-> ScriptWitness WitCtxTxIn era -> Witness WitCtxTxIn era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxTxIn
ScriptWitnessForSpending
         (ScriptWitness WitCtxTxIn era -> Witness WitCtxTxIn era)
-> Gen (ScriptWitness WitCtxTxIn era)
-> Gen (Witness WitCtxTxIn era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxTxIn era)
forall lang era.
ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxTxIn era)
genScriptWitnessSpend ScriptLanguageInEra lang era
langInEra
       | AnyScriptLanguage ScriptLanguage lang
lang <- [AnyScriptLanguage
forall a. Bounded a => a
minBound..AnyScriptLanguage
forall a. Bounded a => a
maxBound]
       , Just ScriptLanguageInEra lang era
langInEra <- [CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
forall era lang.
CardanoEra era
-> ScriptLanguage lang -> Maybe (ScriptLanguageInEra lang era)
scriptLanguageSupportedInEra CardanoEra era
era ScriptLanguage lang
lang]
       ]

genScriptWitnessMint
    :: ScriptLanguageInEra lang era
    -> Gen (ScriptWitness WitCtxMint era)
genScriptWitnessMint :: ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxMint era)
genScriptWitnessMint ScriptLanguageInEra lang era
langEra =
    case ScriptLanguageInEra lang era -> ScriptLanguage lang
forall lang era.
ScriptLanguageInEra lang era -> ScriptLanguage lang
languageOfScriptLanguageInEra ScriptLanguageInEra lang era
langEra of
        (SimpleScriptLanguage SimpleScriptVersion lang
ver) ->
            ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness WitCtxMint era
forall lang era witctx.
ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness witctx era
SimpleScriptWitness ScriptLanguageInEra lang era
langEra SimpleScriptVersion lang
ver (SimpleScriptOrReferenceInput lang -> ScriptWitness WitCtxMint era)
-> Gen (SimpleScriptOrReferenceInput lang)
-> Gen (ScriptWitness WitCtxMint era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleScriptVersion lang -> Gen (SimpleScriptOrReferenceInput lang)
forall lang.
SimpleScriptVersion lang -> Gen (SimpleScriptOrReferenceInput lang)
genSimpleScriptOrReferenceInput SimpleScriptVersion lang
ver
        (PlutusScriptLanguage PlutusScriptVersion lang
ver) ->
            ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum WitCtxMint
-> ScriptData
-> ExecutionUnits
-> ScriptWitness WitCtxMint era
forall lang era witctx.
ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptData
-> ExecutionUnits
-> ScriptWitness witctx era
PlutusScriptWitness ScriptLanguageInEra lang era
langEra PlutusScriptVersion lang
ver
            (PlutusScriptOrReferenceInput lang
 -> ScriptDatum WitCtxMint
 -> ScriptData
 -> ExecutionUnits
 -> ScriptWitness WitCtxMint era)
-> Gen (PlutusScriptOrReferenceInput lang)
-> Gen
     (ScriptDatum WitCtxMint
      -> ScriptData -> ExecutionUnits -> ScriptWitness WitCtxMint era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PlutusScriptVersion lang -> Gen (PlutusScriptOrReferenceInput lang)
forall lang.
PlutusScriptVersion lang -> Gen (PlutusScriptOrReferenceInput lang)
genPlutusScriptOrReferenceInput PlutusScriptVersion lang
ver
            Gen
  (ScriptDatum WitCtxMint
   -> ScriptData -> ExecutionUnits -> ScriptWitness WitCtxMint era)
-> Gen (ScriptDatum WitCtxMint)
-> Gen
     (ScriptData -> ExecutionUnits -> ScriptWitness WitCtxMint era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ScriptDatum WitCtxMint -> Gen (ScriptDatum WitCtxMint)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScriptDatum WitCtxMint
NoScriptDatumForMint
            Gen (ScriptData -> ExecutionUnits -> ScriptWitness WitCtxMint era)
-> Gen ScriptData
-> Gen (ExecutionUnits -> ScriptWitness WitCtxMint era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ScriptData
genScriptData
            Gen (ExecutionUnits -> ScriptWitness WitCtxMint era)
-> Gen ExecutionUnits -> Gen (ScriptWitness WitCtxMint era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ExecutionUnits
genExecutionUnits

genScriptWitnessStake
    :: ScriptLanguageInEra lang era
    -> Gen (ScriptWitness WitCtxStake era)
genScriptWitnessStake :: ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxStake era)
genScriptWitnessStake ScriptLanguageInEra lang era
langEra =
    case ScriptLanguageInEra lang era -> ScriptLanguage lang
forall lang era.
ScriptLanguageInEra lang era -> ScriptLanguage lang
languageOfScriptLanguageInEra ScriptLanguageInEra lang era
langEra of
        (SimpleScriptLanguage SimpleScriptVersion lang
ver) ->
            ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness WitCtxStake era
forall lang era witctx.
ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness witctx era
SimpleScriptWitness ScriptLanguageInEra lang era
langEra SimpleScriptVersion lang
ver (SimpleScriptOrReferenceInput lang
 -> ScriptWitness WitCtxStake era)
-> Gen (SimpleScriptOrReferenceInput lang)
-> Gen (ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleScriptVersion lang -> Gen (SimpleScriptOrReferenceInput lang)
forall lang.
SimpleScriptVersion lang -> Gen (SimpleScriptOrReferenceInput lang)
genSimpleScriptOrReferenceInput SimpleScriptVersion lang
ver
        (PlutusScriptLanguage PlutusScriptVersion lang
ver) ->
            ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum WitCtxStake
-> ScriptData
-> ExecutionUnits
-> ScriptWitness WitCtxStake era
forall lang era witctx.
ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptData
-> ExecutionUnits
-> ScriptWitness witctx era
PlutusScriptWitness ScriptLanguageInEra lang era
langEra PlutusScriptVersion lang
ver
            (PlutusScriptOrReferenceInput lang
 -> ScriptDatum WitCtxStake
 -> ScriptData
 -> ExecutionUnits
 -> ScriptWitness WitCtxStake era)
-> Gen (PlutusScriptOrReferenceInput lang)
-> Gen
     (ScriptDatum WitCtxStake
      -> ScriptData -> ExecutionUnits -> ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PlutusScriptVersion lang -> Gen (PlutusScriptOrReferenceInput lang)
forall lang.
PlutusScriptVersion lang -> Gen (PlutusScriptOrReferenceInput lang)
genPlutusScriptOrReferenceInput PlutusScriptVersion lang
ver
            Gen
  (ScriptDatum WitCtxStake
   -> ScriptData -> ExecutionUnits -> ScriptWitness WitCtxStake era)
-> Gen (ScriptDatum WitCtxStake)
-> Gen
     (ScriptData -> ExecutionUnits -> ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ScriptDatum WitCtxStake -> Gen (ScriptDatum WitCtxStake)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScriptDatum WitCtxStake
NoScriptDatumForStake
            Gen (ScriptData -> ExecutionUnits -> ScriptWitness WitCtxStake era)
-> Gen ScriptData
-> Gen (ExecutionUnits -> ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ScriptData
genScriptData
            Gen (ExecutionUnits -> ScriptWitness WitCtxStake era)
-> Gen ExecutionUnits -> Gen (ScriptWitness WitCtxStake era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ExecutionUnits
genExecutionUnits

genScriptWitnessSpend
    :: ScriptLanguageInEra lang era
    -> Gen (ScriptWitness WitCtxTxIn era)
genScriptWitnessSpend :: ScriptLanguageInEra lang era -> Gen (ScriptWitness WitCtxTxIn era)
genScriptWitnessSpend ScriptLanguageInEra lang era
langEra =
    case ScriptLanguageInEra lang era -> ScriptLanguage lang
forall lang era.
ScriptLanguageInEra lang era -> ScriptLanguage lang
languageOfScriptLanguageInEra ScriptLanguageInEra lang era
langEra of
        (SimpleScriptLanguage SimpleScriptVersion lang
ver) ->
            ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness WitCtxTxIn era
forall lang era witctx.
ScriptLanguageInEra lang era
-> SimpleScriptVersion lang
-> SimpleScriptOrReferenceInput lang
-> ScriptWitness witctx era
SimpleScriptWitness ScriptLanguageInEra lang era
langEra SimpleScriptVersion lang
ver (SimpleScriptOrReferenceInput lang -> ScriptWitness WitCtxTxIn era)
-> Gen (SimpleScriptOrReferenceInput lang)
-> Gen (ScriptWitness WitCtxTxIn era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleScriptVersion lang -> Gen (SimpleScriptOrReferenceInput lang)
forall lang.
SimpleScriptVersion lang -> Gen (SimpleScriptOrReferenceInput lang)
genSimpleScriptOrReferenceInput SimpleScriptVersion lang
ver
        (PlutusScriptLanguage PlutusScriptVersion lang
ver) ->
            ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum WitCtxTxIn
-> ScriptData
-> ExecutionUnits
-> ScriptWitness WitCtxTxIn era
forall lang era witctx.
ScriptLanguageInEra lang era
-> PlutusScriptVersion lang
-> PlutusScriptOrReferenceInput lang
-> ScriptDatum witctx
-> ScriptData
-> ExecutionUnits
-> ScriptWitness witctx era
PlutusScriptWitness ScriptLanguageInEra lang era
langEra PlutusScriptVersion lang
ver
            (PlutusScriptOrReferenceInput lang
 -> ScriptDatum WitCtxTxIn
 -> ScriptData
 -> ExecutionUnits
 -> ScriptWitness WitCtxTxIn era)
-> Gen (PlutusScriptOrReferenceInput lang)
-> Gen
     (ScriptDatum WitCtxTxIn
      -> ScriptData -> ExecutionUnits -> ScriptWitness WitCtxTxIn era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PlutusScriptVersion lang -> Gen (PlutusScriptOrReferenceInput lang)
forall lang.
PlutusScriptVersion lang -> Gen (PlutusScriptOrReferenceInput lang)
genPlutusScriptOrReferenceInput PlutusScriptVersion lang
ver
            Gen
  (ScriptDatum WitCtxTxIn
   -> ScriptData -> ExecutionUnits -> ScriptWitness WitCtxTxIn era)
-> Gen (ScriptDatum WitCtxTxIn)
-> Gen
     (ScriptData -> ExecutionUnits -> ScriptWitness WitCtxTxIn era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ScriptData -> ScriptDatum WitCtxTxIn
ScriptDatumForTxIn (ScriptData -> ScriptDatum WitCtxTxIn)
-> Gen ScriptData -> Gen (ScriptDatum WitCtxTxIn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ScriptData
genScriptData)
            Gen (ScriptData -> ExecutionUnits -> ScriptWitness WitCtxTxIn era)
-> Gen ScriptData
-> Gen (ExecutionUnits -> ScriptWitness WitCtxTxIn era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ScriptData
genScriptData
            Gen (ExecutionUnits -> ScriptWitness WitCtxTxIn era)
-> Gen ExecutionUnits -> Gen (ScriptWitness WitCtxTxIn era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ExecutionUnits
genExecutionUnits

genTxAuxScripts :: CardanoEra era -> Gen (TxAuxScripts era)
genTxAuxScripts :: CardanoEra era -> Gen (TxAuxScripts era)
genTxAuxScripts CardanoEra era
era =
  case CardanoEra era -> Maybe (AuxScriptsSupportedInEra era)
forall era. CardanoEra era -> Maybe (AuxScriptsSupportedInEra era)
auxScriptsSupportedInEra CardanoEra era
era of
    Maybe (AuxScriptsSupportedInEra era)
Nothing -> TxAuxScripts era -> Gen (TxAuxScripts era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
    Just AuxScriptsSupportedInEra era
supported ->
        [(Int, Gen (TxAuxScripts era))] -> Gen (TxAuxScripts era)
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
1, TxAuxScripts era -> Gen (TxAuxScripts era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone)
        , (Int
3, AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
forall era.
AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
TxAuxScripts AuxScriptsSupportedInEra era
supported
              ([ScriptInEra era] -> TxAuxScripts era)
-> Gen [ScriptInEra era] -> Gen (TxAuxScripts era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [ScriptInEra era] -> Gen [ScriptInEra era]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen (ScriptInEra era) -> Gen [ScriptInEra era]
forall a. Gen a -> Gen [a]
listOf (CardanoEra era -> Gen (ScriptInEra era)
forall era. CardanoEra era -> Gen (ScriptInEra era)
genScriptInEra CardanoEra era
era)))
        ]

genTxMetadataInEra :: CardanoEra era -> Gen (TxMetadataInEra era)
genTxMetadataInEra :: CardanoEra era -> Gen (TxMetadataInEra era)
genTxMetadataInEra CardanoEra era
era =
  case CardanoEra era -> Maybe (TxMetadataSupportedInEra era)
forall era. CardanoEra era -> Maybe (TxMetadataSupportedInEra era)
txMetadataSupportedInEra CardanoEra era
era of
    Maybe (TxMetadataSupportedInEra era)
Nothing -> TxMetadataInEra era -> Gen (TxMetadataInEra era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
    Just TxMetadataSupportedInEra era
supported ->
        [Gen (TxMetadataInEra era)] -> Gen (TxMetadataInEra era)
forall a. [Gen a] -> Gen a
oneof
            [ TxMetadataInEra era -> Gen (TxMetadataInEra era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
            , TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
forall era.
TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra TxMetadataSupportedInEra era
supported (TxMetadata -> TxMetadataInEra era)
-> Gen TxMetadata -> Gen (TxMetadataInEra era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxMetadata
genTxMetadata
            ]

genTxMetadata :: Gen TxMetadata
genTxMetadata :: Gen TxMetadata
genTxMetadata =
    ([(Word64, TxMetadataValue)] -> TxMetadata)
-> Gen [(Word64, TxMetadataValue)] -> Gen TxMetadata
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map Word64 TxMetadataValue -> TxMetadata
TxMetadata (Map Word64 TxMetadataValue -> TxMetadata)
-> ([(Word64, TxMetadataValue)] -> Map Word64 TxMetadataValue)
-> [(Word64, TxMetadataValue)]
-> TxMetadata
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Word64, TxMetadataValue)] -> Map Word64 TxMetadataValue
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList) (Gen [(Word64, TxMetadataValue)] -> Gen TxMetadata)
-> Gen [(Word64, TxMetadataValue)] -> Gen TxMetadata
forall a b. (a -> b) -> a -> b
$ do
        Gen (Word64, TxMetadataValue) -> Gen [(Word64, TxMetadataValue)]
forall a. Gen a -> Gen [a]
listOf
            ((,) (Word64 -> TxMetadataValue -> (Word64, TxMetadataValue))
-> Gen Word64 -> Gen (TxMetadataValue -> (Word64, TxMetadataValue))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Large Word64 -> Word64
forall a. Large a -> a
getLarge (Large Word64 -> Word64) -> Gen (Large Word64) -> Gen Word64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Large Word64)
forall a. Arbitrary a => Gen a
arbitrary)
                 Gen (TxMetadataValue -> (Word64, TxMetadataValue))
-> Gen TxMetadataValue -> Gen (Word64, TxMetadataValue)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen TxMetadataValue
genTxMetadataValue)

genTxMetadataValue :: Gen TxMetadataValue
genTxMetadataValue :: Gen TxMetadataValue
genTxMetadataValue =
    (Int -> Gen TxMetadataValue) -> Gen TxMetadataValue
forall a. (Int -> Gen a) -> Gen a
sized ((Int -> Gen TxMetadataValue) -> Gen TxMetadataValue)
-> (Int -> Gen TxMetadataValue) -> Gen TxMetadataValue
forall a b. (a -> b) -> a -> b
$ \Int
sz ->
        [(Int, Gen TxMetadataValue)] -> Gen TxMetadataValue
forall a. [(Int, Gen a)] -> Gen a
frequency
            [ (Int
2, Integer -> TxMetadataValue
TxMetaNumber (Integer -> TxMetadataValue) -> Gen Integer -> Gen TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Integer
genTxMetaNumber)
            , (Int
2, ByteString -> TxMetadataValue
TxMetaBytes  (ByteString -> TxMetadataValue)
-> Gen ByteString -> Gen TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ByteString
genTxMetaBytes)
            , (Int
2, Text -> TxMetadataValue
TxMetaText   (Text -> TxMetadataValue) -> Gen Text -> Gen TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
genTxMetaText)
            , (Int
sz Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4,
                  [TxMetadataValue] -> TxMetadataValue
TxMetaList ([TxMetadataValue] -> TxMetadataValue)
-> Gen [TxMetadataValue] -> Gen TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [TxMetadataValue] -> Gen [TxMetadataValue]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4) Gen [TxMetadataValue]
genTxMetaList)
            , (Int
sz Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4,
                  [(TxMetadataValue, TxMetadataValue)] -> TxMetadataValue
TxMetaMap ([(TxMetadataValue, TxMetadataValue)] -> TxMetadataValue)
-> Gen [(TxMetadataValue, TxMetadataValue)] -> Gen TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int)
-> Gen [(TxMetadataValue, TxMetadataValue)]
-> Gen [(TxMetadataValue, TxMetadataValue)]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4) Gen [(TxMetadataValue, TxMetadataValue)]
genTxMetaMap)
            ]
    where
        genTxMetaNumber :: Gen Integer
        genTxMetaNumber :: Gen Integer
genTxMetaNumber = do
            (Large (Int64
n :: Int64)) <- Gen (Large Int64)
forall a. Arbitrary a => Gen a
arbitrary
            Integer -> Gen Integer
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
n)

        genTxMetaBytes :: Gen ByteString
        genTxMetaBytes :: Gen ByteString
genTxMetaBytes = do
            Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
64)
            [Word8] -> ByteString
BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Word8]
forall a. Arbitrary a => Int -> Gen [a]
vector Int
n

        genTxMetaText :: Gen Text
        genTxMetaText :: Gen Text
genTxMetaText = do
            Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
64)
            [Char] -> Text
T.pack ([Char] -> Text) -> Gen [Char] -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen Char -> Gen [Char]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
n Gen Char
genAlphaNum

        genTxMetaList :: Gen [TxMetadataValue]
        genTxMetaList :: Gen [TxMetadataValue]
genTxMetaList = do
            Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
10)
            Int -> Gen TxMetadataValue -> Gen [TxMetadataValue]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
n Gen TxMetadataValue
genTxMetadataValue

        genTxMetaMap :: Gen [(TxMetadataValue, TxMetadataValue)]
        genTxMetaMap :: Gen [(TxMetadataValue, TxMetadataValue)]
genTxMetaMap = do
            Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
10)
            Int
-> Gen (TxMetadataValue, TxMetadataValue)
-> Gen [(TxMetadataValue, TxMetadataValue)]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
n
                ((,) (TxMetadataValue
 -> TxMetadataValue -> (TxMetadataValue, TxMetadataValue))
-> Gen TxMetadataValue
-> Gen (TxMetadataValue -> (TxMetadataValue, TxMetadataValue))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxMetadataValue
genTxMetadataValue Gen (TxMetadataValue -> (TxMetadataValue, TxMetadataValue))
-> Gen TxMetadataValue -> Gen (TxMetadataValue, TxMetadataValue)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen TxMetadataValue
genTxMetadataValue)

genPtr :: Gen Ptr
genPtr :: Gen Ptr
genPtr = SlotNo32 -> TxIx -> CertIx -> Ptr
safePtr (SlotNo32 -> TxIx -> CertIx -> Ptr)
-> Gen SlotNo32 -> Gen (TxIx -> CertIx -> Ptr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SlotNo32
genSlotNo32 Gen (TxIx -> CertIx -> Ptr) -> Gen TxIx -> Gen (CertIx -> Ptr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen TxIx
genTxIx Gen (CertIx -> Ptr) -> Gen CertIx -> Gen Ptr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen CertIx
genCertIx

genTxIx :: Gen Ledger.TxIx
genTxIx :: Gen TxIx
genTxIx = Word64 -> TxIx
Ledger.TxIx (Word64 -> TxIx) -> Gen Word64 -> Gen TxIx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary

genCertIx :: Gen Ledger.CertIx
genCertIx :: Gen CertIx
genCertIx = Word64 -> CertIx
Ledger.CertIx (Word64 -> CertIx) -> Gen Word64 -> Gen CertIx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary

genStakeAddressReference :: Gen StakeAddressReference
genStakeAddressReference :: Gen StakeAddressReference
genStakeAddressReference =
  [Gen StakeAddressReference] -> Gen StakeAddressReference
forall a. [Gen a] -> Gen a
oneof
    [ StakeCredential -> StakeAddressReference
StakeAddressByValue (StakeCredential -> StakeAddressReference)
-> Gen StakeCredential -> Gen StakeAddressReference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen StakeCredential
genStakeCredential
    , (StakeAddressPointer -> StakeAddressReference
StakeAddressByPointer (StakeAddressPointer -> StakeAddressReference)
-> (Ptr -> StakeAddressPointer) -> Ptr -> StakeAddressReference
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr -> StakeAddressPointer
StakeAddressPointer) (Ptr -> StakeAddressReference)
-> Gen Ptr -> Gen StakeAddressReference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Ptr
genPtr
    , StakeAddressReference -> Gen StakeAddressReference
forall (m :: * -> *) a. Monad m => a -> m a
return StakeAddressReference
NoStakeAddress
    ]

genPaymentCredential :: Gen PaymentCredential
genPaymentCredential :: Gen PaymentCredential
genPaymentCredential =
    [Gen PaymentCredential] -> Gen PaymentCredential
forall a. [Gen a] -> Gen a
oneof
        [ Gen PaymentCredential
byKey
        , Gen PaymentCredential
byScript
        ]
    where
        byKey :: Gen PaymentCredential
        byKey :: Gen PaymentCredential
byKey = do
            VerificationKey PaymentKey
vKey <- AsType PaymentKey -> Gen (VerificationKey PaymentKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey AsType PaymentKey
AsPaymentKey
            PaymentCredential -> Gen PaymentCredential
forall (m :: * -> *) a. Monad m => a -> m a
return (PaymentCredential -> Gen PaymentCredential)
-> (Hash PaymentKey -> PaymentCredential)
-> Hash PaymentKey
-> Gen PaymentCredential
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash PaymentKey -> PaymentCredential
PaymentCredentialByKey (Hash PaymentKey -> Gen PaymentCredential)
-> Hash PaymentKey -> Gen PaymentCredential
forall a b. (a -> b) -> a -> b
$ VerificationKey PaymentKey -> Hash PaymentKey
forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash VerificationKey PaymentKey
vKey

        byScript :: Gen PaymentCredential
        byScript :: Gen PaymentCredential
byScript = ScriptHash -> PaymentCredential
PaymentCredentialByScript (ScriptHash -> PaymentCredential)
-> Gen ScriptHash -> Gen PaymentCredential
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ScriptHash
genScriptHash

genAddressAny :: Gen AddressAny
genAddressAny :: Gen AddressAny
genAddressAny = [Gen AddressAny] -> Gen AddressAny
forall a. [Gen a] -> Gen a
oneof
    [ Address ByronAddr -> AddressAny
AddressByron
        (Address ByronAddr -> AddressAny)
-> Gen (Address ByronAddr) -> Gen AddressAny
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Address ByronAddr)
genAddressByron
    , Address ShelleyAddr -> AddressAny
AddressShelley
        (Address ShelleyAddr -> AddressAny)
-> Gen (Address ShelleyAddr) -> Gen AddressAny
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Address ShelleyAddr)
genAddressShelley
    ]

genAddressByron :: Gen (Address ByronAddr)
genAddressByron :: Gen (Address ByronAddr)
genAddressByron = NetworkId -> VerificationKey ByronKey -> Address ByronAddr
makeByronAddress (NetworkId -> VerificationKey ByronKey -> Address ByronAddr)
-> Gen NetworkId
-> Gen (VerificationKey ByronKey -> Address ByronAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen NetworkId
genNetworkId
                                   Gen (VerificationKey ByronKey -> Address ByronAddr)
-> Gen (VerificationKey ByronKey) -> Gen (Address ByronAddr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType ByronKey -> Gen (VerificationKey ByronKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey AsType ByronKey
AsByronKey

genAddressShelley :: Gen (Address ShelleyAddr)
genAddressShelley :: Gen (Address ShelleyAddr)
genAddressShelley = NetworkId
-> PaymentCredential
-> StakeAddressReference
-> Address ShelleyAddr
makeShelleyAddress (NetworkId
 -> PaymentCredential
 -> StakeAddressReference
 -> Address ShelleyAddr)
-> Gen NetworkId
-> Gen
     (PaymentCredential -> StakeAddressReference -> Address ShelleyAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen NetworkId
genNetworkId
                                       Gen
  (PaymentCredential -> StakeAddressReference -> Address ShelleyAddr)
-> Gen PaymentCredential
-> Gen (StakeAddressReference -> Address ShelleyAddr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen PaymentCredential
genPaymentCredential
                                       Gen (StakeAddressReference -> Address ShelleyAddr)
-> Gen StakeAddressReference -> Gen (Address ShelleyAddr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen StakeAddressReference
genStakeAddressReference

genAddressInEra :: CardanoEra era -> Gen (AddressInEra era)
genAddressInEra :: CardanoEra era -> Gen (AddressInEra era)
genAddressInEra CardanoEra era
era =
  case CardanoEra era -> CardanoEraStyle era
forall era. CardanoEra era -> CardanoEraStyle era
cardanoEraStyle CardanoEra era
era of
    CardanoEraStyle era
LegacyByronEra ->
      Address ByronAddr -> AddressInEra era
forall era. Address ByronAddr -> AddressInEra era
byronAddressInEra (Address ByronAddr -> AddressInEra era)
-> Gen (Address ByronAddr) -> Gen (AddressInEra era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Address ByronAddr)
genAddressByron

    ShelleyBasedEra ShelleyBasedEra era
_ ->
      [Gen (AddressInEra era)] -> Gen (AddressInEra era)
forall a. [Gen a] -> Gen a
oneof
        [ Address ByronAddr -> AddressInEra era
forall era. Address ByronAddr -> AddressInEra era
byronAddressInEra   (Address ByronAddr -> AddressInEra era)
-> Gen (Address ByronAddr) -> Gen (AddressInEra era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Address ByronAddr)
genAddressByron
        , Address ShelleyAddr -> AddressInEra era
forall era.
IsShelleyBasedEra era =>
Address ShelleyAddr -> AddressInEra era
shelleyAddressInEra (Address ShelleyAddr -> AddressInEra era)
-> Gen (Address ShelleyAddr) -> Gen (AddressInEra era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Address ShelleyAddr)
genAddressShelley
        ]

genUnsignedQuantity :: Gen Quantity
genUnsignedQuantity :: Gen Quantity
genUnsignedQuantity = do
    Int
n <- Arbitrary Int => Gen Int
forall a. Arbitrary a => Gen a
arbitrary @Int
    [(Int, Gen Quantity)] -> Gen Quantity
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
30, Quantity -> Gen Quantity
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Quantity -> Gen Quantity) -> Quantity -> Gen Quantity
forall a b. (a -> b) -> a -> b
$ Quantity -> Quantity
forall a. Num a => a -> a
abs (Quantity -> Quantity) -> Quantity -> Quantity
forall a b. (a -> b) -> a -> b
$ Int -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
        , (Int
30, forall b. (Integral Integer, Num b) => Integer -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Integer (Integer -> Quantity) -> Gen Integer -> Gen Quantity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (Integer
0, Integer
1_000_000_000_000))
        , (Int
30, Word64 -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Quantity) -> Gen Word64 -> Gen Quantity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Arbitrary Word64 => Gen Word64
forall a. Arbitrary a => Gen a
arbitrary @Word64)
        ]

genTxOutValue :: CardanoEra era -> Gen (TxOutValue era)
genTxOutValue :: CardanoEra era -> Gen (TxOutValue era)
genTxOutValue CardanoEra era
era =
  case CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra era
era of
    Left OnlyAdaSupportedInEra era
adaOnlyInEra     -> OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra era
adaOnlyInEra (Lovelace -> TxOutValue era)
-> Gen Lovelace -> Gen (TxOutValue era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace
    Right MultiAssetSupportedInEra era
multiAssetInEra -> MultiAssetSupportedInEra era -> Value -> TxOutValue era
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra era
multiAssetInEra (Value -> TxOutValue era) -> Gen Value -> Gen (TxOutValue era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genValueForTxOut

genTxOut :: CardanoEra era -> Gen (TxOut ctx era)
genTxOut :: CardanoEra era -> Gen (TxOut ctx era)
genTxOut CardanoEra era
era =
  AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra era
 -> TxOutValue era
 -> TxOutDatum ctx era
 -> ReferenceScript era
 -> TxOut ctx era)
-> Gen (AddressInEra era)
-> Gen
     (TxOutValue era
      -> TxOutDatum ctx era -> ReferenceScript era -> TxOut ctx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era -> Gen (AddressInEra era)
forall era. CardanoEra era -> Gen (AddressInEra era)
genAddressInEra CardanoEra era
era
        Gen
  (TxOutValue era
   -> TxOutDatum ctx era -> ReferenceScript era -> TxOut ctx era)
-> Gen (TxOutValue era)
-> Gen (TxOutDatum ctx era -> ReferenceScript era -> TxOut ctx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra era -> Gen (TxOutValue era)
forall era. CardanoEra era -> Gen (TxOutValue era)
genTxOutValue CardanoEra era
era
        Gen (TxOutDatum ctx era -> ReferenceScript era -> TxOut ctx era)
-> Gen (TxOutDatum ctx era)
-> Gen (ReferenceScript era -> TxOut ctx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra era -> Gen (TxOutDatum ctx era)
forall era ctx. CardanoEra era -> Gen (TxOutDatum ctx era)
genTxOutDatum CardanoEra era
era
        Gen (ReferenceScript era -> TxOut ctx era)
-> Gen (ReferenceScript era) -> Gen (TxOut ctx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra era -> Gen (ReferenceScript era)
forall era. CardanoEra era -> Gen (ReferenceScript era)
genReferenceScript CardanoEra era
era

genTxOutDatum :: CardanoEra era -> Gen (TxOutDatum ctx era)
genTxOutDatum :: CardanoEra era -> Gen (TxOutDatum ctx era)
genTxOutDatum CardanoEra era
era = case CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
forall era. CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra CardanoEra era
era of
    Maybe (ScriptDataSupportedInEra era)
Nothing -> TxOutDatum ctx era -> Gen (TxOutDatum ctx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
    Just ScriptDataSupportedInEra era
supported -> [Gen (TxOutDatum ctx era)] -> Gen (TxOutDatum ctx era)
forall a. [Gen a] -> Gen a
oneof
        [ TxOutDatum ctx era -> Gen (TxOutDatum ctx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
        , ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
supported (Hash ScriptData -> TxOutDatum ctx era)
-> Gen (Hash ScriptData) -> Gen (TxOutDatum ctx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Hash ScriptData)
genHashScriptData
        ]

genReferenceScript :: CardanoEra era -> Gen (ReferenceScript era)
genReferenceScript :: CardanoEra era -> Gen (ReferenceScript era)
genReferenceScript CardanoEra era
era = case CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
refInsScriptsAndInlineDatsSupportedInEra CardanoEra era
era of
    Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
Nothing -> ReferenceScript era -> Gen (ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
    Just ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supported -> [Gen (ReferenceScript era)] -> Gen (ReferenceScript era)
forall a. [Gen a] -> Gen a
oneof
        [ ReferenceScript era -> Gen (ReferenceScript era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
        , ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptInAnyLang -> ReferenceScript era
forall era.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptInAnyLang -> ReferenceScript era
ReferenceScript ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supported (ScriptInAnyLang -> ReferenceScript era)
-> Gen ScriptInAnyLang -> Gen (ReferenceScript era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ScriptInAnyLang
genScriptInAnyLang
        ]

mkDummyHash :: forall h a. Crypto.HashAlgorithm h => Int -> Crypto.Hash h a
mkDummyHash :: Int -> Hash h a
mkDummyHash = Hash h Int -> Hash h a
coerce (Hash h Int -> Hash h a) -> (Int -> Hash h Int) -> Int -> Hash h a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Encoding) -> Int -> Hash h Int
forall h a. HashAlgorithm h => (a -> Encoding) -> a -> Hash h a
Crypto.hashWithSerialiser @h Int -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR

genHashScriptData :: Gen (Cardano.Api.Hash ScriptData)
genHashScriptData :: Gen (Hash ScriptData)
genHashScriptData =
    DataHash StandardCrypto -> Hash ScriptData
ScriptDataHash (DataHash StandardCrypto -> Hash ScriptData)
-> (Int -> DataHash StandardCrypto) -> Int -> Hash ScriptData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash Blake2b_256 EraIndependentData -> DataHash StandardCrypto
forall crypto index.
Hash (HASH crypto) index -> SafeHash crypto index
unsafeMakeSafeHash (Hash Blake2b_256 EraIndependentData -> DataHash StandardCrypto)
-> (Int -> Hash Blake2b_256 EraIndependentData)
-> Int
-> DataHash StandardCrypto
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Hash Blake2b_256 EraIndependentData
forall h a. HashAlgorithm h => Int -> Hash h a
mkDummyHash
        (Int -> Hash ScriptData) -> Gen Int -> Gen (Hash ScriptData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Int -> Int) -> Gen Int -> Gen Int
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
10) Gen Int
forall a. Arbitrary a => Gen a
arbitrary)

genNat :: Gen Natural
genNat :: Gen Natural
genNat = do
    Large (Word64
n :: Word64) <- Gen (Large Word64)
forall a. Arbitrary a => Gen a
arbitrary
    Natural -> Gen Natural
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Natural -> Gen Natural) -> Natural -> Gen Natural
forall a b. (a -> b) -> a -> b
$ Word64 -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n

genRational :: Gen Rational
genRational :: Gen Rational
genRational =
    (\Word64
d -> Ratio Word64 -> Rational
ratioToRational (Word64
1 Word64 -> Word64 -> Ratio Word64
forall a. Integral a => a -> a -> Ratio a
% Word64
d)) (Word64 -> Rational) -> Gen Word64 -> Gen Rational
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
genDenominator
  where
    genDenominator :: Gen Word64
    genDenominator :: Gen Word64
genDenominator = do
        (Positive (Large Word64
n)) <- Gen (Positive (Large Word64))
forall a. Arbitrary a => Gen a
arbitrary
        Word64 -> Gen Word64
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64
n

    ratioToRational :: Ratio Word64 -> Rational
    ratioToRational :: Ratio Word64 -> Rational
ratioToRational = Ratio Word64 -> Rational
forall a. Real a => a -> Rational
toRational

-- TODO: consolidate this back to just genRational once this is merged:
-- https://github.com/input-output-hk/cardano-ledger/pull/2330
genRationalInt64 :: Gen Rational
genRationalInt64 :: Gen Rational
genRationalInt64 =
    (\Int64
d -> Ratio Int64 -> Rational
ratioToRational (Int64
1 Int64 -> Int64 -> Ratio Int64
forall a. Integral a => a -> a -> Ratio a
% Int64
d)) (Int64 -> Rational) -> Gen Int64 -> Gen Rational
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int64
genDenominator
  where
    genDenominator :: Gen Int64
    genDenominator :: Gen Int64
genDenominator = do
        (Positive (Large Int64
n)) <- Gen (Positive (Large Int64))
forall a. Arbitrary a => Gen a
arbitrary
        Int64 -> Gen Int64
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int64
n

    ratioToRational :: Ratio Int64 -> Rational
    ratioToRational :: Ratio Int64 -> Rational
ratioToRational = Ratio Int64 -> Rational
forall a. Real a => a -> Rational
toRational

genPraosNonce :: Gen PraosNonce
genPraosNonce :: Gen PraosNonce
genPraosNonce = ByteString -> PraosNonce
makePraosNonce (ByteString -> PraosNonce) -> Gen ByteString -> Gen PraosNonce
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ByteString
forall a. Arbitrary a => Gen a
arbitrary

genEpochNo :: Gen EpochNo
genEpochNo :: Gen EpochNo
genEpochNo = Word64 -> EpochNo
EpochNo (Word64 -> EpochNo) -> Gen Word64 -> Gen EpochNo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary

genCostModel :: Gen CostModel
genCostModel :: Gen CostModel
genCostModel = case Maybe CostModelParams
Plutus.defaultCostModelParams of
  Maybe CostModelParams
Nothing -> [Char] -> Gen CostModel
forall a. HasCallStack => [Char] -> a
error [Char]
"Plutus defaultCostModelParams is broken."
  Just CostModelParams
dcm ->
      CostModelParams -> CostModel
CostModel
    -- TODO This needs to be the cost model struct for whichever
    -- Plutus version we're using, once we support multiple Plutus versions.
    (CostModelParams -> CostModel)
-> Gen CostModelParams -> Gen CostModel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Integer -> Gen Integer) -> CostModelParams -> Gen CostModelParams
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Gen Integer -> Integer -> Gen Integer
forall a b. a -> b -> a
const (Gen Integer -> Integer -> Gen Integer)
-> Gen Integer -> Integer -> Gen Integer
forall a b. (a -> b) -> a -> b
$ (Integer, Integer) -> Gen Integer
chooseInteger (Integer
0, Integer
5000)) CostModelParams
dcm

genCostModels :: Gen (Map AnyPlutusScriptVersion CostModel)
genCostModels :: Gen (Map AnyPlutusScriptVersion CostModel)
genCostModels = do
    Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
0, [AnyPlutusScriptVersion] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [AnyPlutusScriptVersion]
plutusScriptVersions)
    [(AnyPlutusScriptVersion, CostModel)]
-> Map AnyPlutusScriptVersion CostModel
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
        ([(AnyPlutusScriptVersion, CostModel)]
 -> Map AnyPlutusScriptVersion CostModel)
-> Gen [(AnyPlutusScriptVersion, CostModel)]
-> Gen (Map AnyPlutusScriptVersion CostModel)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int
-> Gen (AnyPlutusScriptVersion, CostModel)
-> Gen [(AnyPlutusScriptVersion, CostModel)]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
n ((,) (AnyPlutusScriptVersion
 -> CostModel -> (AnyPlutusScriptVersion, CostModel))
-> Gen AnyPlutusScriptVersion
-> Gen (CostModel -> (AnyPlutusScriptVersion, CostModel))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [AnyPlutusScriptVersion] -> Gen AnyPlutusScriptVersion
forall a. [a] -> Gen a
elements [AnyPlutusScriptVersion]
plutusScriptVersions Gen (CostModel -> (AnyPlutusScriptVersion, CostModel))
-> Gen CostModel -> Gen (AnyPlutusScriptVersion, CostModel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen CostModel
genCostModel)
  where
    plutusScriptVersions :: [AnyPlutusScriptVersion]
    plutusScriptVersions :: [AnyPlutusScriptVersion]
plutusScriptVersions = [AnyPlutusScriptVersion
forall a. Bounded a => a
minBound..AnyPlutusScriptVersion
forall a. Bounded a => a
maxBound]

genExecutionUnitPrices :: Gen ExecutionUnitPrices
genExecutionUnitPrices :: Gen ExecutionUnitPrices
genExecutionUnitPrices = Rational -> Rational -> ExecutionUnitPrices
ExecutionUnitPrices (Rational -> Rational -> ExecutionUnitPrices)
-> Gen Rational -> Gen (Rational -> ExecutionUnitPrices)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Rational
genRational Gen (Rational -> ExecutionUnitPrices)
-> Gen Rational -> Gen ExecutionUnitPrices
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRational

genProtocolParameters :: Gen ProtocolParameters
genProtocolParameters :: Gen ProtocolParameters
genProtocolParameters =
  (Natural, Natural)
-> Maybe Rational
-> Maybe PraosNonce
-> Natural
-> Natural
-> Natural
-> Natural
-> Natural
-> Maybe Lovelace
-> Lovelace
-> Lovelace
-> Lovelace
-> EpochNo
-> Natural
-> Rational
-> Rational
-> Rational
-> Maybe Lovelace
-> Map AnyPlutusScriptVersion CostModel
-> Maybe ExecutionUnitPrices
-> Maybe ExecutionUnits
-> Maybe ExecutionUnits
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Lovelace
-> ProtocolParameters
ProtocolParameters
    ((Natural, Natural)
 -> Maybe Rational
 -> Maybe PraosNonce
 -> Natural
 -> Natural
 -> Natural
 -> Natural
 -> Natural
 -> Maybe Lovelace
 -> Lovelace
 -> Lovelace
 -> Lovelace
 -> EpochNo
 -> Natural
 -> Rational
 -> Rational
 -> Rational
 -> Maybe Lovelace
 -> Map AnyPlutusScriptVersion CostModel
 -> Maybe ExecutionUnitPrices
 -> Maybe ExecutionUnits
 -> Maybe ExecutionUnits
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Lovelace
 -> ProtocolParameters)
-> Gen (Natural, Natural)
-> Gen
     (Maybe Rational
      -> Maybe PraosNonce
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (Natural -> Natural -> (Natural, Natural))
-> Gen Natural -> Gen (Natural -> (Natural, Natural))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Natural
genNat Gen (Natural -> (Natural, Natural))
-> Gen Natural -> Gen (Natural, Natural)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat)
    Gen
  (Maybe Rational
   -> Maybe PraosNonce
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Rational)
-> Gen
     (Maybe PraosNonce
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> Maybe Rational
forall a. a -> Maybe a
Just (Rational -> Maybe Rational)
-> Gen Rational -> Gen (Maybe Rational)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Rational
genRational)
    Gen
  (Maybe PraosNonce
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe PraosNonce)
-> Gen
     (Natural
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen PraosNonce -> Gen (Maybe PraosNonce)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen PraosNonce
genPraosNonce
    Gen
  (Natural
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Lovelace)
-> Gen
     (Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Gen
  (Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Lovelace
-> Gen
     (Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  (Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Lovelace
-> Gen
     (Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  (Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Lovelace
-> Gen
     (EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  (EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen EpochNo
-> Gen
     (Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen EpochNo
genEpochNo
    Gen
  (Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Rational
-> Gen
     (Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRationalInt64
    Gen
  (Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Rational
-> Gen
     (Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRational
    Gen
  (Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Rational
-> Gen
     (Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRational
    Gen
  (Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Lovelace)
-> Gen
     (Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Gen
  (Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Map AnyPlutusScriptVersion CostModel)
-> Gen
     (Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Map AnyPlutusScriptVersion CostModel)
genCostModels
    Gen
  (Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe ExecutionUnitPrices)
-> Gen
     (Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ExecutionUnitPrices -> Gen (Maybe ExecutionUnitPrices)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ExecutionUnitPrices
genExecutionUnitPrices
    Gen
  (Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe ExecutionUnits)
-> Gen
     (Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ExecutionUnits -> Gen (Maybe ExecutionUnits)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ExecutionUnits
genExecutionUnits
    Gen
  (Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe ExecutionUnits)
-> Gen
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ExecutionUnits -> Gen (Maybe ExecutionUnits)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ExecutionUnits
genExecutionUnits
    Gen
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Natural)
-> Gen
     (Maybe Natural
      -> Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Gen
  (Maybe Natural
   -> Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
-> Gen (Maybe Natural)
-> Gen (Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Gen (Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
-> Gen (Maybe Natural)
-> Gen (Maybe Lovelace -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Gen (Maybe Lovelace -> ProtocolParameters)
-> Gen (Maybe Lovelace) -> Gen ProtocolParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace

genProtocolParametersWithAlonzoScripts :: Gen ProtocolParameters
genProtocolParametersWithAlonzoScripts :: Gen ProtocolParameters
genProtocolParametersWithAlonzoScripts =
  (Natural, Natural)
-> Maybe Rational
-> Maybe PraosNonce
-> Natural
-> Natural
-> Natural
-> Natural
-> Natural
-> Maybe Lovelace
-> Lovelace
-> Lovelace
-> Lovelace
-> EpochNo
-> Natural
-> Rational
-> Rational
-> Rational
-> Maybe Lovelace
-> Map AnyPlutusScriptVersion CostModel
-> Maybe ExecutionUnitPrices
-> Maybe ExecutionUnits
-> Maybe ExecutionUnits
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Lovelace
-> ProtocolParameters
ProtocolParameters
    ((Natural, Natural)
 -> Maybe Rational
 -> Maybe PraosNonce
 -> Natural
 -> Natural
 -> Natural
 -> Natural
 -> Natural
 -> Maybe Lovelace
 -> Lovelace
 -> Lovelace
 -> Lovelace
 -> EpochNo
 -> Natural
 -> Rational
 -> Rational
 -> Rational
 -> Maybe Lovelace
 -> Map AnyPlutusScriptVersion CostModel
 -> Maybe ExecutionUnitPrices
 -> Maybe ExecutionUnits
 -> Maybe ExecutionUnits
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Lovelace
 -> ProtocolParameters)
-> Gen (Natural, Natural)
-> Gen
     (Maybe Rational
      -> Maybe PraosNonce
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (Natural -> Natural -> (Natural, Natural))
-> Gen Natural -> Gen (Natural -> (Natural, Natural))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Natural
genNat Gen (Natural -> (Natural, Natural))
-> Gen Natural -> Gen (Natural, Natural)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat)
    Gen
  (Maybe Rational
   -> Maybe PraosNonce
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Rational)
-> Gen
     (Maybe PraosNonce
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> Maybe Rational
forall a. a -> Maybe a
Just (Rational -> Maybe Rational)
-> Gen Rational -> Gen (Maybe Rational)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Rational
genRational)
    Gen
  (Maybe PraosNonce
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe PraosNonce)
-> Gen
     (Natural
      -> Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen PraosNonce -> Gen (Maybe PraosNonce)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen PraosNonce
genPraosNonce
    Gen
  (Natural
   -> Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Natural
      -> Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Natural
   -> Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Maybe Lovelace
      -> Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Maybe Lovelace
   -> Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Lovelace)
-> Gen
     (Lovelace
      -> Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Gen
  (Lovelace
   -> Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Lovelace
-> Gen
     (Lovelace
      -> Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  (Lovelace
   -> Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Lovelace
-> Gen
     (Lovelace
      -> EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  (Lovelace
   -> EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Lovelace
-> Gen
     (EpochNo
      -> Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  (EpochNo
   -> Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen EpochNo
-> Gen
     (Natural
      -> Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen EpochNo
genEpochNo
    Gen
  (Natural
   -> Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Natural
-> Gen
     (Rational
      -> Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat
    Gen
  (Rational
   -> Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Rational
-> Gen
     (Rational
      -> Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRationalInt64
    Gen
  (Rational
   -> Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Rational
-> Gen
     (Rational
      -> Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRational
    Gen
  (Rational
   -> Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen Rational
-> Gen
     (Maybe Lovelace
      -> Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRational
    Gen
  (Maybe Lovelace
   -> Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Lovelace)
-> Gen
     (Map AnyPlutusScriptVersion CostModel
      -> Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Lovelace -> Maybe Lovelace
forall a. a -> Maybe a
Just (Lovelace -> Maybe Lovelace)
-> Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace)
    Gen
  (Map AnyPlutusScriptVersion CostModel
   -> Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Map AnyPlutusScriptVersion CostModel)
-> Gen
     (Maybe ExecutionUnitPrices
      -> Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Map AnyPlutusScriptVersion CostModel)
genCostModels
    Gen
  (Maybe ExecutionUnitPrices
   -> Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe ExecutionUnitPrices)
-> Gen
     (Maybe ExecutionUnits
      -> Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ExecutionUnitPrices -> Maybe ExecutionUnitPrices
forall a. a -> Maybe a
Just (ExecutionUnitPrices -> Maybe ExecutionUnitPrices)
-> Gen ExecutionUnitPrices -> Gen (Maybe ExecutionUnitPrices)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ExecutionUnitPrices
genExecutionUnitPrices)
    Gen
  (Maybe ExecutionUnits
   -> Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe ExecutionUnits)
-> Gen
     (Maybe ExecutionUnits
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ExecutionUnits -> Maybe ExecutionUnits
forall a. a -> Maybe a
Just (ExecutionUnits -> Maybe ExecutionUnits)
-> Gen ExecutionUnits -> Gen (Maybe ExecutionUnits)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ExecutionUnits
genExecutionUnits)
    Gen
  (Maybe ExecutionUnits
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe ExecutionUnits)
-> Gen
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Lovelace
      -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ExecutionUnits -> Maybe ExecutionUnits
forall a. a -> Maybe a
Just (ExecutionUnits -> Maybe ExecutionUnits)
-> Gen ExecutionUnits -> Gen (Maybe ExecutionUnits)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ExecutionUnits
genExecutionUnits)
    Gen
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Lovelace
   -> ProtocolParameters)
-> Gen (Maybe Natural)
-> Gen
     (Maybe Natural
      -> Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Natural -> Maybe Natural
forall a. a -> Maybe a
Just (Natural -> Maybe Natural) -> Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Natural
genNat)
    Gen
  (Maybe Natural
   -> Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
-> Gen (Maybe Natural)
-> Gen (Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Natural -> Maybe Natural
forall a. a -> Maybe a
Just (Natural -> Maybe Natural) -> Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Natural
genNat)
    Gen (Maybe Natural -> Maybe Lovelace -> ProtocolParameters)
-> Gen (Maybe Natural)
-> Gen (Maybe Lovelace -> ProtocolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Natural -> Maybe Natural
forall a. a -> Maybe a
Just (Natural -> Maybe Natural) -> Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Natural
genNat)
    Gen (Maybe Lovelace -> ProtocolParameters)
-> Gen (Maybe Lovelace) -> Gen ProtocolParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Lovelace -> Maybe Lovelace
forall a. a -> Maybe a
Just (Lovelace -> Maybe Lovelace)
-> Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace)

genWitnessNetworkIdOrByronAddress :: Gen WitnessNetworkIdOrByronAddress
genWitnessNetworkIdOrByronAddress :: Gen WitnessNetworkIdOrByronAddress
genWitnessNetworkIdOrByronAddress =
  [Gen WitnessNetworkIdOrByronAddress]
-> Gen WitnessNetworkIdOrByronAddress
forall a. [Gen a] -> Gen a
oneof
    [ NetworkId -> WitnessNetworkIdOrByronAddress
WitnessNetworkId (NetworkId -> WitnessNetworkIdOrByronAddress)
-> Gen NetworkId -> Gen WitnessNetworkIdOrByronAddress
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen NetworkId
genNetworkId
    , Address ByronAddr -> WitnessNetworkIdOrByronAddress
WitnessByronAddress (Address ByronAddr -> WitnessNetworkIdOrByronAddress)
-> Gen (Address ByronAddr) -> Gen WitnessNetworkIdOrByronAddress
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Address ByronAddr)
genAddressByron
    ]

genByronKeyWitness :: Gen (KeyWitness ByronEra)
genByronKeyWitness :: Gen (KeyWitness ByronEra)
genByronKeyWitness = do
  ProtocolMagicId
pmId <- Gen ProtocolMagicId -> Gen ProtocolMagicId
forall a. Gen a -> Gen a
hedgehog Gen ProtocolMagicId
genProtocolMagicId
  TxInWitness
txinWitness <- Gen TxInWitness -> Gen TxInWitness
forall a. Gen a -> Gen a
hedgehog (Gen TxInWitness -> Gen TxInWitness)
-> Gen TxInWitness -> Gen TxInWitness
forall a b. (a -> b) -> a -> b
$ ProtocolMagicId -> Gen TxInWitness
genVKWitness ProtocolMagicId
pmId
  KeyWitness ByronEra -> Gen (KeyWitness ByronEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (KeyWitness ByronEra -> Gen (KeyWitness ByronEra))
-> KeyWitness ByronEra -> Gen (KeyWitness ByronEra)
forall a b. (a -> b) -> a -> b
$ TxInWitness -> KeyWitness ByronEra
ByronKeyWitness TxInWitness
txinWitness

genShelleyWitnessSigningKey :: Gen ShelleyWitnessSigningKey
genShelleyWitnessSigningKey :: Gen ShelleyWitnessSigningKey
genShelleyWitnessSigningKey =
  [Gen ShelleyWitnessSigningKey] -> Gen ShelleyWitnessSigningKey
forall a. [Gen a] -> Gen a
oneof
      [ SigningKey PaymentKey -> ShelleyWitnessSigningKey
WitnessPaymentKey
        (SigningKey PaymentKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey PaymentKey) -> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType PaymentKey -> Gen (SigningKey PaymentKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType PaymentKey
AsPaymentKey
      , SigningKey PaymentExtendedKey -> ShelleyWitnessSigningKey
WitnessPaymentExtendedKey
        (SigningKey PaymentExtendedKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey PaymentExtendedKey)
-> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType PaymentExtendedKey -> Gen (SigningKey PaymentExtendedKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType PaymentExtendedKey
AsPaymentExtendedKey
      , SigningKey StakeKey -> ShelleyWitnessSigningKey
WitnessStakeKey
        (SigningKey StakeKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey StakeKey) -> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType StakeKey -> Gen (SigningKey StakeKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType StakeKey
AsStakeKey
      , SigningKey StakeExtendedKey -> ShelleyWitnessSigningKey
WitnessStakeExtendedKey
        (SigningKey StakeExtendedKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey StakeExtendedKey)
-> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType StakeExtendedKey -> Gen (SigningKey StakeExtendedKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType StakeExtendedKey
AsStakeExtendedKey
      , SigningKey StakePoolKey -> ShelleyWitnessSigningKey
WitnessStakePoolKey
        (SigningKey StakePoolKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey StakePoolKey) -> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType StakePoolKey -> Gen (SigningKey StakePoolKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType StakePoolKey
AsStakePoolKey
      , SigningKey GenesisKey -> ShelleyWitnessSigningKey
WitnessGenesisKey
        (SigningKey GenesisKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey GenesisKey) -> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType GenesisKey -> Gen (SigningKey GenesisKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType GenesisKey
AsGenesisKey
      , SigningKey GenesisExtendedKey -> ShelleyWitnessSigningKey
WitnessGenesisExtendedKey
        (SigningKey GenesisExtendedKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey GenesisExtendedKey)
-> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType GenesisExtendedKey -> Gen (SigningKey GenesisExtendedKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType GenesisExtendedKey
AsGenesisExtendedKey
      , SigningKey GenesisDelegateKey -> ShelleyWitnessSigningKey
WitnessGenesisDelegateKey
        (SigningKey GenesisDelegateKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey GenesisDelegateKey)
-> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType GenesisDelegateKey -> Gen (SigningKey GenesisDelegateKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType GenesisDelegateKey
AsGenesisDelegateKey
      , SigningKey GenesisDelegateExtendedKey -> ShelleyWitnessSigningKey
WitnessGenesisDelegateExtendedKey
        (SigningKey GenesisDelegateExtendedKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey GenesisDelegateExtendedKey)
-> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType GenesisDelegateExtendedKey
-> Gen (SigningKey GenesisDelegateExtendedKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType GenesisDelegateExtendedKey
AsGenesisDelegateExtendedKey
      , SigningKey GenesisUTxOKey -> ShelleyWitnessSigningKey
WitnessGenesisUTxOKey
        (SigningKey GenesisUTxOKey -> ShelleyWitnessSigningKey)
-> Gen (SigningKey GenesisUTxOKey) -> Gen ShelleyWitnessSigningKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType GenesisUTxOKey -> Gen (SigningKey GenesisUTxOKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType GenesisUTxOKey
AsGenesisUTxOKey
      ]

genPoolId :: Gen PoolId
genPoolId :: Gen PoolId
genPoolId = AsType StakePoolKey -> Gen PoolId
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType StakePoolKey
AsStakePoolKey

genMIRPot :: Gen MIRPot
genMIRPot :: Gen MIRPot
genMIRPot = [MIRPot] -> Gen MIRPot
forall a. [a] -> Gen a
elements [ MIRPot
ReservesMIR, MIRPot
TreasuryMIR ]

genMIRTarget :: Gen MIRTarget
genMIRTarget :: Gen MIRTarget
genMIRTarget =
    [Gen MIRTarget] -> Gen MIRTarget
forall a. [Gen a] -> Gen a
oneof
        [ [(StakeCredential, Lovelace)] -> MIRTarget
StakeAddressesMIR
          ([(StakeCredential, Lovelace)] -> MIRTarget)
-> Gen [(StakeCredential, Lovelace)] -> Gen MIRTarget
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int)
-> Gen [(StakeCredential, Lovelace)]
-> Gen [(StakeCredential, Lovelace)]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen (StakeCredential, Lovelace)
-> Gen [(StakeCredential, Lovelace)]
forall a. Gen a -> Gen [a]
listOf ((,) (StakeCredential -> Lovelace -> (StakeCredential, Lovelace))
-> Gen StakeCredential
-> Gen (Lovelace -> (StakeCredential, Lovelace))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen StakeCredential
genStakeCredential Gen (Lovelace -> (StakeCredential, Lovelace))
-> Gen Lovelace -> Gen (StakeCredential, Lovelace)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace))
        , Lovelace -> MIRTarget
SendToReservesMIR (Lovelace -> MIRTarget) -> Gen Lovelace -> Gen MIRTarget
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace
        , Lovelace -> MIRTarget
SendToTreasuryMIR (Lovelace -> MIRTarget) -> Gen Lovelace -> Gen MIRTarget
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Lovelace
genLovelace
        ]

genStakePoolMetadata :: Gen StakePoolMetadata
genStakePoolMetadata :: Gen StakePoolMetadata
genStakePoolMetadata =
    Text -> Text -> Text -> Text -> StakePoolMetadata
StakePoolMetadata
    (Text -> Text -> Text -> Text -> StakePoolMetadata)
-> Gen Text -> Gen (Text -> Text -> Text -> StakePoolMetadata)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
genName
    Gen (Text -> Text -> Text -> StakePoolMetadata)
-> Gen Text -> Gen (Text -> Text -> StakePoolMetadata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
genDescription
    Gen (Text -> Text -> StakePoolMetadata)
-> Gen Text -> Gen (Text -> StakePoolMetadata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
genTicker
    Gen (Text -> StakePoolMetadata)
-> Gen Text -> Gen StakePoolMetadata
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
genHomepage

    where
        genName :: Gen T.Text
        genName :: Gen Text
genName = do
            -- There is a limit of 50 characters on the name
            Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
50)
            [Char] -> Text
T.pack ([Char] -> Text) -> Gen [Char] -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Char]
forall a. Arbitrary a => Int -> Gen [a]
vector Int
n

        genDescription :: Gen T.Text
        genDescription :: Gen Text
genDescription = do
            -- There is a overall limit of 512 bytes for metadata
            Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
64)
            [Char] -> Text
T.pack ([Char] -> Text) -> Gen [Char] -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Char]
forall a. Arbitrary a => Int -> Gen [a]
vector Int
n

        genTicker :: Gen T.Text
        genTicker :: Gen Text
genTicker = do
            Int
n <- (Int, Int) -> Gen Int
chooseInt (Int
3, Int
5)
            [Char] -> Text
T.pack ([Char] -> Text) -> Gen [Char] -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Char]
forall a. Arbitrary a => Int -> Gen [a]
vector Int
n

        genHomepage :: Gen T.Text
        genHomepage :: Gen Text
genHomepage = do
            -- There is a limit of 64 bytes on the size of the URL
            Text
scheme <- [Text] -> Gen Text
forall a. [a] -> Gen a
elements [ Text
"http://"
                               , Text
"https://"
                               ]
            Text
host <- [Char] -> Text
T.pack ([Char] -> Text) -> Gen [Char] -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen Char -> Gen [Char]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
10 Gen Char
genAlphaNum
            Text
domain <- [Text] -> Gen Text
forall a. [a] -> Gen a
elements [ Text
".com"
                               , Text
".net"
                               , Text
".org"
                               ]
            [Text] -> Gen Text
forall a. [a] -> Gen a
elements [ Text
""
                     , Text
scheme Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
host Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
domain
                     ]

instance ToJSON StakePoolMetadata where
    toJSON :: StakePoolMetadata -> Value
toJSON (StakePoolMetadata Text
name Text
description Text
ticker Text
homepage) =
        [Pair] -> Value
Aeson.object
            [ Key
"name" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
name
            , Key
"description" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
description
            , Key
"ticker" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
ticker
            , Key
"homepage" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
homepage
            ]

genStakePoolMetadataReference :: Gen StakePoolMetadataReference
genStakePoolMetadataReference :: Gen StakePoolMetadataReference
genStakePoolMetadataReference = do
    meta :: StakePoolMetadata
meta@(StakePoolMetadata Text
_name Text
_desc Text
_ticker Text
homepage) <- Gen StakePoolMetadata
genStakePoolMetadata
    StakePoolMetadataReference -> Gen StakePoolMetadataReference
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StakePoolMetadataReference -> Gen StakePoolMetadataReference)
-> StakePoolMetadataReference -> Gen StakePoolMetadataReference
forall a b. (a -> b) -> a -> b
$ Text -> Hash StakePoolMetadata -> StakePoolMetadataReference
StakePoolMetadataReference Text
homepage (StakePoolMetadata -> Hash StakePoolMetadata
hashStakePoolMetadata StakePoolMetadata
meta)

    where
        hashStakePoolMetadata :: StakePoolMetadata -> Hash StakePoolMetadata
        hashStakePoolMetadata :: StakePoolMetadata -> Hash StakePoolMetadata
hashStakePoolMetadata StakePoolMetadata
meta = do
            let json :: ByteString
json = StakePoolMetadata -> ByteString
forall a. ToJSON a => a -> ByteString
Aeson.encode StakePoolMetadata
meta
            case ByteString
-> Either
     StakePoolMetadataValidationError
     (StakePoolMetadata, Hash StakePoolMetadata)
validateAndHashStakePoolMetadata (ByteString -> ByteString
BL.toStrict ByteString
json) of
                Left StakePoolMetadataValidationError
err -> [Char] -> Hash StakePoolMetadata
forall a. HasCallStack => [Char] -> a
error
                    ([Char] -> Hash StakePoolMetadata)
-> [Char] -> Hash StakePoolMetadata
forall a b. (a -> b) -> a -> b
$ [Char]
"genStakePoolMetadata generated an invalid stake pool metadata: "
                      [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> StakePoolMetadataValidationError -> [Char]
forall a. Show a => a -> [Char]
show StakePoolMetadataValidationError
err
                Right (StakePoolMetadata
_meta, Hash StakePoolMetadata
metaHash) ->
                    Hash StakePoolMetadata
metaHash

genStakePoolRelay :: Gen StakePoolRelay
genStakePoolRelay :: Gen StakePoolRelay
genStakePoolRelay = do
    StakePoolRelay
relay <- Gen StakePoolRelay -> Gen StakePoolRelay
forall a. Gen a -> Gen a
hedgehog Gen StakePoolRelay
Ledger.genStakePoolRelay
    StakePoolRelay -> Gen StakePoolRelay
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StakePoolRelay -> Gen StakePoolRelay)
-> StakePoolRelay -> Gen StakePoolRelay
forall a b. (a -> b) -> a -> b
$ case StakePoolRelay
relay of
        Ledger.SingleHostAddr StrictMaybe Port
mPort StrictMaybe IPv4
mIPv4 StrictMaybe IPv6
mIPv6 ->
            Maybe IPv4 -> Maybe IPv6 -> Maybe PortNumber -> StakePoolRelay
StakePoolRelayIp
                (StrictMaybe IPv4 -> Maybe IPv4
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe StrictMaybe IPv4
mIPv4)
                (StrictMaybe IPv6 -> Maybe IPv6
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe StrictMaybe IPv6
mIPv6)
                (Port -> PortNumber
castPort (Port -> PortNumber) -> Maybe Port -> Maybe PortNumber
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictMaybe Port -> Maybe Port
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe StrictMaybe Port
mPort)
        Ledger.SingleHostName StrictMaybe Port
mPort DnsName
dnsName ->
            ByteString -> Maybe PortNumber -> StakePoolRelay
StakePoolRelayDnsARecord
                (Text -> ByteString
T.encodeUtf8 (Text -> ByteString) -> (DnsName -> Text) -> DnsName -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DnsName -> Text
Ledger.dnsToText (DnsName -> ByteString) -> DnsName -> ByteString
forall a b. (a -> b) -> a -> b
$ DnsName
dnsName)
                (Port -> PortNumber
castPort (Port -> PortNumber) -> Maybe Port -> Maybe PortNumber
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictMaybe Port -> Maybe Port
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe StrictMaybe Port
mPort)
        Ledger.MultiHostName DnsName
dnsName ->
            ByteString -> StakePoolRelay
StakePoolRelayDnsSrvRecord
                (Text -> ByteString
T.encodeUtf8 (Text -> ByteString) -> (DnsName -> Text) -> DnsName -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DnsName -> Text
Ledger.dnsToText (DnsName -> ByteString) -> DnsName -> ByteString
forall a b. (a -> b) -> a -> b
$ DnsName
dnsName)

    where
        castPort :: Ledger.Port -> PortNumber
        castPort :: Port -> PortNumber
castPort = Integer -> PortNumber
forall a. Num a => Integer -> a
fromInteger (Integer -> PortNumber) -> (Port -> Integer) -> Port -> PortNumber
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Integer
forall a. Integral a => a -> Integer
toInteger (Word16 -> Integer) -> (Port -> Word16) -> Port -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Port -> Word16
Ledger.portToWord16

genStakePoolParameters :: Gen StakePoolParameters
genStakePoolParameters :: Gen StakePoolParameters
genStakePoolParameters =
    PoolId
-> Hash VrfKey
-> Lovelace
-> Rational
-> StakeAddress
-> Lovelace
-> [Hash StakeKey]
-> [StakePoolRelay]
-> Maybe StakePoolMetadataReference
-> StakePoolParameters
StakePoolParameters
    (PoolId
 -> Hash VrfKey
 -> Lovelace
 -> Rational
 -> StakeAddress
 -> Lovelace
 -> [Hash StakeKey]
 -> [StakePoolRelay]
 -> Maybe StakePoolMetadataReference
 -> StakePoolParameters)
-> Gen PoolId
-> Gen
     (Hash VrfKey
      -> Lovelace
      -> Rational
      -> StakeAddress
      -> Lovelace
      -> [Hash StakeKey]
      -> [StakePoolRelay]
      -> Maybe StakePoolMetadataReference
      -> StakePoolParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen PoolId
genPoolId
    Gen
  (Hash VrfKey
   -> Lovelace
   -> Rational
   -> StakeAddress
   -> Lovelace
   -> [Hash StakeKey]
   -> [StakePoolRelay]
   -> Maybe StakePoolMetadataReference
   -> StakePoolParameters)
-> Gen (Hash VrfKey)
-> Gen
     (Lovelace
      -> Rational
      -> StakeAddress
      -> Lovelace
      -> [Hash StakeKey]
      -> [StakePoolRelay]
      -> Maybe StakePoolMetadataReference
      -> StakePoolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType VrfKey -> Gen (Hash VrfKey)
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType VrfKey
AsVrfKey
    Gen
  (Lovelace
   -> Rational
   -> StakeAddress
   -> Lovelace
   -> [Hash StakeKey]
   -> [StakePoolRelay]
   -> Maybe StakePoolMetadataReference
   -> StakePoolParameters)
-> Gen Lovelace
-> Gen
     (Rational
      -> StakeAddress
      -> Lovelace
      -> [Hash StakeKey]
      -> [StakePoolRelay]
      -> Maybe StakePoolMetadataReference
      -> StakePoolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  (Rational
   -> StakeAddress
   -> Lovelace
   -> [Hash StakeKey]
   -> [StakePoolRelay]
   -> Maybe StakePoolMetadataReference
   -> StakePoolParameters)
-> Gen Rational
-> Gen
     (StakeAddress
      -> Lovelace
      -> [Hash StakeKey]
      -> [StakePoolRelay]
      -> Maybe StakePoolMetadataReference
      -> StakePoolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Rational
genRational
    Gen
  (StakeAddress
   -> Lovelace
   -> [Hash StakeKey]
   -> [StakePoolRelay]
   -> Maybe StakePoolMetadataReference
   -> StakePoolParameters)
-> Gen StakeAddress
-> Gen
     (Lovelace
      -> [Hash StakeKey]
      -> [StakePoolRelay]
      -> Maybe StakePoolMetadataReference
      -> StakePoolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen StakeAddress
genStakeAddress
    Gen
  (Lovelace
   -> [Hash StakeKey]
   -> [StakePoolRelay]
   -> Maybe StakePoolMetadataReference
   -> StakePoolParameters)
-> Gen Lovelace
-> Gen
     ([Hash StakeKey]
      -> [StakePoolRelay]
      -> Maybe StakePoolMetadataReference
      -> StakePoolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Lovelace
genLovelace
    Gen
  ([Hash StakeKey]
   -> [StakePoolRelay]
   -> Maybe StakePoolMetadataReference
   -> StakePoolParameters)
-> Gen [Hash StakeKey]
-> Gen
     ([StakePoolRelay]
      -> Maybe StakePoolMetadataReference -> StakePoolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> Int) -> Gen [Hash StakeKey] -> Gen [Hash StakeKey]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen (Hash StakeKey) -> Gen [Hash StakeKey]
forall a. Gen a -> Gen [a]
listOf (AsType StakeKey -> Gen (Hash StakeKey)
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType StakeKey
AsStakeKey))
    Gen
  ([StakePoolRelay]
   -> Maybe StakePoolMetadataReference -> StakePoolParameters)
-> Gen [StakePoolRelay]
-> Gen (Maybe StakePoolMetadataReference -> StakePoolParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> Int) -> Gen [StakePoolRelay] -> Gen [StakePoolRelay]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen StakePoolRelay -> Gen [StakePoolRelay]
forall a. Gen a -> Gen [a]
listOf Gen StakePoolRelay
genStakePoolRelay)
    Gen (Maybe StakePoolMetadataReference -> StakePoolParameters)
-> Gen (Maybe StakePoolMetadataReference)
-> Gen StakePoolParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen StakePoolMetadataReference
-> Gen (Maybe StakePoolMetadataReference)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen StakePoolMetadataReference
genStakePoolMetadataReference

genTxCertificate :: Gen Certificate
genTxCertificate :: Gen Certificate
genTxCertificate =
    [Gen Certificate] -> Gen Certificate
forall a. [Gen a] -> Gen a
oneof
        [ StakeCredential -> Certificate
StakeAddressRegistrationCertificate (StakeCredential -> Certificate)
-> Gen StakeCredential -> Gen Certificate
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen StakeCredential
genStakeCredential
        , StakeCredential -> Certificate
StakeAddressDeregistrationCertificate (StakeCredential -> Certificate)
-> Gen StakeCredential -> Gen Certificate
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen StakeCredential
genStakeCredential
        , StakeCredential -> PoolId -> Certificate
StakeAddressDelegationCertificate (StakeCredential -> PoolId -> Certificate)
-> Gen StakeCredential -> Gen (PoolId -> Certificate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen StakeCredential
genStakeCredential Gen (PoolId -> Certificate) -> Gen PoolId -> Gen Certificate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen PoolId
genPoolId
        , StakePoolParameters -> Certificate
StakePoolRegistrationCertificate (StakePoolParameters -> Certificate)
-> Gen StakePoolParameters -> Gen Certificate
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen StakePoolParameters
genStakePoolParameters
        , PoolId -> EpochNo -> Certificate
StakePoolRetirementCertificate (PoolId -> EpochNo -> Certificate)
-> Gen PoolId -> Gen (EpochNo -> Certificate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen PoolId
genPoolId Gen (EpochNo -> Certificate) -> Gen EpochNo -> Gen Certificate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen EpochNo
genEpochNo
        , Hash GenesisKey
-> Hash GenesisDelegateKey -> Hash VrfKey -> Certificate
GenesisKeyDelegationCertificate
          (Hash GenesisKey
 -> Hash GenesisDelegateKey -> Hash VrfKey -> Certificate)
-> Gen (Hash GenesisKey)
-> Gen (Hash GenesisDelegateKey -> Hash VrfKey -> Certificate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType GenesisKey -> Gen (Hash GenesisKey)
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType GenesisKey
AsGenesisKey
          Gen (Hash GenesisDelegateKey -> Hash VrfKey -> Certificate)
-> Gen (Hash GenesisDelegateKey)
-> Gen (Hash VrfKey -> Certificate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType GenesisDelegateKey -> Gen (Hash GenesisDelegateKey)
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType GenesisDelegateKey
AsGenesisDelegateKey
          Gen (Hash VrfKey -> Certificate)
-> Gen (Hash VrfKey) -> Gen Certificate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType VrfKey -> Gen (Hash VrfKey)
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType VrfKey
AsVrfKey
        , do
              MIRTarget
target <- Gen MIRTarget
genMIRTarget
              MIRPot
pot <- case MIRTarget
target of
                  SendToTreasuryMIR Lovelace
_ -> MIRPot -> Gen MIRPot
forall (f :: * -> *) a. Applicative f => a -> f a
pure MIRPot
ReservesMIR
                  SendToReservesMIR Lovelace
_ -> MIRPot -> Gen MIRPot
forall (f :: * -> *) a. Applicative f => a -> f a
pure MIRPot
TreasuryMIR
                  MIRTarget
_ -> Gen MIRPot
genMIRPot
              Certificate -> Gen Certificate
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Certificate -> Gen Certificate) -> Certificate -> Gen Certificate
forall a b. (a -> b) -> a -> b
$ MIRPot -> MIRTarget -> Certificate
MIRCertificate MIRPot
pot MIRTarget
target
        ]

genTxCertificates :: CardanoEra era -> Gen (TxCertificates BuildTx era)
genTxCertificates :: CardanoEra era -> Gen (TxCertificates BuildTx era)
genTxCertificates CardanoEra era
era =
    case CardanoEra era -> Maybe (CertificatesSupportedInEra era)
forall era.
CardanoEra era -> Maybe (CertificatesSupportedInEra era)
certificatesSupportedInEra CardanoEra era
era of
        Maybe (CertificatesSupportedInEra era)
Nothing ->
            TxCertificates BuildTx era -> Gen (TxCertificates BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxCertificates BuildTx era
forall build era. TxCertificates build era
TxCertificatesNone
        Just CertificatesSupportedInEra era
supported ->
            [Gen (TxCertificates BuildTx era)]
-> Gen (TxCertificates BuildTx era)
forall a. [Gen a] -> Gen a
oneof
                [ TxCertificates BuildTx era -> Gen (TxCertificates BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxCertificates BuildTx era
forall build era. TxCertificates build era
TxCertificatesNone
                , CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     BuildTx (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates BuildTx era
forall era build.
CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     build (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates build era
TxCertificates CertificatesSupportedInEra era
supported
                  ([Certificate]
 -> BuildTxWith
      BuildTx (Map StakeCredential (Witness WitCtxStake era))
 -> TxCertificates BuildTx era)
-> Gen [Certificate]
-> Gen
     (BuildTxWith
        BuildTx (Map StakeCredential (Witness WitCtxStake era))
      -> TxCertificates BuildTx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int) -> Gen [Certificate] -> Gen [Certificate]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen Certificate -> Gen [Certificate]
forall a. Gen a -> Gen [a]
listOf Gen Certificate
genTxCertificate)
                  Gen
  (BuildTxWith
     BuildTx (Map StakeCredential (Witness WitCtxStake era))
   -> TxCertificates BuildTx era)
-> Gen
     (BuildTxWith
        BuildTx (Map StakeCredential (Witness WitCtxStake era)))
-> Gen (TxCertificates BuildTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( (Map StakeCredential (Witness WitCtxStake era)
-> BuildTxWith
     BuildTx (Map StakeCredential (Witness WitCtxStake era))
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Map StakeCredential (Witness WitCtxStake era)
 -> BuildTxWith
      BuildTx (Map StakeCredential (Witness WitCtxStake era)))
-> ([(StakeCredential, Witness WitCtxStake era)]
    -> Map StakeCredential (Witness WitCtxStake era))
-> [(StakeCredential, Witness WitCtxStake era)]
-> BuildTxWith
     BuildTx (Map StakeCredential (Witness WitCtxStake era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(StakeCredential, Witness WitCtxStake era)]
-> Map StakeCredential (Witness WitCtxStake era)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList)
                        ([(StakeCredential, Witness WitCtxStake era)]
 -> BuildTxWith
      BuildTx (Map StakeCredential (Witness WitCtxStake era)))
-> Gen [(StakeCredential, Witness WitCtxStake era)]
-> Gen
     (BuildTxWith
        BuildTx (Map StakeCredential (Witness WitCtxStake era)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int)
-> Gen [(StakeCredential, Witness WitCtxStake era)]
-> Gen [(StakeCredential, Witness WitCtxStake era)]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen (StakeCredential, Witness WitCtxStake era)
-> Gen [(StakeCredential, Witness WitCtxStake era)]
forall a. Gen a -> Gen [a]
listOf ( (,)
                                     (StakeCredential
 -> Witness WitCtxStake era
 -> (StakeCredential, Witness WitCtxStake era))
-> Gen StakeCredential
-> Gen
     (Witness WitCtxStake era
      -> (StakeCredential, Witness WitCtxStake era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen StakeCredential
genStakeCredential
                                     Gen
  (Witness WitCtxStake era
   -> (StakeCredential, Witness WitCtxStake era))
-> Gen (Witness WitCtxStake era)
-> Gen (StakeCredential, Witness WitCtxStake era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra era -> Gen (Witness WitCtxStake era)
forall era. CardanoEra era -> Gen (Witness WitCtxStake era)
genWitnessStake CardanoEra era
era
                                   ))
                      )
                ]

genProtocolParametersUpdate :: Gen ProtocolParametersUpdate
genProtocolParametersUpdate :: Gen ProtocolParametersUpdate
genProtocolParametersUpdate = do
    Maybe (Natural, Natural)
protocolUpdateProtocolVersion <-
        Gen (Natural, Natural) -> Gen (Maybe (Natural, Natural))
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary ((,) (Natural -> Natural -> (Natural, Natural))
-> Gen Natural -> Gen (Natural -> (Natural, Natural))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Natural
genNat Gen (Natural -> (Natural, Natural))
-> Gen Natural -> Gen (Natural, Natural)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Natural
genNat)
    Maybe Rational
protocolUpdateDecentralization <-
        Gen Rational -> Gen (Maybe Rational)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Rational
genRational
    Maybe (Maybe PraosNonce)
protocolUpdateExtraPraosEntropy <-
        Gen (Maybe PraosNonce) -> Gen (Maybe (Maybe PraosNonce))
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary (Gen PraosNonce -> Gen (Maybe PraosNonce)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen PraosNonce
genPraosNonce)
    Maybe Natural
protocolUpdateMaxBlockHeaderSize <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Natural
protocolUpdateMaxBlockBodySize <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Natural
protocolUpdateMaxTxSize <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Natural
protocolUpdateTxFeeFixed <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Natural
protocolUpdateTxFeePerByte <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Lovelace
protocolUpdateMinUTxOValue <-
        Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Maybe Lovelace
protocolUpdateStakeAddressDeposit <-
        Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Maybe Lovelace
protocolUpdateStakePoolDeposit <-
        Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Maybe Lovelace
protocolUpdateMinPoolCost <-
        Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Maybe EpochNo
protocolUpdatePoolRetireMaxEpoch <-
        Gen EpochNo -> Gen (Maybe EpochNo)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen EpochNo
genEpochNo
    Maybe Natural
protocolUpdateStakePoolTargetNum <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Rational
protocolUpdatePoolPledgeInfluence <-
        Gen Rational -> Gen (Maybe Rational)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Rational
genRational
    Maybe Rational
protocolUpdateMonetaryExpansion <-
        Gen Rational -> Gen (Maybe Rational)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Rational
genRational
    Maybe Rational
protocolUpdateTreasuryCut <-
        Gen Rational -> Gen (Maybe Rational)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Rational
genRational
    Maybe Lovelace
protocolUpdateUTxOCostPerWord <-
        Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Maybe Lovelace
protocolUpdateUTxOCostPerByte <-
        Gen Lovelace -> Gen (Maybe Lovelace)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Lovelace
genLovelace
    Map AnyPlutusScriptVersion CostModel
protocolUpdateCostModels <-
        Gen (Map AnyPlutusScriptVersion CostModel)
genCostModels
    Maybe ExecutionUnitPrices
protocolUpdatePrices <-
        Gen ExecutionUnitPrices -> Gen (Maybe ExecutionUnitPrices)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ExecutionUnitPrices
genExecutionUnitPrices
    Maybe ExecutionUnits
protocolUpdateMaxTxExUnits <-
        Gen ExecutionUnits -> Gen (Maybe ExecutionUnits)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ExecutionUnits
genExecutionUnits
    Maybe ExecutionUnits
protocolUpdateMaxBlockExUnits <-
        Gen ExecutionUnits -> Gen (Maybe ExecutionUnits)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ExecutionUnits
genExecutionUnits
    Maybe Natural
protocolUpdateMaxValueSize <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Natural
protocolUpdateCollateralPercent <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat
    Maybe Natural
protocolUpdateMaxCollateralInputs <-
        Gen Natural -> Gen (Maybe Natural)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen Natural
genNat

    ProtocolParametersUpdate -> Gen ProtocolParametersUpdate
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ProtocolParametersUpdate -> Gen ProtocolParametersUpdate)
-> ProtocolParametersUpdate -> Gen ProtocolParametersUpdate
forall a b. (a -> b) -> a -> b
$ ProtocolParametersUpdate :: Maybe (Natural, Natural)
-> Maybe Rational
-> Maybe (Maybe PraosNonce)
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Lovelace
-> Maybe Lovelace
-> Maybe Lovelace
-> Maybe Lovelace
-> Maybe EpochNo
-> Maybe Natural
-> Maybe Rational
-> Maybe Rational
-> Maybe Rational
-> Maybe Lovelace
-> Map AnyPlutusScriptVersion CostModel
-> Maybe ExecutionUnitPrices
-> Maybe ExecutionUnits
-> Maybe ExecutionUnits
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Lovelace
-> ProtocolParametersUpdate
ProtocolParametersUpdate
        { Maybe (Natural, Natural)
protocolUpdateProtocolVersion :: Maybe (Natural, Natural)
protocolUpdateProtocolVersion :: Maybe (Natural, Natural)
Api.protocolUpdateProtocolVersion
        , Maybe Rational
protocolUpdateDecentralization :: Maybe Rational
protocolUpdateDecentralization :: Maybe Rational
Api.protocolUpdateDecentralization
        , Maybe (Maybe PraosNonce)
protocolUpdateExtraPraosEntropy :: Maybe (Maybe PraosNonce)
protocolUpdateExtraPraosEntropy :: Maybe (Maybe PraosNonce)
Api.protocolUpdateExtraPraosEntropy
        , Maybe Natural
protocolUpdateMaxBlockHeaderSize :: Maybe Natural
protocolUpdateMaxBlockHeaderSize :: Maybe Natural
Api.protocolUpdateMaxBlockHeaderSize
        , Maybe Natural
protocolUpdateMaxBlockBodySize :: Maybe Natural
protocolUpdateMaxBlockBodySize :: Maybe Natural
Api.protocolUpdateMaxBlockBodySize
        , Maybe Natural
protocolUpdateMaxTxSize :: Maybe Natural
protocolUpdateMaxTxSize :: Maybe Natural
Api.protocolUpdateMaxTxSize
        , Maybe Natural
protocolUpdateTxFeeFixed :: Maybe Natural
protocolUpdateTxFeeFixed :: Maybe Natural
Api.protocolUpdateTxFeeFixed
        , Maybe Natural
protocolUpdateTxFeePerByte :: Maybe Natural
protocolUpdateTxFeePerByte :: Maybe Natural
Api.protocolUpdateTxFeePerByte
        , Maybe Lovelace
protocolUpdateMinUTxOValue :: Maybe Lovelace
protocolUpdateMinUTxOValue :: Maybe Lovelace
Api.protocolUpdateMinUTxOValue
        , Maybe Lovelace
protocolUpdateStakeAddressDeposit :: Maybe Lovelace
protocolUpdateStakeAddressDeposit :: Maybe Lovelace
Api.protocolUpdateStakeAddressDeposit
        , Maybe Lovelace
protocolUpdateStakePoolDeposit :: Maybe Lovelace
protocolUpdateStakePoolDeposit :: Maybe Lovelace
Api.protocolUpdateStakePoolDeposit
        , Maybe Lovelace
protocolUpdateMinPoolCost :: Maybe Lovelace
protocolUpdateMinPoolCost :: Maybe Lovelace
Api.protocolUpdateMinPoolCost
        , Maybe EpochNo
protocolUpdatePoolRetireMaxEpoch :: Maybe EpochNo
protocolUpdatePoolRetireMaxEpoch :: Maybe EpochNo
Api.protocolUpdatePoolRetireMaxEpoch
        , Maybe Natural
protocolUpdateStakePoolTargetNum :: Maybe Natural
protocolUpdateStakePoolTargetNum :: Maybe Natural
Api.protocolUpdateStakePoolTargetNum
        , Maybe Rational
protocolUpdatePoolPledgeInfluence :: Maybe Rational
protocolUpdatePoolPledgeInfluence :: Maybe Rational
Api.protocolUpdatePoolPledgeInfluence
        , Maybe Rational
protocolUpdateMonetaryExpansion :: Maybe Rational
protocolUpdateMonetaryExpansion :: Maybe Rational
Api.protocolUpdateMonetaryExpansion
        , Maybe Rational
protocolUpdateTreasuryCut :: Maybe Rational
protocolUpdateTreasuryCut :: Maybe Rational
Api.protocolUpdateTreasuryCut
        , Maybe Lovelace
protocolUpdateUTxOCostPerWord :: Maybe Lovelace
protocolUpdateUTxOCostPerWord :: Maybe Lovelace
Api.protocolUpdateUTxOCostPerWord
        , Maybe Lovelace
protocolUpdateUTxOCostPerByte :: Maybe Lovelace
protocolUpdateUTxOCostPerByte :: Maybe Lovelace
Api.protocolUpdateUTxOCostPerByte
        , Map AnyPlutusScriptVersion CostModel
protocolUpdateCostModels :: Map AnyPlutusScriptVersion CostModel
protocolUpdateCostModels :: Map AnyPlutusScriptVersion CostModel
Api.protocolUpdateCostModels
        , Maybe ExecutionUnitPrices
protocolUpdatePrices :: Maybe ExecutionUnitPrices
protocolUpdatePrices :: Maybe ExecutionUnitPrices
Api.protocolUpdatePrices
        , Maybe ExecutionUnits
protocolUpdateMaxTxExUnits :: Maybe ExecutionUnits
protocolUpdateMaxTxExUnits :: Maybe ExecutionUnits
Api.protocolUpdateMaxTxExUnits
        , Maybe ExecutionUnits
protocolUpdateMaxBlockExUnits :: Maybe ExecutionUnits
protocolUpdateMaxBlockExUnits :: Maybe ExecutionUnits
Api.protocolUpdateMaxBlockExUnits
        , Maybe Natural
protocolUpdateMaxValueSize :: Maybe Natural
protocolUpdateMaxValueSize :: Maybe Natural
Api.protocolUpdateMaxValueSize
        , Maybe Natural
protocolUpdateCollateralPercent :: Maybe Natural
protocolUpdateCollateralPercent :: Maybe Natural
Api.protocolUpdateCollateralPercent
        , Maybe Natural
protocolUpdateMaxCollateralInputs :: Maybe Natural
protocolUpdateMaxCollateralInputs :: Maybe Natural
Api.protocolUpdateMaxCollateralInputs
        }

genUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era)
genUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era)
genUpdateProposal CardanoEra era
era =
    case CardanoEra era -> Maybe (UpdateProposalSupportedInEra era)
forall era.
CardanoEra era -> Maybe (UpdateProposalSupportedInEra era)
updateProposalSupportedInEra CardanoEra era
era of
        Maybe (UpdateProposalSupportedInEra era)
Nothing ->
            TxUpdateProposal era -> Gen (TxUpdateProposal era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
        Just UpdateProposalSupportedInEra era
supported ->
            [Gen (TxUpdateProposal era)] -> Gen (TxUpdateProposal era)
forall a. [Gen a] -> Gen a
oneof
                [ TxUpdateProposal era -> Gen (TxUpdateProposal era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
                , UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
forall era.
UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal UpdateProposalSupportedInEra era
supported
                  (UpdateProposal -> TxUpdateProposal era)
-> Gen UpdateProposal -> Gen (TxUpdateProposal era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Map (Hash GenesisKey) ProtocolParametersUpdate
-> EpochNo -> UpdateProposal
UpdateProposal
                        (Map (Hash GenesisKey) ProtocolParametersUpdate
 -> EpochNo -> UpdateProposal)
-> Gen (Map (Hash GenesisKey) ProtocolParametersUpdate)
-> Gen (EpochNo -> UpdateProposal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( [(Hash GenesisKey, ProtocolParametersUpdate)]
-> Map (Hash GenesisKey) ProtocolParametersUpdate
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
                              ([(Hash GenesisKey, ProtocolParametersUpdate)]
 -> Map (Hash GenesisKey) ProtocolParametersUpdate)
-> Gen [(Hash GenesisKey, ProtocolParametersUpdate)]
-> Gen (Map (Hash GenesisKey) ProtocolParametersUpdate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Int)
-> Gen [(Hash GenesisKey, ProtocolParametersUpdate)]
-> Gen [(Hash GenesisKey, ProtocolParametersUpdate)]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen (Hash GenesisKey, ProtocolParametersUpdate)
-> Gen [(Hash GenesisKey, ProtocolParametersUpdate)]
forall a. Gen a -> Gen [a]
listOf ( (,)
                                    (Hash GenesisKey
 -> ProtocolParametersUpdate
 -> (Hash GenesisKey, ProtocolParametersUpdate))
-> Gen (Hash GenesisKey)
-> Gen
     (ProtocolParametersUpdate
      -> (Hash GenesisKey, ProtocolParametersUpdate))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AsType GenesisKey -> Gen (Hash GenesisKey)
forall keyrole. Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash AsType GenesisKey
AsGenesisKey
                                    Gen
  (ProtocolParametersUpdate
   -> (Hash GenesisKey, ProtocolParametersUpdate))
-> Gen ProtocolParametersUpdate
-> Gen (Hash GenesisKey, ProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ProtocolParametersUpdate
genProtocolParametersUpdate
                                  ))
                            )
                        Gen (EpochNo -> UpdateProposal)
-> Gen EpochNo -> Gen UpdateProposal
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen EpochNo
genEpochNo
                      )
                ]

genTxBodyContent :: CardanoEra era -> Gen (TxBodyContent BuildTx era)
genTxBodyContent :: CardanoEra era -> Gen (TxBodyContent BuildTx era)
genTxBodyContent CardanoEra era
era = do
    [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
txIns <- (Int -> Int)
-> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
 -> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))])
-> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a b. (a -> b) -> a -> b
$ do
        [TxIn]
txIns <- Gen TxIn -> Gen [TxIn]
forall a. Gen a -> Gen [a]
listOf1 Gen TxIn
genTxIn
        [Witness WitCtxTxIn era]
ctxs <- Int -> Gen (Witness WitCtxTxIn era) -> Gen [Witness WitCtxTxIn era]
forall a. Int -> Gen a -> Gen [a]
vectorOf ([TxIn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TxIn]
txIns) (CardanoEra era -> Gen (Witness WitCtxTxIn era)
forall era. CardanoEra era -> Gen (Witness WitCtxTxIn era)
genWitnessSpend CardanoEra era
era)
        [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
 -> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))])
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Gen [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a b. (a -> b) -> a -> b
$ [TxIn]
-> [BuildTxWith BuildTx (Witness WitCtxTxIn era)]
-> [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a b. [a] -> [b] -> [(a, b)]
zip [TxIn]
txIns (Witness WitCtxTxIn era
-> BuildTxWith BuildTx (Witness WitCtxTxIn era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxTxIn era
 -> BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> [Witness WitCtxTxIn era]
-> [BuildTxWith BuildTx (Witness WitCtxTxIn era)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Witness WitCtxTxIn era]
ctxs)
    [TxOut CtxTx era]
txOuts <- (Int -> Int) -> Gen [TxOut CtxTx era] -> Gen [TxOut CtxTx era]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen [TxOut CtxTx era] -> Gen [TxOut CtxTx era])
-> Gen [TxOut CtxTx era] -> Gen [TxOut CtxTx era]
forall a b. (a -> b) -> a -> b
$ Gen (TxOut CtxTx era) -> Gen [TxOut CtxTx era]
forall a. Gen a -> Gen [a]
listOf1 (Gen (TxOut CtxTx era) -> Gen [TxOut CtxTx era])
-> Gen (TxOut CtxTx era) -> Gen [TxOut CtxTx era]
forall a b. (a -> b) -> a -> b
$ CardanoEra era -> Gen (TxOut CtxTx era)
forall era ctx. CardanoEra era -> Gen (TxOut ctx era)
genTxOut CardanoEra era
era
    TxFee era
txFee <- CardanoEra era -> Gen (TxFee era)
forall era. CardanoEra era -> Gen (TxFee era)
genTxFee CardanoEra era
era
    (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange <- CardanoEra era
-> Gen (TxValidityLowerBound era, TxValidityUpperBound era)
forall era.
CardanoEra era
-> Gen (TxValidityLowerBound era, TxValidityUpperBound era)
genTxValidityRange CardanoEra era
era
    TxMetadataInEra era
txMetadata <- CardanoEra era -> Gen (TxMetadataInEra era)
forall era. CardanoEra era -> Gen (TxMetadataInEra era)
genTxMetadataInEra CardanoEra era
era
    TxAuxScripts era
txAuxScripts <- CardanoEra era -> Gen (TxAuxScripts era)
forall era. CardanoEra era -> Gen (TxAuxScripts era)
genTxAuxScripts CardanoEra era
era
    TxWithdrawals BuildTx era
txWithdrawals <- CardanoEra era -> Gen (TxWithdrawals BuildTx era)
forall era. CardanoEra era -> Gen (TxWithdrawals BuildTx era)
genTxWithdrawals CardanoEra era
era
    TxCertificates BuildTx era
txCertificates <- CardanoEra era -> Gen (TxCertificates BuildTx era)
forall era. CardanoEra era -> Gen (TxCertificates BuildTx era)
genTxCertificates CardanoEra era
era
    TxUpdateProposal era
txUpdateProposal <- CardanoEra era -> Gen (TxUpdateProposal era)
forall era. CardanoEra era -> Gen (TxUpdateProposal era)
genUpdateProposal CardanoEra era
era
    TxMintValue BuildTx era
txMintValue <- CardanoEra era -> Gen (TxMintValue BuildTx era)
forall era. CardanoEra era -> Gen (TxMintValue BuildTx era)
genTxMintValue CardanoEra era
era
    TxScriptValidity era
txScriptValidity <- CardanoEra era -> Gen (TxScriptValidity era)
forall era. CardanoEra era -> Gen (TxScriptValidity era)
genTxScriptValidity CardanoEra era
era
    TxExtraKeyWitnesses era
txExtraKeyWits <- CardanoEra era -> Gen (TxExtraKeyWitnesses era)
forall era. CardanoEra era -> Gen (TxExtraKeyWitnesses era)
genExtraKeyWitnesses CardanoEra era
era
    TxTotalCollateral era
txTotalCollateral <- CardanoEra era -> Gen (TxTotalCollateral era)
forall era. CardanoEra era -> Gen (TxTotalCollateral era)
genTxTotalCollateral CardanoEra era
era
    TxReturnCollateral CtxTx era
txReturnCollateral <- CardanoEra era -> Gen (TxReturnCollateral CtxTx era)
forall era ctx. CardanoEra era -> Gen (TxReturnCollateral ctx era)
genTxReturnCollateral CardanoEra era
era

    let
        txBody :: TxBodyContent BuildTx era
txBody = TxBodyContent :: forall build era.
TxIns build era
-> TxInsCollateral era
-> TxInsReference build era
-> [TxOut CtxTx era]
-> TxTotalCollateral era
-> TxReturnCollateral CtxTx era
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> TxExtraKeyWitnesses era
-> BuildTxWith build (Maybe ProtocolParameters)
-> TxWithdrawals build era
-> TxCertificates build era
-> TxUpdateProposal era
-> TxMintValue build era
-> TxScriptValidity era
-> TxBodyContent build era
TxBodyContent
            { [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
txIns :: [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
txIns :: [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
Api.txIns
            , [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
Api.txOuts
            -- NOTE: We are adding collateral at a later step, despite only
            -- generating @TxInsCollateralNone@ here. This seems to be because
            -- the generation currently is dependent on
            -- @collectTxBodyScriptWitnesses txBody@.
            , txInsCollateral :: TxInsCollateral era
Api.txInsCollateral = TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone

            -- TODO add proper generator, perhaps as part of ADP-1655
            , txInsReference :: TxInsReference BuildTx era
Api.txInsReference = TxInsReference BuildTx era
forall build era. TxInsReference build era
TxInsReferenceNone

            , TxTotalCollateral era
txTotalCollateral :: TxTotalCollateral era
txTotalCollateral :: TxTotalCollateral era
Api.txTotalCollateral
            , TxReturnCollateral CtxTx era
txReturnCollateral :: TxReturnCollateral CtxTx era
txReturnCollateral :: TxReturnCollateral CtxTx era
Api.txReturnCollateral
            , TxFee era
txFee :: TxFee era
txFee :: TxFee era
Api.txFee
            , (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange :: (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange :: (TxValidityLowerBound era, TxValidityUpperBound era)
Api.txValidityRange
            , TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: TxMetadataInEra era
Api.txMetadata
            , TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts :: TxAuxScripts era
Api.txAuxScripts
            , TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
Api.txExtraKeyWits
            , txProtocolParams :: BuildTxWith BuildTx (Maybe ProtocolParameters)
Api.txProtocolParams = Maybe ProtocolParameters
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Maybe ProtocolParameters
forall a. Maybe a
Nothing
            , TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
Api.txWithdrawals
            , TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
Api.txCertificates
            , TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
Api.txUpdateProposal
            , TxMintValue BuildTx era
txMintValue :: TxMintValue BuildTx era
txMintValue :: TxMintValue BuildTx era
Api.txMintValue
            , TxScriptValidity era
txScriptValidity :: TxScriptValidity era
txScriptValidity :: TxScriptValidity era
Api.txScriptValidity
            }

    let witnesses :: [(ScriptWitnessIndex, AnyScriptWitness era)]
witnesses = TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent BuildTx era
txBody
    -- No use of a script language means no need for collateral
    if Set AnyPlutusScriptVersion -> Bool
forall a. Set a -> Bool
Set.null ([(ScriptWitnessIndex, AnyScriptWitness era)]
-> Set AnyPlutusScriptVersion
forall a era.
[(a, AnyScriptWitness era)] -> Set AnyPlutusScriptVersion
languages [(ScriptWitnessIndex, AnyScriptWitness era)]
witnesses)
    then do
        BuildTxWith BuildTx (Maybe ProtocolParameters)
pparams <- Maybe ProtocolParameters
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Maybe ProtocolParameters
 -> BuildTxWith BuildTx (Maybe ProtocolParameters))
-> Gen (Maybe ProtocolParameters)
-> Gen (BuildTxWith BuildTx (Maybe ProtocolParameters))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ProtocolParameters -> Gen (Maybe ProtocolParameters)
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen ProtocolParameters
genProtocolParameters
        TxInsCollateral era
collateral <- CardanoEra era -> Gen (TxInsCollateral era)
forall era. CardanoEra era -> Gen (TxInsCollateral era)
genTxInsCollateral CardanoEra era
era
        TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era))
-> TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era)
forall a b. (a -> b) -> a -> b
$ TxBodyContent BuildTx era
txBody
            { txProtocolParams :: BuildTxWith BuildTx (Maybe ProtocolParameters)
Api.txProtocolParams = BuildTxWith BuildTx (Maybe ProtocolParameters)
pparams
            , txInsCollateral :: TxInsCollateral era
Api.txInsCollateral = TxInsCollateral era
collateral
            }
    else do
        BuildTxWith BuildTx (Maybe ProtocolParameters)
pparams <-
            (Maybe ProtocolParameters
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Maybe ProtocolParameters
 -> BuildTxWith BuildTx (Maybe ProtocolParameters))
-> (ProtocolParameters -> Maybe ProtocolParameters)
-> ProtocolParameters
-> BuildTxWith BuildTx (Maybe ProtocolParameters)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProtocolParameters -> Maybe ProtocolParameters
forall a. a -> Maybe a
Just) (ProtocolParameters
 -> BuildTxWith BuildTx (Maybe ProtocolParameters))
-> Gen ProtocolParameters
-> Gen (BuildTxWith BuildTx (Maybe ProtocolParameters))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ProtocolParameters
genProtocolParametersWithAlonzoScripts
        TxInsCollateral era
collateral <-
            case CardanoEra era -> Maybe (CollateralSupportedInEra era)
forall era. CardanoEra era -> Maybe (CollateralSupportedInEra era)
collateralSupportedInEra CardanoEra era
era of
                Maybe (CollateralSupportedInEra era)
Nothing -> TxInsCollateral era -> Gen (TxInsCollateral era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
                Just CollateralSupportedInEra era
supported -> CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
forall era.
CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
TxInsCollateral CollateralSupportedInEra era
supported ([TxIn] -> TxInsCollateral era)
-> Gen [TxIn] -> Gen (TxInsCollateral era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, Gen [TxIn])] -> Gen [TxIn]
forall a. [(Int, Gen a)] -> Gen a
frequency
                    [ (Int
95, [TxIn] -> Gen [TxIn]
forall (m :: * -> *) a. Monad m => a -> m a
return [])
                    , (Int
5, Gen TxIn -> Gen [TxIn]
forall a. Gen a -> Gen [a]
listOf Gen TxIn
genTxIn)
                    ]
        TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era))
-> TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era)
forall a b. (a -> b) -> a -> b
$ TxBodyContent BuildTx era
txBody
            { txProtocolParams :: BuildTxWith BuildTx (Maybe ProtocolParameters)
Api.txProtocolParams = BuildTxWith BuildTx (Maybe ProtocolParameters)
pparams
            , txInsCollateral :: TxInsCollateral era
Api.txInsCollateral = TxInsCollateral era
collateral
            }

    where
        languages :: [(a, AnyScriptWitness era)] -> Set AnyPlutusScriptVersion
        languages :: [(a, AnyScriptWitness era)] -> Set AnyPlutusScriptVersion
languages [(a, AnyScriptWitness era)]
witnesses =
            [AnyPlutusScriptVersion] -> Set AnyPlutusScriptVersion
forall a. Ord a => [a] -> Set a
Set.fromList
            [ PlutusScriptVersion lang -> AnyPlutusScriptVersion
forall lang. PlutusScriptVersion lang -> AnyPlutusScriptVersion
AnyPlutusScriptVersion PlutusScriptVersion lang
v
            | (a
_, AnyScriptWitness (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
v PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ ScriptData
_ ExecutionUnits
_)) <- [(a, AnyScriptWitness era)]
witnesses
            ]

genTxBody :: IsCardanoEra era => CardanoEra era -> Gen (TxBody era)
genTxBody :: CardanoEra era -> Gen (TxBody era)
genTxBody CardanoEra era
era = do
  Either TxBodyError (TxBody era)
res <- TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
forall era.
IsCardanoEra era =>
TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
makeTransactionBody (TxBodyContent BuildTx era -> Either TxBodyError (TxBody era))
-> Gen (TxBodyContent BuildTx era)
-> Gen (Either TxBodyError (TxBody era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era -> Gen (TxBodyContent BuildTx era)
forall era. CardanoEra era -> Gen (TxBodyContent BuildTx era)
genTxBodyContent CardanoEra era
era
  case Either TxBodyError (TxBody era)
res of
    Left TxBodyError
err -> [Char] -> Gen (TxBody era)
forall a. HasCallStack => [Char] -> a
error (TxBodyError -> [Char]
forall e. Error e => e -> [Char]
displayError TxBodyError
err)
    Right TxBody era
txBody -> TxBody era -> Gen (TxBody era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody era
txBody

-- | Similar to 'genTxBody', but with a distribution better suitable for testing
-- balancing.
genTxBodyForBalancing :: IsCardanoEra era => CardanoEra era -> Gen (TxBody era)
genTxBodyForBalancing :: CardanoEra era -> Gen (TxBody era)
genTxBodyForBalancing CardanoEra era
era = do
    Either TxBodyError (TxBody era)
res <- TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
forall era.
IsCardanoEra era =>
TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
makeTransactionBody (TxBodyContent BuildTx era -> Either TxBodyError (TxBody era))
-> Gen (TxBodyContent BuildTx era)
-> Gen (Either TxBodyError (TxBody era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (TxBodyContent BuildTx era)
genStrippedContent
    case Either TxBodyError (TxBody era)
res of
      Left TxBodyError
err -> [Char] -> Gen (TxBody era)
forall a. HasCallStack => [Char] -> a
error (TxBodyError -> [Char]
forall e. Error e => e -> [Char]
displayError TxBodyError
err)
      Right TxBody era
txBody -> TxBody era -> Gen (TxBody era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody era
txBody
  where
    genStrippedContent :: Gen (TxBodyContent BuildTx era)
genStrippedContent = do
        TxBodyContent BuildTx era
content <- CardanoEra era -> Gen (TxBodyContent BuildTx era)
forall era. CardanoEra era -> Gen (TxBodyContent BuildTx era)
genTxBodyContent CardanoEra era
era
        Gen Bool
genShouldStrip Gen Bool
-> (Bool -> Gen (TxBodyContent BuildTx era))
-> Gen (TxBodyContent BuildTx era)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
            Bool
True -> TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era))
-> TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era)
forall a b. (a -> b) -> a -> b
$ TxBodyContent BuildTx era
content
                { txInsCollateral :: TxInsCollateral era
txInsCollateral = case TxBodyContent BuildTx era -> TxInsCollateral era
forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral TxBodyContent BuildTx era
content of
                    TxInsCollateral era
TxInsCollateralNone -> TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
                    TxInsCollateral CollateralSupportedInEra era
colInEra [TxIn]
_ -> CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
forall era.
CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
TxInsCollateral CollateralSupportedInEra era
colInEra []
                }
            Bool
False -> TxBodyContent BuildTx era -> Gen (TxBodyContent BuildTx era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBodyContent BuildTx era
content
    genShouldStrip :: Gen Bool
genShouldStrip = [(Int, Gen Bool)] -> Gen Bool
forall a. [(Int, Gen a)] -> Gen a
frequency [ (Int
90, Bool -> Gen Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True), (Int
10, Bool -> Gen Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False) ]

genWitnesses :: CardanoEra era -> TxBody era -> Gen [KeyWitness era]
genWitnesses :: CardanoEra era -> TxBody era -> Gen [KeyWitness era]
genWitnesses CardanoEra era
era TxBody era
body =
    case CardanoEra era -> CardanoEraStyle era
forall era. CardanoEra era -> CardanoEraStyle era
cardanoEraStyle CardanoEra era
era of
        CardanoEraStyle era
LegacyByronEra    -> do
            (Int -> Int)
-> Gen [KeyWitness ByronEra] -> Gen [KeyWitness ByronEra]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen [KeyWitness ByronEra] -> Gen [KeyWitness ByronEra])
-> Gen [KeyWitness ByronEra] -> Gen [KeyWitness ByronEra]
forall a b. (a -> b) -> a -> b
$ Gen (KeyWitness ByronEra) -> Gen [KeyWitness ByronEra]
forall a. Gen a -> Gen [a]
listOf1 (Gen (KeyWitness ByronEra) -> Gen [KeyWitness ByronEra])
-> Gen (KeyWitness ByronEra) -> Gen [KeyWitness ByronEra]
forall a b. (a -> b) -> a -> b
$ NetworkId
-> TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra
forall key.
IsByronKey key =>
NetworkId
-> TxBody ByronEra -> SigningKey key -> KeyWitness ByronEra
makeByronKeyWitness
                (NetworkId
 -> TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra)
-> Gen NetworkId
-> Gen
     (TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen NetworkId
genNetworkId
                Gen (TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra)
-> Gen (TxBody ByronEra)
-> Gen (SigningKey ByronKey -> KeyWitness ByronEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxBody era -> Gen (TxBody era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody era
body
                Gen (SigningKey ByronKey -> KeyWitness ByronEra)
-> Gen (SigningKey ByronKey) -> Gen (KeyWitness ByronEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType ByronKey -> Gen (SigningKey ByronKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType ByronKey
AsByronKey
        ShelleyBasedEra ShelleyBasedEra era
_ -> do
            let
                genShelley :: Gen (KeyWitness era)
genShelley =
                    TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
forall era.
IsShelleyBasedEra era =>
TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
makeShelleyKeyWitness TxBody era
body (ShelleyWitnessSigningKey -> KeyWitness era)
-> Gen ShelleyWitnessSigningKey -> Gen (KeyWitness era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ShelleyWitnessSigningKey
genShelleyWitnessSigningKey
                genBootstrap :: Gen (KeyWitness era)
genBootstrap =
                    WitnessNetworkIdOrByronAddress
-> TxBody era -> SigningKey ByronKey -> KeyWitness era
forall era.
IsShelleyBasedEra era =>
WitnessNetworkIdOrByronAddress
-> TxBody era -> SigningKey ByronKey -> KeyWitness era
makeShelleyBootstrapWitness
                    (WitnessNetworkIdOrByronAddress
 -> TxBody era -> SigningKey ByronKey -> KeyWitness era)
-> Gen WitnessNetworkIdOrByronAddress
-> Gen (TxBody era -> SigningKey ByronKey -> KeyWitness era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen WitnessNetworkIdOrByronAddress
genWitnessNetworkIdOrByronAddress
                    Gen (TxBody era -> SigningKey ByronKey -> KeyWitness era)
-> Gen (TxBody era) -> Gen (SigningKey ByronKey -> KeyWitness era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxBody era -> Gen (TxBody era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody era
body
                    Gen (SigningKey ByronKey -> KeyWitness era)
-> Gen (SigningKey ByronKey) -> Gen (KeyWitness era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType ByronKey -> Gen (SigningKey ByronKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType ByronKey
AsByronKey

            [KeyWitness era]
bsWits  <- [(Int, Gen [KeyWitness era])] -> Gen [KeyWitness era]
forall a. [(Int, Gen a)] -> Gen a
frequency
                [ (Int
3, (Int -> Int) -> Gen [KeyWitness era] -> Gen [KeyWitness era]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen [KeyWitness era] -> Gen [KeyWitness era])
-> Gen [KeyWitness era] -> Gen [KeyWitness era]
forall a b. (a -> b) -> a -> b
$ Gen (KeyWitness era) -> Gen [KeyWitness era]
forall a. Gen a -> Gen [a]
listOf1 Gen (KeyWitness era)
genBootstrap)
                , (Int
1, [KeyWitness era] -> Gen [KeyWitness era]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [])
                ]
            [KeyWitness era]
keyWits <- [(Int, Gen [KeyWitness era])] -> Gen [KeyWitness era]
forall a. [(Int, Gen a)] -> Gen a
frequency
                [ (Int
3, (Int -> Int) -> Gen [KeyWitness era] -> Gen [KeyWitness era]
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3) (Gen [KeyWitness era] -> Gen [KeyWitness era])
-> Gen [KeyWitness era] -> Gen [KeyWitness era]
forall a b. (a -> b) -> a -> b
$ Gen (KeyWitness era) -> Gen [KeyWitness era]
forall a. Gen a -> Gen [a]
listOf1 Gen (KeyWitness era)
genShelley)
                , (Int
1, [KeyWitness era] -> Gen [KeyWitness era]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [])
                ]
            [KeyWitness era] -> Gen [KeyWitness era]
forall (m :: * -> *) a. Monad m => a -> m a
return ([KeyWitness era] -> Gen [KeyWitness era])
-> [KeyWitness era] -> Gen [KeyWitness era]
forall a b. (a -> b) -> a -> b
$ [KeyWitness era]
bsWits [KeyWitness era] -> [KeyWitness era] -> [KeyWitness era]
forall a. [a] -> [a] -> [a]
++ [KeyWitness era]
keyWits

genWitness :: CardanoEra era -> TxBody era -> Gen (KeyWitness era)
genWitness :: CardanoEra era -> TxBody era -> Gen (KeyWitness era)
genWitness CardanoEra era
era TxBody era
body =
  case CardanoEra era -> CardanoEraStyle era
forall era. CardanoEra era -> CardanoEraStyle era
cardanoEraStyle CardanoEra era
era of
    CardanoEraStyle era
LegacyByronEra    ->
        NetworkId
-> TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra
forall key.
IsByronKey key =>
NetworkId
-> TxBody ByronEra -> SigningKey key -> KeyWitness ByronEra
makeByronKeyWitness
            (NetworkId
 -> TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra)
-> Gen NetworkId
-> Gen
     (TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen NetworkId
genNetworkId
            Gen (TxBody ByronEra -> SigningKey ByronKey -> KeyWitness ByronEra)
-> Gen (TxBody ByronEra)
-> Gen (SigningKey ByronKey -> KeyWitness ByronEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxBody era -> Gen (TxBody era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody era
body
            Gen (SigningKey ByronKey -> KeyWitness ByronEra)
-> Gen (SigningKey ByronKey) -> Gen (KeyWitness ByronEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType ByronKey -> Gen (SigningKey ByronKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType ByronKey
AsByronKey
    ShelleyBasedEra ShelleyBasedEra era
_ ->
      [Gen (KeyWitness era)] -> Gen (KeyWitness era)
forall a. [Gen a] -> Gen a
oneof [ WitnessNetworkIdOrByronAddress
-> TxBody era -> SigningKey ByronKey -> KeyWitness era
forall era.
IsShelleyBasedEra era =>
WitnessNetworkIdOrByronAddress
-> TxBody era -> SigningKey ByronKey -> KeyWitness era
makeShelleyBootstrapWitness
                  (WitnessNetworkIdOrByronAddress
 -> TxBody era -> SigningKey ByronKey -> KeyWitness era)
-> Gen WitnessNetworkIdOrByronAddress
-> Gen (TxBody era -> SigningKey ByronKey -> KeyWitness era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen WitnessNetworkIdOrByronAddress
genWitnessNetworkIdOrByronAddress
                  Gen (TxBody era -> SigningKey ByronKey -> KeyWitness era)
-> Gen (TxBody era) -> Gen (SigningKey ByronKey -> KeyWitness era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxBody era -> Gen (TxBody era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody era
body
                  Gen (SigningKey ByronKey -> KeyWitness era)
-> Gen (SigningKey ByronKey) -> Gen (KeyWitness era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AsType ByronKey -> Gen (SigningKey ByronKey)
forall keyrole.
Key keyrole =>
AsType keyrole -> Gen (SigningKey keyrole)
genSigningKey AsType ByronKey
AsByronKey
            , TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
forall era.
IsShelleyBasedEra era =>
TxBody era -> ShelleyWitnessSigningKey -> KeyWitness era
makeShelleyKeyWitness TxBody era
body (ShelleyWitnessSigningKey -> KeyWitness era)
-> Gen ShelleyWitnessSigningKey -> Gen (KeyWitness era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ShelleyWitnessSigningKey
genShelleyWitnessSigningKey
            ]

genTxInEra :: forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxInEra :: CardanoEra era -> Gen (Tx era)
genTxInEra CardanoEra era
era = do
  TxBody era
body <- CardanoEra era -> Gen (TxBody era)
forall era. IsCardanoEra era => CardanoEra era -> Gen (TxBody era)
genTxBody CardanoEra era
era
  [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction
    ([KeyWitness era] -> TxBody era -> Tx era)
-> Gen [KeyWitness era] -> Gen (TxBody era -> Tx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era -> TxBody era -> Gen [KeyWitness era]
forall era. CardanoEra era -> TxBody era -> Gen [KeyWitness era]
genWitnesses CardanoEra era
era TxBody era
body
    Gen (TxBody era -> Tx era) -> Gen (TxBody era) -> Gen (Tx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxBody era -> Gen (TxBody era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody era
body

genTx :: Gen (InAnyCardanoEra Tx)
genTx :: Gen (InAnyCardanoEra Tx)
genTx =
    [Gen (InAnyCardanoEra Tx)] -> Gen (InAnyCardanoEra Tx)
forall a. [Gen a] -> Gen a
oneof [ CardanoEra ByronEra -> Tx ByronEra -> InAnyCardanoEra Tx
forall era (thing :: * -> *).
IsCardanoEra era =>
CardanoEra era -> thing era -> InAnyCardanoEra thing
InAnyCardanoEra CardanoEra ByronEra
ByronEra    (Tx ByronEra -> InAnyCardanoEra Tx)
-> Gen (Tx ByronEra) -> Gen (InAnyCardanoEra Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra ByronEra -> Gen (Tx ByronEra)
forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxInEra CardanoEra ByronEra
ByronEra
          , CardanoEra ShelleyEra -> Tx ShelleyEra -> InAnyCardanoEra Tx
forall era (thing :: * -> *).
IsCardanoEra era =>
CardanoEra era -> thing era -> InAnyCardanoEra thing
InAnyCardanoEra CardanoEra ShelleyEra
ShelleyEra  (Tx ShelleyEra -> InAnyCardanoEra Tx)
-> Gen (Tx ShelleyEra) -> Gen (InAnyCardanoEra Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra ShelleyEra -> Gen (Tx ShelleyEra)
forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxInEra CardanoEra ShelleyEra
ShelleyEra
          , CardanoEra MaryEra -> Tx MaryEra -> InAnyCardanoEra Tx
forall era (thing :: * -> *).
IsCardanoEra era =>
CardanoEra era -> thing era -> InAnyCardanoEra thing
InAnyCardanoEra CardanoEra MaryEra
MaryEra     (Tx MaryEra -> InAnyCardanoEra Tx)
-> Gen (Tx MaryEra) -> Gen (InAnyCardanoEra Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra MaryEra -> Gen (Tx MaryEra)
forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxInEra CardanoEra MaryEra
MaryEra
          , CardanoEra AllegraEra -> Tx AllegraEra -> InAnyCardanoEra Tx
forall era (thing :: * -> *).
IsCardanoEra era =>
CardanoEra era -> thing era -> InAnyCardanoEra thing
InAnyCardanoEra CardanoEra AllegraEra
AllegraEra  (Tx AllegraEra -> InAnyCardanoEra Tx)
-> Gen (Tx AllegraEra) -> Gen (InAnyCardanoEra Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra AllegraEra -> Gen (Tx AllegraEra)
forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxInEra CardanoEra AllegraEra
AllegraEra
          , CardanoEra AlonzoEra -> Tx AlonzoEra -> InAnyCardanoEra Tx
forall era (thing :: * -> *).
IsCardanoEra era =>
CardanoEra era -> thing era -> InAnyCardanoEra thing
InAnyCardanoEra CardanoEra AlonzoEra
AlonzoEra   (Tx AlonzoEra -> InAnyCardanoEra Tx)
-> Gen (Tx AlonzoEra) -> Gen (InAnyCardanoEra Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra AlonzoEra -> Gen (Tx AlonzoEra)
forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxInEra CardanoEra AlonzoEra
AlonzoEra
          , CardanoEra BabbageEra -> Tx BabbageEra -> InAnyCardanoEra Tx
forall era (thing :: * -> *).
IsCardanoEra era =>
CardanoEra era -> thing era -> InAnyCardanoEra thing
InAnyCardanoEra CardanoEra BabbageEra
BabbageEra  (Tx BabbageEra -> InAnyCardanoEra Tx)
-> Gen (Tx BabbageEra) -> Gen (InAnyCardanoEra Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra BabbageEra -> Gen (Tx BabbageEra)
forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxInEra CardanoEra BabbageEra
BabbageEra
          ]

-- TODO: Generate txs with no inputs
-- TODO: Generate txs with existing key witnesses
-- TODO: Generate txs with no outputs
genTxForBalancing :: forall era. IsCardanoEra era => CardanoEra era -> Gen (Tx era)
genTxForBalancing :: CardanoEra era -> Gen (Tx era)
genTxForBalancing CardanoEra era
era = [KeyWitness era] -> TxBody era -> Tx era
forall era. [KeyWitness era] -> TxBody era -> Tx era
makeSignedTransaction [] (TxBody era -> Tx era) -> Gen (TxBody era) -> Gen (Tx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra era -> Gen (TxBody era)
forall era. IsCardanoEra era => CardanoEra era -> Gen (TxBody era)
genTxBodyForBalancing CardanoEra era
era

--------------------------------------------------------------------------------
-- Orphan instances
--------------------------------------------------------------------------------

-- This definition makes it possible to avoid unwrapping and wrapping
-- 'Lovelace' values when using 'choose'.
--
deriving via Integer instance Random Lovelace