{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TypeApplications #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Consensus.Byron.Generators (
    RegularBlock (..)
  , epochSlots
  , genByronLedgerConfig
  , genByronLedgerState
  , k
  , protocolMagicId
  ) where

import           Cardano.Chain.Block (ABlockOrBoundary (..),
                     ABlockOrBoundaryHdr (..), ChainValidationState (..),
                     cvsPreviousHash)
import qualified Cardano.Chain.Block as CC.Block
import qualified Cardano.Chain.Byron.API as API
import           Cardano.Chain.Common (Address, BlockCount (..), CompactAddress,
                     KeyHash, Lovelace)
import qualified Cardano.Chain.Delegation as CC.Del
import qualified Cardano.Chain.Delegation.Validation.Activation as CC.Act
import qualified Cardano.Chain.Delegation.Validation.Interface as CC.DI
import qualified Cardano.Chain.Delegation.Validation.Scheduling as CC.Sched
import qualified Cardano.Chain.Genesis as Byron
import qualified Cardano.Chain.Genesis as CC.Genesis
import           Cardano.Chain.Slotting (EpochNumber, EpochSlots (..),
                     SlotNumber)
import qualified Cardano.Chain.Update as CC.Update
import qualified Cardano.Chain.Update.Validation.Interface as CC.UPI
import qualified Cardano.Chain.Update.Validation.Registration as CC.Reg
import qualified Cardano.Chain.UTxO as CC.UTxO
import           Cardano.Crypto (ProtocolMagicId (..),
                     RequiresNetworkMagic (..))
import           Cardano.Crypto.Hashing (Hash)
import           Cardano.Crypto.Signing
import qualified Cardano.Crypto.Wallet as Wallet
import           Cardano.Ledger.BaseTypes (knownNonZeroBounded)
import           Cardano.Ledger.Binary (decCBOR, encCBOR)
import           Control.Monad (replicateM)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as BSC8
import           Data.Coerce (coerce)
import qualified Data.Map.Strict as Map
import           Data.String (IsString (fromString))
import qualified Data.Text as T
import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.Byron.Ledger
import           Ouroboros.Consensus.Byron.Protocol
import           Ouroboros.Consensus.Config.SecurityParam
import           Ouroboros.Consensus.HeaderValidation (AnnTip (..))
import           Ouroboros.Consensus.Ledger.Abstract
import           Ouroboros.Consensus.Ledger.Query
import           Ouroboros.Consensus.Ledger.SupportsMempool (GenTxId)
import           Ouroboros.Consensus.Ledger.Tables.Utils (emptyLedgerTables)
import           Ouroboros.Consensus.Protocol.PBFT.State (PBftState)
import qualified Ouroboros.Consensus.Protocol.PBFT.State as PBftState
import           Ouroboros.Network.SizeInBytes
import qualified Test.Cardano.Chain.Block.Gen as CC
import qualified Test.Cardano.Chain.Common.Gen as CC
import qualified Test.Cardano.Chain.Delegation.Gen as CC
import qualified Test.Cardano.Chain.Genesis.Gen as CC
import qualified Test.Cardano.Chain.MempoolPayload.Gen as CC
import qualified Test.Cardano.Chain.Slotting.Gen as CC
import qualified Test.Cardano.Chain.Update.Gen as UG
import qualified Test.Cardano.Chain.UTxO.Gen as CC
import qualified Test.Cardano.Crypto.Gen as CC
import           Test.Cardano.Ledger.Binary.Arbitrary ()
import           Test.QuickCheck hiding (Result)
import           Test.QuickCheck.Hedgehog (hedgehog)
import           Test.Util.Orphans.Arbitrary ()
import           Test.Util.Serialisation.Roundtrip (Coherent (..),
                     WithVersion (..))
import           Test.Util.Serialisation.SomeResult (SomeResult (..))

{-------------------------------------------------------------------------------
  Generators
-------------------------------------------------------------------------------}

-- | Matches that from the 'CC.dummyConfig'
k :: SecurityParam
k :: SecurityParam
k = NonZero Word64 -> SecurityParam
SecurityParam (NonZero Word64 -> SecurityParam)
-> NonZero Word64 -> SecurityParam
forall a b. (a -> b) -> a -> b
$ forall (n :: Natural) a.
(KnownNat n, 1 <= n, WithinBounds n a, Num a) =>
NonZero a
knownNonZeroBounded @10

-- | Matches that from the 'CC.dummyConfig'
epochSlots :: EpochSlots
epochSlots :: EpochSlots
epochSlots = Word64 -> EpochSlots
EpochSlots Word64
100

protocolMagicId :: ProtocolMagicId
protocolMagicId :: ProtocolMagicId
protocolMagicId = Word32 -> ProtocolMagicId
ProtocolMagicId Word32
100

instance Arbitrary CC.Genesis.Config where
  arbitrary :: Gen Config
arbitrary = GenesisData
-> GenesisHash
-> RequiresNetworkMagic
-> UTxOConfiguration
-> Config
CC.Genesis.Config
    (GenesisData
 -> GenesisHash
 -> RequiresNetworkMagic
 -> UTxOConfiguration
 -> Config)
-> Gen GenesisData
-> Gen
     (GenesisHash
      -> RequiresNetworkMagic -> UTxOConfiguration -> Config)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen GenesisData
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (GenesisHash
   -> RequiresNetworkMagic -> UTxOConfiguration -> Config)
-> Gen GenesisHash
-> Gen (RequiresNetworkMagic -> UTxOConfiguration -> Config)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen GenesisHash
forall a. Arbitrary a => Gen a
arbitrary
    Gen (RequiresNetworkMagic -> UTxOConfiguration -> Config)
-> Gen RequiresNetworkMagic -> Gen (UTxOConfiguration -> Config)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen RequiresNetworkMagic
forall a. Arbitrary a => Gen a
arbitrary
    Gen (UTxOConfiguration -> Config)
-> Gen UTxOConfiguration -> Gen Config
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UTxOConfiguration
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Genesis.GenesisData where
  arbitrary :: Gen GenesisData
arbitrary = GenesisKeyHashes
-> GenesisDelegation
-> UTCTime
-> GenesisNonAvvmBalances
-> ProtocolParameters
-> BlockCount
-> ProtocolMagicId
-> GenesisAvvmBalances
-> GenesisData
CC.Genesis.GenesisData
    (GenesisKeyHashes
 -> GenesisDelegation
 -> UTCTime
 -> GenesisNonAvvmBalances
 -> ProtocolParameters
 -> BlockCount
 -> ProtocolMagicId
 -> GenesisAvvmBalances
 -> GenesisData)
