Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ module Test.Gen.Cardano.Api.Typed
, genMintWitnessable
, genPlutusScriptWitness
, genIndexedPlutusScriptWitness
, genBlockNo
, genBlockHeader
, genBlockHeaderAt
, genBlockHeaderHash
)
where

Expand Down Expand Up @@ -1488,3 +1492,31 @@ genScriptWitnessForMint sbe = do
NoScriptDatumForMint
scriptRedeemer
<$> genExecutionUnits

genBlockNo :: Gen BlockNo
genBlockNo = BlockNo <$> Gen.word64 Range.constantBounded

-- | Fully arbitrary block header with completely random hash.
genBlockHeader :: Gen BlockHeader
genBlockHeader = genSlotNo >>= genBlockHeaderAt

-- | Generate a random block header with completely random hash, but at a
-- certain slot.
genBlockHeaderAt :: SlotNo -> Gen BlockHeader
genBlockHeaderAt slotNo = BlockHeader slotNo <$> genBlockHeaderHash <*> genBlockNo

-- | Generate a random block header hash.
-- This will error if the hash size of block headers changes (currently 32 bytes).
genBlockHeaderHash :: Gen (Hash BlockHeader)
genBlockHeaderHash =
unsafeBlockHeaderHashFromBytes . BS.pack <$> Gen.list (Range.singleton 32) Q.arbitrary
where
unsafeBlockHeaderHashFromBytes bytes =
case deserialiseFromRawBytes (proxyToAsType Proxy) bytes of
Left e ->
error $
"unsafeBlockHeaderHashFromBytes: failed on bytes "
<> show bytes
<> " with error "
<> show e
Right h -> h
Loading