File tree 1 file changed +33
-0
lines changed
cardano-api/gen/Test/Gen/Cardano/Api
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,11 @@ module Test.Gen.Cardano.Api.Typed
137
137
, genMintWitnessable
138
138
, genPlutusScriptWitness
139
139
, genIndexedPlutusScriptWitness
140
+
141
+ , genBlockNo
142
+ , genBlockHeader
143
+ , genBlockHeaderAt
144
+ , genBlockHeaderHash
140
145
)
141
146
where
142
147
@@ -1488,3 +1493,31 @@ genScriptWitnessForMint sbe = do
1488
1493
NoScriptDatumForMint
1489
1494
scriptRedeemer
1490
1495
<$> genExecutionUnits
1496
+
1497
+ genBlockNo :: Gen BlockNo
1498
+ genBlockNo = BlockNo <$> Gen. word64 Range. constantBounded
1499
+
1500
+ -- | Fully arbitrary block header with completely random hash.
1501
+ genBlockHeader :: Gen BlockHeader
1502
+ genBlockHeader = genSlotNo >>= genBlockHeaderAt
1503
+
1504
+ -- | Generate a random block header with completely random hash, but at a
1505
+ -- certain slot.
1506
+ genBlockHeaderAt :: SlotNo -> Gen BlockHeader
1507
+ genBlockHeaderAt slotNo = BlockHeader slotNo <$> genBlockHeaderHash <*> genBlockNo
1508
+
1509
+ -- | Generate a random block header hash.
1510
+ -- | This will error if the hash size of block headers changes (currently 32 bytes).
1511
+ genBlockHeaderHash :: Gen (Hash BlockHeader )
1512
+ genBlockHeaderHash =
1513
+ unsafeBlockHeaderHashFromBytes . BS. pack <$> Gen. list (Range. singleton 32 ) Q. arbitrary
1514
+ where
1515
+ unsafeBlockHeaderHashFromBytes bytes =
1516
+ case deserialiseFromRawBytes (proxyToAsType Proxy ) bytes of
1517
+ Left e ->
1518
+ error $
1519
+ " unsafeBlockHeaderHashFromBytes: failed on bytes "
1520
+ <> show bytes
1521
+ <> " with error "
1522
+ <> show e
1523
+ Right h -> h
You can’t perform that action at this time.
0 commit comments