{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Ledger.Core.Utils (
  unsafeBoundRational,
  testGlobals,
  mkDummySafeHash,
  txInAt,
)
where

import Cardano.Ledger.BaseTypes (
  EpochSize (..),
  Globals (..),
  Network (..),
  mkActiveSlotCoeff,
 )
import Cardano.Ledger.Core
import Cardano.Ledger.Hashes (unsafeMakeSafeHash)
import Cardano.Ledger.TxIn (TxIn, mkTxInPartial)
import Cardano.Slotting.EpochInfo (fixedEpochInfo)
import Cardano.Slotting.Time (SystemStart (..), mkSlotLength)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Test.Cardano.Ledger.Binary.Random (mkDummyHash)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Rational (unsafeBoundRational)

testGlobals :: Globals
testGlobals :: Globals
testGlobals =
  Globals
    { epochInfo :: EpochInfo (Either Text)
epochInfo = forall (m :: * -> *).
Monad m =>
EpochSize -> SlotLength -> EpochInfo m
fixedEpochInfo (Word64 -> EpochSize
EpochSize Word64
100) (NominalDiffTime -> SlotLength
mkSlotLength NominalDiffTime
1)
    , slotsPerKESPeriod :: Word64
slotsPerKESPeriod = Word64
20
    , stabilityWindow :: Word64
stabilityWindow = Word64
33
    , randomnessStabilisationWindow :: Word64
randomnessStabilisationWindow = Word64
33
    , securityParameter :: Word64
securityParameter = Word64
10
    , maxKESEvo :: Word64
maxKESEvo = Word64
10
    , quorum :: Word64
quorum = Word64
5
    , maxLovelaceSupply :: Word64
maxLovelaceSupply = Word64
45 forall a. Num a => a -> a -> a
* Word64
1000 forall a. Num a => a -> a -> a
* Word64
1000 forall a. Num a => a -> a -> a
* Word64
1000 forall a. Num a => a -> a -> a
* Word64
1000 forall a. Num a => a -> a -> a
* Word64
1000
    , activeSlotCoeff :: ActiveSlotCoeff
activeSlotCoeff = PositiveUnitInterval -> ActiveSlotCoeff
mkActiveSlotCoeff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r.
(HasCallStack, Typeable r, BoundedRational r) =>
Rational -> r
unsafeBoundRational forall a b. (a -> b) -> a -> b
$ Rational
0.9
    , networkId :: Network
networkId = Network
Testnet
    , systemStart :: SystemStart
systemStart = UTCTime -> SystemStart
SystemStart forall a b. (a -> b) -> a -> b
$ NominalDiffTime -> UTCTime
posixSecondsToUTCTime NominalDiffTime
0
    }

mkDummySafeHash :: forall a. Int -> SafeHash a
mkDummySafeHash :: forall a. Int -> SafeHash a
mkDummySafeHash = forall i. Hash HASH i -> SafeHash i
unsafeMakeSafeHash forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall h a b. (HashAlgorithm h, EncCBOR a) => a -> Hash h b
mkDummyHash @HASH

txInAt :: (HasCallStack, Integral i, EraTx era) => i -> Tx era -> TxIn
txInAt :: forall i era.
(HasCallStack, Integral i, EraTx era) =>
i -> Tx era -> TxIn
txInAt i
index Tx era
tx =
  let txId :: TxId
txId = forall era. EraTx era => Tx era -> TxId
txIdTx Tx era
tx
   in HasCallStack => TxId -> Integer -> TxIn
mkTxInPartial TxId
txId (forall a. Integral a => a -> Integer
toInteger i
index)