-> Gen GenesisKeyHashes
-> Gen
     (GenesisDelegation
      -> UTCTime
      -> GenesisNonAvvmBalances
      -> ProtocolParameters
      -> BlockCount
      -> ProtocolMagicId
      -> GenesisAvvmBalances
      -> GenesisData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen GenesisKeyHashes
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (GenesisDelegation
   -> UTCTime
   -> GenesisNonAvvmBalances
   -> ProtocolParameters
   -> BlockCount
   -> ProtocolMagicId
   -> GenesisAvvmBalances
   -> GenesisData)
-> Gen GenesisDelegation
-> Gen
     (UTCTime
      -> GenesisNonAvvmBalances
      -> ProtocolParameters
      -> BlockCount
      -> ProtocolMagicId
      -> GenesisAvvmBalances
      -> GenesisData)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen GenesisDelegation
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (UTCTime
   -> GenesisNonAvvmBalances
   -> ProtocolParameters
   -> BlockCount
   -> ProtocolMagicId
   -> GenesisAvvmBalances
   -> GenesisData)
-> Gen UTCTime
-> Gen
     (GenesisNonAvvmBalances
      -> ProtocolParameters
      -> BlockCount
      -> ProtocolMagicId
      -> GenesisAvvmBalances
      -> GenesisData)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UTCTime
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (GenesisNonAvvmBalances
   -> ProtocolParameters
   -> BlockCount
   -> ProtocolMagicId
   -> GenesisAvvmBalances
   -> GenesisData)
-> Gen GenesisNonAvvmBalances
-> Gen
     (ProtocolParameters
      -> BlockCount
      -> ProtocolMagicId
      -> GenesisAvvmBalances
      -> GenesisData)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen GenesisNonAvvmBalances
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (ProtocolParameters
   -> BlockCount
   -> ProtocolMagicId
   -> GenesisAvvmBalances
   -> GenesisData)
-> Gen ProtocolParameters
-> Gen
     (BlockCount
      -> ProtocolMagicId -> GenesisAvvmBalances -> GenesisData)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ProtocolParameters
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (BlockCount
   -> ProtocolMagicId -> GenesisAvvmBalances -> GenesisData)
-> Gen BlockCount
-> Gen (ProtocolMagicId -> GenesisAvvmBalances -> GenesisData)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen BlockCount
forall a. Arbitrary a => Gen a
arbitrary
    Gen (ProtocolMagicId -> GenesisAvvmBalances -> GenesisData)
-> Gen ProtocolMagicId -> Gen (GenesisAvvmBalances -> GenesisData)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ProtocolMagicId
forall a. Arbitrary a => Gen a
arbitrary
    Gen (GenesisAvvmBalances -> GenesisData)
-> Gen GenesisAvvmBalances -> Gen GenesisData
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen GenesisAvvmBalances
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Genesis.GenesisKeyHashes where
  arbitrary :: Gen GenesisKeyHashes
arbitrary = Set KeyHash -> GenesisKeyHashes
CC.Genesis.GenesisKeyHashes (Set KeyHash -> GenesisKeyHashes)
-> Gen (Set KeyHash) -> Gen GenesisKeyHashes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Set KeyHash)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Genesis.GenesisDelegation where
  arbitrary :: Gen GenesisDelegation
arbitrary = ([Certificate] -> Either GenesisDelegationError GenesisDelegation
forall (m :: * -> *).
MonadError GenesisDelegationError m =>
[Certificate] -> m GenesisDelegation
CC.Genesis.mkGenesisDelegation ([Certificate] -> Either GenesisDelegationError GenesisDelegation)
-> Gen [Certificate]
-> Gen (Either GenesisDelegationError GenesisDelegation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Certificate]
forall a. Arbitrary a => Gen a
arbitrary)
    Gen (Either GenesisDelegationError GenesisDelegation)
-> (Either GenesisDelegationError GenesisDelegation
    -> Maybe GenesisDelegation)
-> Gen GenesisDelegation
forall a b. Gen a -> (a -> Maybe b) -> Gen b
`suchThatMap` ((GenesisDelegationError -> Maybe GenesisDelegation)
-> (GenesisDelegation -> Maybe GenesisDelegation)
-> Either GenesisDelegationError GenesisDelegation
-> Maybe GenesisDelegation
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe GenesisDelegation
-> GenesisDelegationError -> Maybe GenesisDelegation
forall a b. a -> b -> a
const Maybe GenesisDelegation
forall a. Maybe a
Nothing) GenesisDelegation -> Maybe GenesisDelegation
forall a. a -> Maybe a
Just)

instance Arbitrary (CC.Del.ACertificate ()) where
  arbitrary :: Gen Certificate
arbitrary = ProtocolMagicId
-> VerificationKey -> EpochNumber -> SafeSigner -> Certificate
CC.Del.signCertificate
    (ProtocolMagicId
 -> VerificationKey -> EpochNumber -> SafeSigner -> Certificate)
-> Gen ProtocolMagicId
-> Gen
     (VerificationKey -> EpochNumber -> SafeSigner -> Certificate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ProtocolMagicId
forall a. Arbitrary a => Gen a
arbitrary
    Gen (VerificationKey -> EpochNumber -> SafeSigner -> Certificate)
-> Gen VerificationKey
-> Gen (EpochNumber -> SafeSigner -> Certificate)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen VerificationKey
forall a. Arbitrary a => Gen a
arbitrary
    Gen (EpochNumber -> SafeSigner -> Certificate)
-> Gen EpochNumber -> Gen (SafeSigner -> Certificate)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen EpochNumber
forall a. Arbitrary a => Gen a
arbitrary
    Gen (SafeSigner -> Certificate)
-> Gen SafeSigner -> Gen Certificate
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen SafeSigner
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary SafeSigner where
  arbitrary :: Gen SafeSigner
arbitrary = do
    seed <- [Word8] -> ByteString
BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Gen Word8] -> Gen [Word8]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence (Int -> Gen Word8 -> [Gen Word8]
forall a. Int -> a -> [a]
replicate Int
32 Gen Word8
forall a. Arbitrary a => Gen a
arbitrary)
    passPhrase <- BS.pack <$> sequence (replicate passphraseLength arbitrary)
    let xprv = ByteString -> ByteString -> XPrv
forall passPhrase seed.
(ByteArrayAccess passPhrase, ByteArrayAccess seed) =>
seed -> passPhrase -> XPrv
Wallet.generate ByteString
seed ByteString
passPhrase
    return $ SafeSigner (SigningKey xprv) (PassPhrase (fromString (BSC8.unpack passPhrase)))

instance Arbitrary VerificationKey where
  arbitrary :: Gen VerificationKey
arbitrary = (VerificationKeyParseError -> VerificationKey)
-> (VerificationKey -> VerificationKey)
-> Either VerificationKeyParseError VerificationKey
-> VerificationKey
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> VerificationKey
forall a. HasCallStack => String -> a
error (String -> VerificationKey)
-> (VerificationKeyParseError -> String)
-> VerificationKeyParseError
-> VerificationKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerificationKeyParseError -> String
forall a. Show a => a -> String
show) VerificationKey -> VerificationKey
forall a. a -> a
id (Either VerificationKeyParseError VerificationKey
 -> VerificationKey)
-> (Text -> Either VerificationKeyParseError VerificationKey)
-> Text
-> VerificationKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either VerificationKeyParseError VerificationKey
parseFullVerificationKey (Text -> VerificationKey) -> Gen Text -> Gen VerificationKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (String -> Text
T.pack (String -> Text) -> (ByteString -> String) -> ByteString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BSC8.unpack (ByteString -> String)
-> (ByteString -> ByteString) -> ByteString -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64.encode (ByteString -> Text) -> Gen ByteString -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ByteString
arbitraryKey)
    where
      -- The key must be 64 bytes
      arbitraryKey :: Gen ByteString
