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