-
Notifications
You must be signed in to change notification settings - Fork 210
/
Gen.hs
48 lines (38 loc) · 1.21 KB
/
Gen.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Cardano.Api.Gen
( genTxIn
, genTxId
, genTxIndex
, genShelleyHash
, genTxInsCollateral
, genSlotNo
) where
import Prelude
import Cardano.Api hiding
( txIns )
import Test.QuickCheck
( Gen, Large (..), arbitrary, listOf, oneof )
import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash as Crypto
import qualified Shelley.Spec.Ledger.TxBody as Ledger
( EraIndependentTxBody )
genShelleyHash
:: Gen (Crypto.Hash Crypto.Blake2b_256 Ledger.EraIndependentTxBody)
genShelleyHash = return . Crypto.castHash $ Crypto.hashWith CBOR.serialize' ()
genTxIn :: Gen TxIn
genTxIn = TxIn <$> genTxId <*> genTxIndex
genTxId :: Gen TxId
genTxId = TxId <$> genShelleyHash
genTxIndex :: Gen TxIx
genTxIndex = do
(Large (n :: Word)) <- arbitrary
pure $ TxIx n
genTxInsCollateral :: CardanoEra era -> Gen (TxInsCollateral era)
genTxInsCollateral era =
case collateralSupportedInEra era of
Nothing -> pure TxInsCollateralNone
Just supported -> oneof
[ pure TxInsCollateralNone
, TxInsCollateral supported <$> listOf genTxIn
]
genSlotNo :: Gen SlotNo
genSlotNo = SlotNo <$> arbitrary