arbitraryKey = [Word8] -> ByteString
BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Gen Word8] -> Gen [Word8]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence (Int -> Gen Word8 -> [Gen Word8]
forall a. Int -> a -> [a]
replicate Int
64 Gen Word8
forall a. Arbitrary a => Gen a
arbitrary)

instance Arbitrary CC.Genesis.GenesisNonAvvmBalances where
  arbitrary :: Gen GenesisNonAvvmBalances
arbitrary = Map Address Lovelace -> GenesisNonAvvmBalances
CC.Genesis.GenesisNonAvvmBalances (Map Address Lovelace -> GenesisNonAvvmBalances)
-> Gen (Map Address Lovelace) -> Gen GenesisNonAvvmBalances
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Map Address Lovelace)
forall a. Arbitrary a => Gen a
arbitrary

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

instance Arbitrary Lovelace where
  arbitrary :: Gen Lovelace
arbitrary = Gen Lovelace -> Gen Lovelace
forall a. Gen a -> Gen a
hedgehog Gen Lovelace
CC.genLovelace

instance Arbitrary CC.Genesis.GenesisAvvmBalances where
  arbitrary :: Gen GenesisAvvmBalances
arbitrary = Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances
CC.Genesis.GenesisAvvmBalances (Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances)
-> Gen (Map CompactRedeemVerificationKey Lovelace)
-> Gen GenesisAvvmBalances
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Map CompactRedeemVerificationKey Lovelace)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CompactRedeemVerificationKey where
  arbitrary :: Gen CompactRedeemVerificationKey
arbitrary = Gen CompactRedeemVerificationKey
-> Gen CompactRedeemVerificationKey
forall a. Gen a -> Gen a
hedgehog Gen CompactRedeemVerificationKey
CC.genCompactRedeemVerificationKey

instance Arbitrary BlockCount where
  arbitrary :: Gen BlockCount
arbitrary = Gen BlockCount -> Gen BlockCount
forall a. Gen a -> Gen a
hedgehog Gen BlockCount
CC.genBlockCount

instance Arbitrary RequiresNetworkMagic where
  arbitrary :: Gen RequiresNetworkMagic
arbitrary = Gen RequiresNetworkMagic -> Gen RequiresNetworkMagic
forall a. Gen a -> Gen a
hedgehog Gen RequiresNetworkMagic
CC.genRequiresNetworkMagic

instance Arbitrary ProtocolMagicId where
  arbitrary :: Gen ProtocolMagicId
arbitrary = Gen ProtocolMagicId -> Gen ProtocolMagicId
forall a. Gen a -> Gen a
hedgehog Gen ProtocolMagicId
CC.genProtocolMagicId

instance Arbitrary CC.UTxO.UTxOConfiguration where
  arbitrary :: Gen UTxOConfiguration
arbitrary = Set CompactAddress -> UTxOConfiguration
CC.UTxO.UTxOConfiguration (Set CompactAddress -> UTxOConfiguration)
-> Gen (Set CompactAddress) -> Gen UTxOConfiguration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Set CompactAddress)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CompactAddress where
  arbitrary :: Gen CompactAddress
arbitrary = Gen CompactAddress -> Gen CompactAddress
forall a. Gen a -> Gen a
hedgehog Gen CompactAddress
CC.genCompactAddress

-- | A 'ByronBlock' that is never an EBB.
newtype RegularBlock = RegularBlock { RegularBlock -> ByronBlock
unRegularBlock :: ByronBlock }
  deriving (RegularBlock -> RegularBlock -> Bool
(RegularBlock -> RegularBlock -> Bool)
-> (RegularBlock -> RegularBlock -> Bool) -> Eq RegularBlock
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RegularBlock -> RegularBlock -> Bool
== :: RegularBlock -> RegularBlock -> Bool
$c/= :: RegularBlock -> RegularBlock -> Bool
/= :: RegularBlock -> RegularBlock -> Bool
Eq, Int -> RegularBlock -> ShowS
[RegularBlock] -> ShowS
RegularBlock -> String
(Int -> RegularBlock -> ShowS)
-> (RegularBlock -> String)
-> ([RegularBlock] -> ShowS)
-> Show RegularBlock
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RegularBlock -> ShowS
showsPrec :: Int -> RegularBlock -> ShowS
$cshow :: RegularBlock -> String
show :: RegularBlock -> String
$cshowList :: [RegularBlock] -> ShowS
showList :: [RegularBlock] -> ShowS
Show)

instance Arbitrary RegularBlock where
  arbitrary :: Gen RegularBlock
arbitrary =
    ByronBlock -> RegularBlock
RegularBlock (ByronBlock -> RegularBlock)
-> (Block -> ByronBlock) -> Block -> RegularBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
.EpochSlots -> Block -> ByronBlock
annotateByronBlock EpochSlots
epochSlots (Block -> RegularBlock) -> Gen Block -> Gen RegularBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    Gen Block -> Gen Block
forall a. Gen a -> Gen a
hedgehog (ProtocolMagicId -> EpochSlots -> Gen Block
CC.genBlock ProtocolMagicId
protocolMagicId EpochSlots
epochSlots)

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

instance Arbitrary (Coherent ByronBlock) where
  arbitrary :: Gen (Coherent ByronBlock)
arbitrary = ByronBlock -> Coherent ByronBlock
forall a. a -> Coherent a
Coherent (ByronBlock -> Coherent ByronBlock)
-> Gen ByronBlock -> Gen (Coherent ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, Gen ByronBlock)] -> Gen ByronBlock
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency
      [ (Int
3, Gen ByronBlock
genBlock)
      , (Int
1, Gen ByronBlock
genBoundaryBlock)
      ]
    where
      genBlock :: Gen ByronBlock
      genBlock :: Gen ByronBlock
genBlock = RegularBlock -> ByronBlock
unRegularBlock (RegularBlock -> ByronBlock) -> Gen RegularBlock -> Gen ByronBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen RegularBlock
forall a. Arbitrary a => Gen a
arbitrary
      genBoundaryBlock :: Gen ByronBlock
      genBoundaryBlock :: Gen ByronBlock
genBoundaryBlock =
        EpochSlots -> ABlockOrBoundary ByteString -> ByronBlock
mkByronBlock EpochSlots
epochSlots (ABlockOrBoundary ByteString -> ByronBlock)
-> (ABoundaryBlock () -> ABlockOrBoundary ByteString)
-> ABoundaryBlock ()
-> ByronBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ABoundaryBlock ByteString -> ABlockOrBoundary ByteString
forall a. ABoundaryBlock a -> ABlockOrBoundary a
ABOBBoundary (ABoundaryBlock ByteString -> ABlockOrBoundary ByteString)
-> (ABoundaryBlock () -> ABoundaryBlock ByteString)
-> ABoundaryBlock ()
-> ABlockOrBoundary ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProtocolMagicId -> ABoundaryBlock () -> ABoundaryBlock ByteString
API.reAnnotateBoundary ProtocolMagicId
protocolMagicId (ABoundaryBlock () -> ByronBlock)
-> Gen (ABoundaryBlock ()) -> Gen ByronBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        Gen (ABoundaryBlock ()) -> Gen (ABoundaryBlock ())
forall a. Gen a -> Gen a
hedgehog (Gen (ABoundaryBlock ())
CC.genBoundaryBlock)

