@@ -53,6 +53,10 @@ module Cardano.Ledger.Core (
53
53
RewardType (.. ),
54
54
Reward (.. ),
55
55
56
+ -- * Test utils
57
+ unsafeBoundRational ,
58
+ testGlobals ,
59
+
56
60
-- * Re-exports
57
61
module Cardano.Ledger.Hashes ,
58
62
module Cardano.Ledger.Core.TxCert ,
@@ -71,7 +75,16 @@ import Cardano.Ledger.Address (
71
75
decompactAddr ,
72
76
isBootstrapCompactAddr ,
73
77
)
74
- import Cardano.Ledger.BaseTypes (ProtVer (.. ))
78
+ import Cardano.Ledger.BaseTypes (
79
+ BoundedRational ,
80
+ EpochSize (.. ),
81
+ Globals (.. ),
82
+ Network (.. ),
83
+ ProtVer (.. ),
84
+ boundRational ,
85
+ knownNonZeroBounded ,
86
+ mkActiveSlotCoeff ,
87
+ )
75
88
import Cardano.Ledger.Binary (
76
89
DecCBOR ,
77
90
DecShareCBOR (Share ),
@@ -99,6 +112,8 @@ import Cardano.Ledger.Metadata
99
112
import Cardano.Ledger.Rewards (Reward (.. ), RewardType (.. ))
100
113
import Cardano.Ledger.TxIn (TxId (.. ), TxIn (.. ))
101
114
import Cardano.Ledger.Val (Val (.. ), inject )
115
+ import Cardano.Slotting.EpochInfo (fixedEpochInfo )
116
+ import Cardano.Slotting.Time (SystemStart (.. ), mkSlotLength )
102
117
import Control.DeepSeq (NFData )
103
118
import Data.Aeson (ToJSON )
104
119
import qualified Data.ByteString as BS
@@ -108,9 +123,12 @@ import qualified Data.Map.Strict as Map
108
123
import Data.Maybe (fromMaybe , isJust )
109
124
import Data.Maybe.Strict (StrictMaybe , strictMaybe )
110
125
import Data.MemPack
126
+ import Data.Proxy (Proxy (.. ))
111
127
import Data.Sequence.Strict (StrictSeq )
112
128
import Data.Set (Set )
113
129
import qualified Data.Set as Set
130
+ import Data.Time.Clock.POSIX (posixSecondsToUTCTime )
131
+ import Data.Typeable (Typeable , typeRep )
114
132
import Data.Void (Void )
115
133
import Data.Word (Word32 , Word64 )
116
134
import GHC.Stack (HasCallStack )
@@ -633,3 +651,24 @@ txIdTx tx = txIdTxBody (tx ^. bodyTxL)
633
651
634
652
txIdTxBody :: EraTxBody era => TxBody era -> TxId
635
653
txIdTxBody = TxId . hashAnnotated
654
+
655
+ testGlobals :: Globals
656
+ testGlobals =
657
+ Globals
658
+ { epochInfo = fixedEpochInfo (EpochSize 100 ) (mkSlotLength 1 )
659
+ , slotsPerKESPeriod = 20
660
+ , stabilityWindow = 33
661
+ , randomnessStabilisationWindow = 33
662
+ , securityParameter = knownNonZeroBounded @ 10
663
+ , maxKESEvo = 10
664
+ , quorum = 5
665
+ , maxLovelaceSupply = 45 * 1000 * 1000 * 1000 * 1000 * 1000
666
+ , activeSlotCoeff = mkActiveSlotCoeff . unsafeBoundRational $ 0.9
667
+ , networkId = Testnet
668
+ , systemStart = SystemStart $ posixSecondsToUTCTime 0
669
+ }
670
+
671
+ unsafeBoundRational :: forall r . (HasCallStack , Typeable r , BoundedRational r ) => Rational -> r
672
+ unsafeBoundRational x = fromMaybe (error errMessage) $ boundRational x
673
+ where
674
+ errMessage = show (typeRep (Proxy :: Proxy r )) <> " is out of bounds: " <> show x
0 commit comments