@@ -9,6 +9,7 @@ import Hydra.Prelude hiding (toList)
9
9
import Cardano.Api.UTxO qualified as UTxO
10
10
import Cardano.Crypto.DSIGN qualified as CC
11
11
import Cardano.Crypto.Hash (hashToBytes )
12
+ import Cardano.Ledger.Api (ensureMinCoinTxOut )
12
13
import Cardano.Ledger.BaseTypes qualified as Ledger
13
14
import Cardano.Ledger.Credential qualified as Ledger
14
15
import Cardano.Ledger.Mary.Value (MaryValue (.. ))
@@ -27,6 +28,7 @@ import Hydra.Tx.Crypto (Hash (..))
27
28
import Hydra.Tx.Party (Party (.. ))
28
29
import PlutusTx.Builtins (fromBuiltin )
29
30
import Test.Cardano.Ledger.Conway.Arbitrary ()
31
+ import Test.Hydra.Tx.Fixture (pparams )
30
32
import Test.Hydra.Tx.Fixture qualified as Fixtures
31
33
import Test.QuickCheck (listOf , oneof , scale , shrinkList , shrinkMapBy , sized , suchThat , vector , vectorOf )
32
34
@@ -46,7 +48,8 @@ instance Arbitrary (TxOut CtxUTxO) where
46
48
genTxOut :: Gen (TxOut ctx )
47
49
genTxOut =
48
50
(gen `suchThat` notByronAddress)
49
- <&> ensureSomeAda . realisticAda . noRefScripts . noStakeRefPtr
51
+ >>= realisticAda
52
+ <&> ensureSomeAda . noRefScripts . noStakeRefPtr
50
53
where
51
54
gen =
52
55
oneof
@@ -61,18 +64,17 @@ genTxOut =
61
64
ByronAddressInEra {} -> False
62
65
_ -> True
63
66
64
- realisticAda =
65
- -- 45 billion is max supply
66
- let oneBillionAda = Coin 1_000_000_000_000_000
67
- in modifyTxOutValue $ \ v ->
67
+ realisticAda o = sized $ \ n -> do
68
+ let maxSupply = 45_000_000_000_000_000
69
+ realistic = Coin $ maxSupply `div` fromIntegral ( max n 1 )
70
+ makeRealistic v =
68
71
let MaryValue c ma = toLedgerValue v
69
- in fromLedgerValue (MaryValue (min c oneBillionAda) ma)
72
+ in fromLedgerValue (MaryValue (min c realistic) ma)
73
+ pure $
74
+ modifyTxOutValue makeRealistic o
70
75
71
- ensureSomeAda = modifyTxOutValue $ \ v ->
72
- let minLovelace = Coin 2_000_000
73
- in if selectLovelace v > minLovelace
74
- then v
75
- else v <> lovelaceToValue minLovelace
76
+ ensureSomeAda =
77
+ fromLedgerTxOut . ensureMinCoinTxOut pparams . toLedgerTxOut
76
78
77
79
noStakeRefPtr out@ (TxOut addr val dat refScript) = case addr of
78
80
ShelleyAddressInEra (ShelleyAddress _ cre sr) ->
0 commit comments