instance Arbitrary (Header ByronBlock) where
  arbitrary :: Gen (Header ByronBlock)
arbitrary = [(Int, Gen (Header ByronBlock))] -> Gen (Header ByronBlock)
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency
      [ (Int
3, Gen (Header ByronBlock)
genHeader)
      , (Int
1, Gen (Header ByronBlock)
genBoundaryHeader)
      ]
    where
      genHeader :: Gen (Header ByronBlock)
      genHeader :: Gen (Header ByronBlock)
genHeader = do
        blockSize <- Word32 -> SizeInBytes
SizeInBytes (Word32 -> SizeInBytes) -> Gen Word32 -> Gen SizeInBytes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word32
forall a. Arbitrary a => Gen a
arbitrary
        flip (mkByronHeader epochSlots) blockSize . ABOBBlockHdr .
          API.reAnnotateUsing
            (CC.Block.encCBORHeader epochSlots)
            (CC.Block.decCBORAHeader epochSlots) <$>
          hedgehog (CC.genHeader protocolMagicId epochSlots)

      genBoundaryHeader :: Gen (Header ByronBlock)
      genBoundaryHeader :: Gen (Header ByronBlock)
genBoundaryHeader = do
        blockSize <- Word32 -> SizeInBytes
SizeInBytes (Word32 -> SizeInBytes) -> Gen Word32 -> Gen SizeInBytes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word32
forall a. Arbitrary a => Gen a
arbitrary
        flip (mkByronHeader epochSlots) blockSize . ABOBBoundaryHdr .
          API.reAnnotateUsing
            (CC.Block.encCBORABoundaryHeader protocolMagicId)
            CC.Block.decCBORABoundaryHeader <$>
          hedgehog CC.genBoundaryHeader

instance Arbitrary (Hash a) where
  arbitrary :: Gen (Hash a)
arbitrary = Hash Text -> Hash a
forall a b. Coercible a b => a -> b
coerce (Hash Text -> Hash a) -> Gen (Hash Text) -> Gen (Hash a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Hash Text) -> Gen (Hash Text)
forall a. Gen a -> Gen a
hedgehog Gen (Hash Text)
CC.genTextHash

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

instance Arbitrary KeyHash where
  arbitrary :: Gen KeyHash
arbitrary = Gen KeyHash -> Gen KeyHash
forall a. Gen a -> Gen a
hedgehog Gen KeyHash
CC.genKeyHash

instance Arbitrary (GenTx ByronBlock) where
  arbitrary :: Gen (GenTx ByronBlock)
arbitrary =
    AMempoolPayload ByteString -> GenTx ByronBlock
fromMempoolPayload (AMempoolPayload ByteString -> GenTx ByronBlock)
-> (AMempoolPayload () -> AMempoolPayload ByteString)
-> AMempoolPayload ()
-> GenTx ByronBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AMempoolPayload () -> Encoding)
-> (forall s. Decoder s (AMempoolPayload ByteSpan))
-> AMempoolPayload ()
-> AMempoolPayload ByteString
forall (f :: * -> *) a.
Functor f =>
(f a -> Encoding)
-> (forall s. Decoder s (f ByteSpan)) -> f a -> f ByteString
API.reAnnotateUsing AMempoolPayload () -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Decoder s (AMempoolPayload ByteSpan)
forall s. Decoder s (AMempoolPayload ByteSpan)
forall a s. DecCBOR a => Decoder s a
decCBOR (AMempoolPayload () -> GenTx ByronBlock)
-> Gen (AMempoolPayload ()) -> Gen (GenTx ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    Gen (AMempoolPayload ()) -> Gen (AMempoolPayload ())
forall a. Gen a -> Gen a
hedgehog (ProtocolMagicId -> Gen (AMempoolPayload ())
CC.genMempoolPayload ProtocolMagicId
protocolMagicId)

instance Arbitrary (GenTxId ByronBlock) where
  arbitrary :: Gen (GenTxId ByronBlock)
arbitrary = [Gen (GenTxId ByronBlock)] -> Gen (GenTxId ByronBlock)
forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ TxId -> GenTxId ByronBlock
ByronTxId             (TxId -> GenTxId ByronBlock)
-> Gen TxId -> Gen (GenTxId ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxId -> Gen TxId
forall a. Gen a -> Gen a
hedgehog Gen TxId
CC.genTxId
      , CertificateId -> GenTxId ByronBlock
ByronDlgId            (CertificateId -> GenTxId ByronBlock)
-> Gen CertificateId -> Gen (GenTxId ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen CertificateId -> Gen CertificateId
forall a. Gen a -> Gen a
hedgehog Gen CertificateId
genCertificateId
      , UpId -> GenTxId ByronBlock
ByronUpdateProposalId (UpId -> GenTxId ByronBlock)
-> Gen UpId -> Gen (GenTxId ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen UpId -> Gen UpId
forall a. Gen a -> Gen a
hedgehog (ProtocolMagicId -> Gen UpId
UG.genUpId ProtocolMagicId
protocolMagicId)
      , VoteId -> GenTxId ByronBlock
ByronUpdateVoteId     (VoteId -> GenTxId ByronBlock)
-> Gen VoteId -> Gen (GenTxId ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen VoteId -> Gen VoteId
forall a. Gen a -> Gen a
hedgehog Gen VoteId
genUpdateVoteId
      ]
    where
      genCertificateId :: Gen CertificateId
genCertificateId = Gen Certificate -> Gen CertificateId
forall a algo.
(EncCBOR a, HashAlgorithm algo) =>
Gen a -> Gen (AbstractHash algo a)
CC.genAbstractHash (ProtocolMagicId -> Gen Certificate
CC.genCertificate ProtocolMagicId
protocolMagicId)
      genUpdateVoteId :: Gen VoteId
genUpdateVoteId  = Gen Vote -> Gen VoteId
forall a algo.
(EncCBOR a, HashAlgorithm algo) =>
Gen a -> Gen (AbstractHash algo a)
CC.genAbstractHash (ProtocolMagicId -> Gen Vote
UG.genVote ProtocolMagicId
protocolMagicId)

instance Arbitrary API.ApplyMempoolPayloadErr where
  arbitrary :: Gen ApplyMempoolPayloadErr
arbitrary = [Gen ApplyMempoolPayloadErr] -> Gen ApplyMempoolPayloadErr
forall a. HasCallStack => [Gen a] -> Gen a
oneof
    [ UTxOValidationError -> ApplyMempoolPayloadErr
API.MempoolTxErr  (UTxOValidationError -> ApplyMempoolPayloadErr)
-> Gen UTxOValidationError -> Gen ApplyMempoolPayloadErr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen UTxOValidationError -> Gen UTxOValidationError
forall a. Gen a -> Gen a
hedgehog Gen UTxOValidationError
CC.genUTxOValidationError
    , Error -> ApplyMempoolPayloadErr
API.MempoolDlgErr (Error -> ApplyMempoolPayloadErr)
-> Gen Error -> Gen ApplyMempoolPayloadErr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Error -> Gen Error
forall a. Gen a -> Gen a
hedgehog Gen Error
CC.genError
    -- TODO there is no generator for
    -- Cardano.Chain.Update.Validation.Interface.Error and we can't write one
    -- either because the different Error types it wraps are not exported.
    -- , MempoolUpdateProposalErr <$> arbitrary
    -- , MempoolUpdateVoteErr     <$> arbitrary
    ]

instance Arbitrary (SomeBlockQuery (BlockQuery ByronBlock)) where
  arbitrary :: Gen (SomeBlockQuery (BlockQuery ByronBlock))
arbitrary = SomeBlockQuery (BlockQuery ByronBlock)
-> Gen (SomeBlockQuery (BlockQuery ByronBlock))
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeBlockQuery (BlockQuery ByronBlock)
 -> Gen (SomeBlockQuery (BlockQuery ByronBlock)))
-> SomeBlockQuery (BlockQuery ByronBlock)
-> Gen (SomeBlockQuery (BlockQuery ByronBlock))
forall a b. (a -> b) -> a -> b
$ BlockQuery ByronBlock 'QFNoTables State
-> SomeBlockQuery (BlockQuery ByronBlock)
forall (q :: QueryFootprint -> * -> *)
       (footprint :: QueryFootprint) result.
SingI footprint =>
q footprint result -> SomeBlockQuery q
SomeBlockQuery BlockQuery ByronBlock 'QFNoTables State
GetUpdateInterfaceState

instance Arbitrary EpochNumber where
  arbitrary :: Gen EpochNumber
arbitrary = Gen EpochNumber -> Gen EpochNumber
forall a. Gen a -> Gen a
hedgehog Gen EpochNumber
CC.genEpochNumber

instance Arbitrary SlotNumber where
  arbitrary :: Gen SlotNumber
arbitrary = Gen SlotNumber -> Gen SlotNumber
forall a. Gen a -> Gen a
hedgehog Gen SlotNumber
CC.genSlotNumber

instance Arbitrary CC.Update.ApplicationName where
  arbitrary :: Gen ApplicationName
arbitrary = Gen ApplicationName -> Gen ApplicationName
forall a. Gen a -> Gen a
hedgehog Gen ApplicationName
UG.genApplicationName

instance Arbitrary CC.Update.SystemTag where
  arbitrary :: Gen SystemTag
arbitrary = Gen SystemTag -> Gen SystemTag
forall a. Gen a -> Gen a
hedgehog Gen SystemTag
UG.genSystemTag

instance Arbitrary CC.Update.InstallerHash where
  arbitrary :: Gen InstallerHash
arbitrary = Gen InstallerHash -> Gen InstallerHash
forall a. Gen a -> Gen a
hedgehog Gen InstallerHash
UG.genInstallerHash

instance Arbitrary CC.Update.ProtocolVersion where
  arbitrary :: Gen ProtocolVersion
arbitrary = Gen ProtocolVersion -> Gen ProtocolVersion
forall a. Gen a -> Gen a
hedgehog Gen ProtocolVersion
UG.genProtocolVersion

instance Arbitrary CC.Update.ProtocolParameters where
  arbitrary :: Gen ProtocolParameters
arbitrary = Gen ProtocolParameters -> Gen ProtocolParameters
forall a. Gen a -> Gen a
hedgehog Gen ProtocolParameters
UG.genProtocolParameters

instance Arbitrary CC.Update.SoftwareVersion where
  arbitrary :: Gen SoftwareVersion
arbitrary = Gen SoftwareVersion -> Gen SoftwareVersion
forall a. Gen a -> Gen a
hedgehog Gen SoftwareVersion
UG.genSoftwareVersion

instance Arbitrary CC.Reg.ProtocolUpdateProposal where
  arbitrary :: Gen ProtocolUpdateProposal
arbitrary = ProtocolVersion -> ProtocolParameters -> ProtocolUpdateProposal
CC.Reg.ProtocolUpdateProposal
    (ProtocolVersion -> ProtocolParameters -> ProtocolUpdateProposal)
-> Gen ProtocolVersion
-> Gen (ProtocolParameters -> ProtocolUpdateProposal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ProtocolVersion
forall a. Arbitrary a => Gen a
arbitrary
    Gen (ProtocolParameters -> ProtocolUpdateProposal)
-> Gen ProtocolParameters -> Gen ProtocolUpdateProposal
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ProtocolParameters
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Reg.SoftwareUpdateProposal where
  arbitrary :: Gen SoftwareUpdateProposal
arbitrary = SoftwareVersion -> Metadata -> SoftwareUpdateProposal
CC.Reg.SoftwareUpdateProposal
    (SoftwareVersion -> Metadata -> SoftwareUpdateProposal)
-> Gen SoftwareVersion -> Gen (Metadata -> SoftwareUpdateProposal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SoftwareVersion
forall a. Arbitrary a => Gen a
arbitrary
    Gen (Metadata -> SoftwareUpdateProposal)
-> Gen Metadata -> Gen SoftwareUpdateProposal
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Metadata
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Reg.ApplicationVersion where
  arbitrary :: Gen ApplicationVersion
arbitrary = Word32 -> SlotNumber -> Metadata -> ApplicationVersion
CC.Reg.ApplicationVersion
    (Word32 -> SlotNumber -> Metadata -> ApplicationVersion)
-> Gen Word32 -> Gen (SlotNumber -> Metadata -> ApplicationVersion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word32
forall a. Arbitrary a => Gen a
arbitrary
    Gen (SlotNumber -> Metadata -> ApplicationVersion)
-> Gen SlotNumber -> Gen (Metadata -> ApplicationVersion)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen SlotNumber
forall a. Arbitrary a => Gen a
arbitrary
    Gen (Metadata -> ApplicationVersion)
-> Gen Metadata -> Gen ApplicationVersion
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Metadata
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.UPI.State where
  arbitrary :: Gen State
arbitrary = EpochNumber
-> ProtocolVersion
-> ProtocolParameters
-> [CandidateProtocolUpdate]
-> ApplicationVersions
-> ProtocolUpdateProposals
-> SoftwareUpdateProposals
-> Map UpId SlotNumber
-> Map UpId (Set KeyHash)
-> Set Endorsement
-> Map UpId SlotNumber
-> State
CC.UPI.State
    (EpochNumber
 -> ProtocolVersion
 -> ProtocolParameters
 -> [CandidateProtocolUpdate]
 -> ApplicationVersions
 -> ProtocolUpdateProposals
 -> SoftwareUpdateProposals
 -> Map UpId SlotNumber
 -> Map UpId (Set KeyHash)
 -> Set Endorsement
 -> Map UpId SlotNumber
 -> State)
-> Gen EpochNumber
-> Gen
     (ProtocolVersion
      -> ProtocolParameters
      -> [CandidateProtocolUpdate]
      -> ApplicationVersions
      -> ProtocolUpdateProposals
      -> SoftwareUpdateProposals
      -> Map UpId SlotNumber
      -> Map UpId (Set KeyHash)
      -> Set Endorsement
      -> Map UpId SlotNumber
      -> State)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen EpochNumber
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (ProtocolVersion
   -> ProtocolParameters
   -> [CandidateProtocolUpdate]
   -> ApplicationVersions
   -> ProtocolUpdateProposals
   -> SoftwareUpdateProposals
   -> Map UpId SlotNumber
   -> Map UpId (Set KeyHash)
   -> Set Endorsement
   -> Map UpId SlotNumber
   -> State)
-> Gen ProtocolVersion
-> Gen
     (ProtocolParameters
      -> [CandidateProtocolUpdate]
      -> ApplicationVersions
      -> ProtocolUpdateProposals
      -> SoftwareUpdateProposals
      -> Map UpId SlotNumber
      -> Map UpId (Set KeyHash)
      -> Set Endorsement
      -> Map UpId SlotNumber
      -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ProtocolVersion
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (ProtocolParameters
   -> [CandidateProtocolUpdate]
   -> ApplicationVersions
   -> ProtocolUpdateProposals
   -> SoftwareUpdateProposals
   -> Map UpId SlotNumber
   -> Map UpId (Set KeyHash)
   -> Set Endorsement
   -> Map UpId SlotNumber
   -> State)
-> Gen ProtocolParameters
-> Gen
     ([CandidateProtocolUpdate]
      -> ApplicationVersions
      -> ProtocolUpdateProposals
      -> SoftwareUpdateProposals
      -> Map UpId SlotNumber
      -> Map UpId (Set KeyHash)
      -> Set Endorsement
      -> Map UpId SlotNumber
      -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ProtocolParameters
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  ([CandidateProtocolUpdate]
   -> ApplicationVersions
   -> ProtocolUpdateProposals
   -> SoftwareUpdateProposals
   -> Map UpId SlotNumber
   -> Map UpId (Set KeyHash)
   -> Set Endorsement
   -> Map UpId SlotNumber
   -> State)
-> Gen [CandidateProtocolUpdate]
-> Gen
     (ApplicationVersions
      -> ProtocolUpdateProposals
      -> SoftwareUpdateProposals
      -> Map UpId SlotNumber
      -> Map UpId (Set KeyHash)
      -> Set Endorsement
      -> Map UpId SlotNumber
      -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [CandidateProtocolUpdate] -> Gen [CandidateProtocolUpdate]
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [CandidateProtocolUpdate]
forall a. Monoid a => a
mempty -- TODO CandidateProtocolUpdate's constructor is not exported
    Gen
  (ApplicationVersions
   -> ProtocolUpdateProposals
   -> SoftwareUpdateProposals
   -> Map UpId SlotNumber
   -> Map UpId (Set KeyHash)
   -> Set Endorsement
   -> Map UpId SlotNumber
   -> State)
-> Gen ApplicationVersions
-> Gen
     (ProtocolUpdateProposals
      -> SoftwareUpdateProposals
      -> Map UpId SlotNumber
      -> Map UpId (Set KeyHash)
      -> Set Endorsement
      -> Map UpId SlotNumber
      -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ApplicationVersions
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (ProtocolUpdateProposals
   -> SoftwareUpdateProposals
   -> Map UpId SlotNumber
   -> Map UpId (Set KeyHash)
   -> Set Endorsement
   -> Map UpId SlotNumber
   -> State)
-> Gen ProtocolUpdateProposals
-> Gen
     (SoftwareUpdateProposals
      -> Map UpId SlotNumber
      -> Map UpId (Set KeyHash)
      -> Set Endorsement
      -> Map UpId SlotNumber
      -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ProtocolUpdateProposals
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (SoftwareUpdateProposals
   -> Map UpId SlotNumber
   -> Map UpId (Set KeyHash)
   -> Set Endorsement
   -> Map UpId SlotNumber
   -> State)
-> Gen SoftwareUpdateProposals
-> Gen
     (Map UpId SlotNumber
      -> Map UpId (Set KeyHash)
      -> Set Endorsement
      -> Map UpId SlotNumber
      -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen SoftwareUpdateProposals
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (Map UpId SlotNumber
   -> Map UpId (Set KeyHash)
   -> Set Endorsement
   -> Map UpId SlotNumber
   -> State)
-> Gen (Map UpId SlotNumber)
-> Gen
     (Map UpId (Set KeyHash)
      -> Set Endorsement -> Map UpId SlotNumber -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Map UpId SlotNumber)
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (Map UpId (Set KeyHash)
   -> Set Endorsement -> Map UpId SlotNumber -> State)
-> Gen (Map UpId (Set KeyHash))
-> Gen (Set Endorsement -> Map UpId SlotNumber -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Map UpId (Set KeyHash))
forall a. Arbitrary a => Gen a
arbitrary
    Gen (Set Endorsement -> Map UpId SlotNumber -> State)
-> Gen (Set Endorsement) -> Gen (Map UpId SlotNumber -> State)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Set Endorsement -> Gen (Set Endorsement)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Set Endorsement
forall a. Monoid a => a
mempty -- TODO Endorsement is not exported
    Gen (Map UpId SlotNumber -> State)
-> Gen (Map UpId SlotNumber) -> Gen State
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Map UpId SlotNumber)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Genesis.GenesisHash where
  arbitrary :: Gen GenesisHash
arbitrary = Hash Raw -> GenesisHash
CC.Genesis.GenesisHash (Hash Raw -> GenesisHash) -> Gen (Hash Raw) -> Gen GenesisHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Hash Raw)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.UTxO.UTxO where
  arbitrary :: Gen UTxO
arbitrary = [Gen UTxO] -> Gen UTxO
forall a. HasCallStack => [Gen a] -> Gen a
oneof [
      Gen UTxO -> Gen UTxO
forall a. Gen a -> Gen a
hedgehog Gen UTxO
CC.genUTxO
      -- We would sometimes like to run tests using a smaller (or even empty)
      -- UTxO, but 'genUTxO' generates a UTxO without depending on the QC size
      -- parameter. The probability of generating smaller (or empty) UTxOs is
      -- therefore low.
    , [(TxIn, TxOut)] -> UTxO
CC.UTxO.fromList ([(TxIn, TxOut)] -> UTxO) -> Gen [(TxIn, TxOut)] -> Gen UTxO
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        Gen (TxIn, TxOut) -> Gen [(TxIn, TxOut)]
forall a. Gen a -> Gen [a]
listOf ((,) (TxIn -> TxOut -> (TxIn, TxOut))
-> Gen TxIn -> Gen (TxOut -> (TxIn, TxOut))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen TxIn -> Gen TxIn
forall a. Gen a -> Gen a
hedgehog Gen TxIn
CC.genTxIn Gen (TxOut -> (TxIn, TxOut)) -> Gen TxOut -> Gen (TxIn, TxOut)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen TxOut -> Gen TxOut
forall a. Gen a -> Gen a
hedgehog Gen TxOut
CC.genTxOut)
    ]

instance Arbitrary CC.Act.State where
  arbitrary :: Gen State
arbitrary = Map -> Map KeyHash SlotNumber -> State
CC.Act.State
    (Map -> Map KeyHash SlotNumber -> State)
-> Gen Map -> Gen (Map KeyHash SlotNumber -> State)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Map
forall a. Arbitrary a => Gen a
arbitrary
    Gen (Map KeyHash SlotNumber -> State)
-> Gen (Map KeyHash SlotNumber) -> Gen State
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Map KeyHash SlotNumber)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Sched.ScheduledDelegation where
  arbitrary :: Gen ScheduledDelegation
arbitrary = SlotNumber -> KeyHash -> KeyHash -> ScheduledDelegation
CC.Sched.ScheduledDelegation
    (SlotNumber -> KeyHash -> KeyHash -> ScheduledDelegation)
-> Gen SlotNumber
-> Gen (KeyHash -> KeyHash -> ScheduledDelegation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SlotNumber
forall a. Arbitrary a => Gen a
arbitrary
    Gen (KeyHash -> KeyHash -> ScheduledDelegation)
-> Gen KeyHash -> Gen (KeyHash -> ScheduledDelegation)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen KeyHash
forall a. Arbitrary a => Gen a
arbitrary
    Gen (KeyHash -> ScheduledDelegation)
-> Gen KeyHash -> Gen ScheduledDelegation
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen KeyHash
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary CC.Sched.State where
  arbitrary :: Gen State
arbitrary = Seq ScheduledDelegation -> Set (EpochNumber, KeyHash) -> State
CC.Sched.State
    (Seq ScheduledDelegation -> Set (EpochNumber, KeyHash) -> State)
-> Gen (Seq ScheduledDelegation)
-> Gen (Set (EpochNumber, KeyHash) -> State)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Seq ScheduledDelegation)
forall a. Arbitrary a => Gen a
arbitrary
    Gen (Set (EpochNumber, KeyHash) -> State)
-> Gen (Set (EpochNumber, KeyHash)) -> Gen State
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Set (EpochNumber, KeyHash))
forall a. Arbitrary a => Gen a
arbitrary

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

instance Arbitrary CC.Block.ChainValidationState where
  arbitrary :: Gen ChainValidationState
arbitrary = SlotNumber
-> Either GenesisHash HeaderHash
-> UTxO
-> State
-> State
-> ChainValidationState
CC.Block.ChainValidationState
    (SlotNumber
 -> Either GenesisHash HeaderHash
 -> UTxO
 -> State
 -> State
 -> ChainValidationState)
-> Gen SlotNumber
-> Gen
     (Either GenesisHash HeaderHash
      -> UTxO -> State -> State -> ChainValidationState)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen SlotNumber
forall a. Arbitrary a => Gen a
arbitrary
    Gen
  (Either GenesisHash HeaderHash
   -> UTxO -> State -> State -> ChainValidationState)
-> Gen (Either GenesisHash HeaderHash)
-> Gen (UTxO -> State -> State -> ChainValidationState)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Either GenesisHash HeaderHash)
forall a. Arbitrary a => Gen a
arbitrary
    Gen (UTxO -> State -> State -> ChainValidationState)
-> Gen UTxO -> Gen (State -> State -> ChainValidationState)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UTxO
forall a. Arbitrary a => Gen a
arbitrary
    Gen (State -> State -> ChainValidationState)
-> Gen State -> Gen (State -> ChainValidationState)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen State
forall a. Arbitrary a => Gen a
arbitrary
    Gen (State -> ChainValidationState)
-> Gen State -> Gen ChainValidationState
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen State
forall a. Arbitrary a => Gen a
arbitrary

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

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

instance Arbitrary CC.Del.Map where
  arbitrary :: Gen Map
arbitrary = [(KeyHash, KeyHash)] -> Map
CC.Del.fromList ([(KeyHash, KeyHash)] -> Map)
-> Gen [(KeyHash, KeyHash)] -> Gen Map
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [(KeyHash, KeyHash)]
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary ByronTransition where
  arbitrary :: Gen ByronTransition
arbitrary = Map ProtocolVersion BlockNo -> ByronTransition
ByronTransitionInfo (Map ProtocolVersion BlockNo -> ByronTransition)
-> ([(ProtocolVersion, BlockNo)] -> Map ProtocolVersion BlockNo)
-> [(ProtocolVersion, BlockNo)]
-> ByronTransition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ProtocolVersion, BlockNo)] -> Map ProtocolVersion BlockNo
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(ProtocolVersion, BlockNo)] -> ByronTransition)
-> Gen [(ProtocolVersion, BlockNo)] -> Gen ByronTransition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [(ProtocolVersion, BlockNo)]
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary (LedgerState ByronBlock mk) where
  arbitrary :: Gen (LedgerState ByronBlock mk)
arbitrary = WithOrigin BlockNo
-> ChainValidationState
-> ByronTransition
-> LedgerState ByronBlock mk
forall (mk :: MapKind).
WithOrigin BlockNo
-> ChainValidationState
-> ByronTransition
-> LedgerState ByronBlock mk
ByronLedgerState (WithOrigin BlockNo
 -> ChainValidationState
 -> ByronTransition
 -> LedgerState ByronBlock mk)
-> Gen (WithOrigin BlockNo)
-> Gen
     (ChainValidationState
      -> ByronTransition -> LedgerState ByronBlock mk)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (WithOrigin BlockNo)
forall a. Arbitrary a => Gen a
arbitrary Gen
  (ChainValidationState
   -> ByronTransition -> LedgerState ByronBlock mk)
-> Gen ChainValidationState
-> Gen (ByronTransition -> LedgerState ByronBlock mk)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ChainValidationState
forall a. Arbitrary a => Gen a
arbitrary Gen (ByronTransition -> LedgerState ByronBlock mk)
-> Gen ByronTransition -> Gen (LedgerState ByronBlock mk)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ByronTransition
forall a. Arbitrary a => Gen a
arbitrary

-- | Generator for a Byron ledger state in which the tip of the ledger given by
-- `byronLedgerTipBlockNo` is consistent with the chain validation state, i.e., if there is no
-- previous block, the ledger tip wil be `Origin`.
genByronLedgerState :: Gen (LedgerState ByronBlock EmptyMK)
genByronLedgerState :: Gen (LedgerState ByronBlock EmptyMK)
genByronLedgerState = do
  chainValidationState <- Gen ChainValidationState
forall a. Arbitrary a => Gen a
arbitrary
  ledgerTransition <- arbitrary
  ledgerTipBlockNo <- genLedgerTipBlockNo chainValidationState
  pure $ ByronLedgerState {
      byronLedgerTipBlockNo = ledgerTipBlockNo
    , byronLedgerState      = chainValidationState
    , byronLedgerTransition = ledgerTransition
    }
  where
    genLedgerTipBlockNo :: ChainValidationState -> Gen (WithOrigin t)
genLedgerTipBlockNo ChainValidationState { Either GenesisHash HeaderHash
cvsPreviousHash :: ChainValidationState -> Either GenesisHash HeaderHash
cvsPreviousHash :: Either GenesisHash HeaderHash
cvsPreviousHash } =
      case Either GenesisHash HeaderHash
cvsPreviousHash of
        Left GenesisHash
_  -> WithOrigin t -> Gen (WithOrigin t)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure WithOrigin t
forall t. WithOrigin t
Origin
        Right HeaderHash
_ -> t -> WithOrigin t
forall t. t -> WithOrigin t
NotOrigin (t -> WithOrigin t) -> Gen t -> Gen (WithOrigin t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen t
forall a. Arbitrary a => Gen a
arbitrary

instance ZeroableMK mk => Arbitrary (LedgerTables (LedgerState ByronBlock) mk) where
  arbitrary :: Gen (LedgerTables (LedgerState ByronBlock) mk)
arbitrary = LedgerTables (LedgerState ByronBlock) mk
-> Gen (LedgerTables (LedgerState ByronBlock) mk)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LedgerTables (LedgerState ByronBlock) mk
forall (mk :: MapKind) (l :: LedgerStateKind).
(ZeroableMK mk, LedgerTableConstraints l) =>
LedgerTables l mk
emptyLedgerTables

genByronLedgerConfig :: Gen Byron.Config
genByronLedgerConfig :: Gen Config
genByronLedgerConfig = Gen Config -> Gen Config
forall a. Gen a -> Gen a
hedgehog (Gen Config -> Gen Config) -> Gen Config -> Gen Config
forall a b. (a -> b) -> a -> b
$ ProtocolMagicId -> Gen Config
CC.genConfig ProtocolMagicId
protocolMagicId

instance Arbitrary (TipInfoIsEBB ByronBlock) where
  arbitrary :: Gen (TipInfoIsEBB ByronBlock)
arbitrary = HeaderHash ByronBlock -> IsEBB -> TipInfoIsEBB ByronBlock
ByronHash -> IsEBB -> TipInfoIsEBB ByronBlock
forall blk. HeaderHash blk -> IsEBB -> TipInfoIsEBB blk
TipInfoIsEBB (ByronHash -> IsEBB -> TipInfoIsEBB ByronBlock)
-> Gen ByronHash -> Gen (IsEBB -> TipInfoIsEBB ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ByronHash
forall a. Arbitrary a => Gen a
arbitrary Gen (IsEBB -> TipInfoIsEBB ByronBlock)
-> Gen IsEBB -> Gen (TipInfoIsEBB ByronBlock)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [IsEBB] -> Gen IsEBB
forall a. HasCallStack => [a] -> Gen a
elements [IsEBB
IsEBB, IsEBB
IsNotEBB]

instance Arbitrary (AnnTip ByronBlock) where
  arbitrary :: Gen (AnnTip ByronBlock)
arbitrary = SlotNo -> BlockNo -> TipInfoIsEBB ByronBlock -> AnnTip ByronBlock
SlotNo -> BlockNo -> TipInfo ByronBlock -> AnnTip ByronBlock
forall blk. SlotNo -> BlockNo -> TipInfo blk -> AnnTip blk
AnnTip
    (SlotNo -> BlockNo -> TipInfoIsEBB ByronBlock -> AnnTip ByronBlock)
-> Gen SlotNo
-> Gen (BlockNo -> TipInfoIsEBB ByronBlock -> AnnTip ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Word64 -> SlotNo
SlotNo  (Word64 -> SlotNo) -> Gen Word64 -> Gen SlotNo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary)
    Gen (BlockNo -> TipInfoIsEBB ByronBlock -> AnnTip ByronBlock)
-> Gen BlockNo
-> Gen (TipInfoIsEBB ByronBlock -> AnnTip ByronBlock)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Word64 -> BlockNo
BlockNo (Word64 -> BlockNo) -> Gen Word64 -> Gen BlockNo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary)
    Gen (TipInfoIsEBB ByronBlock -> AnnTip ByronBlock)
-> Gen (TipInfoIsEBB ByronBlock) -> Gen (AnnTip ByronBlock)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (TipInfoIsEBB ByronBlock)
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary (PBftState PBftByronCrypto) where
  arbitrary :: Gen (PBftState PBftByronCrypto)
arbitrary = do
      slots <- (Word64, Word64) -> Gen Word64
forall a. Random a => (a, a) -> Gen a
choose (Word64
0, Word64
10)
      keys  <- replicateM 3 arbitrary
      let signers = (SlotNo -> KeyHash -> PBftSigner PBftByronCrypto)
-> [SlotNo] -> [KeyHash] -> [PBftSigner PBftByronCrypto]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith SlotNo -> KeyHash -> PBftSigner PBftByronCrypto
SlotNo
-> PBftVerKeyHash PBftByronCrypto -> PBftSigner PBftByronCrypto
forall c. SlotNo -> PBftVerKeyHash c -> PBftSigner c
PBftState.PBftSigner ((Word64 -> SlotNo) -> [Word64] -> [SlotNo]
forall a b. (a -> b) -> [a] -> [b]
map Word64 -> SlotNo
SlotNo [Word64
0..Word64
slots]) ([KeyHash] -> [KeyHash]
forall a. HasCallStack => [a] -> [a]
cycle [KeyHash]
keys)
      return $ PBftState.fromList signers

instance Arbitrary (SomeResult ByronBlock) where
  arbitrary :: Gen (SomeResult ByronBlock)
arbitrary = BlockQuery ByronBlock 'QFNoTables State
-> State -> SomeResult ByronBlock
forall result blk (fp :: QueryFootprint).
(Eq result, Show result, Typeable result) =>
BlockQuery blk fp result -> result -> SomeResult blk
SomeResult BlockQuery ByronBlock 'QFNoTables State
GetUpdateInterfaceState  (State -> SomeResult ByronBlock)
-> Gen State -> Gen (SomeResult ByronBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen State
forall a. Arbitrary a => Gen a
arbitrary

{-------------------------------------------------------------------------------
  Versioned generators for serialisation
-------------------------------------------------------------------------------}

-- | We only have to be careful about headers with ByronNodeToNodeVersion1,
-- where we will have a fake block size hint.
instance Arbitrary (WithVersion ByronNodeToNodeVersion (Header ByronBlock)) where
  arbitrary :: Gen (WithVersion ByronNodeToNodeVersion (Header ByronBlock))
arbitrary = do
    version <- Gen ByronNodeToNodeVersion
forall a. Arbitrary a => Gen a
arbitrary
    hdr     <- arbitrary
    let hdr' = case ByronNodeToNodeVersion
version of
          ByronNodeToNodeVersion
ByronNodeToNodeVersion1 ->
            Header ByronBlock
hdr { byronHeaderBlockSizeHint = fakeByronBlockSizeHint }
          ByronNodeToNodeVersion
ByronNodeToNodeVersion2 ->
            Header ByronBlock
hdr
    return (WithVersion version hdr')

instance Arbitrary (WithVersion ByronNodeToNodeVersion (SomeSecond (NestedCtxt Header) ByronBlock)) where
  arbitrary :: Gen
  (WithVersion
     ByronNodeToNodeVersion (SomeSecond (NestedCtxt Header) ByronBlock))
arbitrary = do
      version <- Gen ByronNodeToNodeVersion
forall a. Arbitrary a => Gen a
arbitrary
      size    <- case version of
                   ByronNodeToNodeVersion
ByronNodeToNodeVersion1 -> SizeInBytes -> Gen SizeInBytes
forall a. a -> Gen a
forall (m :: * -> *) a. Monad m => a -> m a
return SizeInBytes
fakeByronBlockSizeHint
                   ByronNodeToNodeVersion
ByronNodeToNodeVersion2 -> Word32 -> SizeInBytes
SizeInBytes (Word32 -> SizeInBytes) -> Gen Word32 -> Gen SizeInBytes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word32
forall a. Arbitrary a => Gen a
arbitrary
      ctxt    <- elements [
                     SomeSecond . NestedCtxt $ CtxtByronRegular  size
                   , SomeSecond . NestedCtxt $ CtxtByronBoundary size
                   ]
      return (WithVersion version ctxt)