{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Chain.Genesis.Dummy (
  dummyConfig,
  dummyK,
  dummyEpochSlots,
  dummySlotSecurityParam,
  dummyGenesisInitializer,
  dummyGenesisAvvmBalances,
  dummyGeneratedSecrets,
  dummyGenesisSigningKeys,
  dummyGenesisSigningKeysRich,
  dummyGenesisSigningKeysPoor,
  dummyGenesisSecretsRich,
  dummyGenesisSecretsPoor,
  dummyGenesisSpec,
  dummyProtocolParameters,
  dummyGenesisData,
  dummyGenesisHash,
)
where

import Cardano.Chain.Common (
  BlockCount (..),
  TxFeePolicy (..),
  TxSizeLinear (..),
  mkKnownLovelace,
  rationalToLovelacePortion,
 )
import Cardano.Chain.Genesis (
  Config (..),
  FakeAvvmOptions (..),
  GeneratedSecrets (..),
  GenesisAvvmBalances (..),
  GenesisData (..),
  GenesisDelegation (..),
  GenesisHash (..),
  GenesisInitializer (..),
  GenesisSpec (..),
  PoorSecret,
  TestnetBalanceOptions (..),
  generateGenesisConfigWithEntropy,
  gsSigningKeys,
  gsSigningKeysPoor,
 )
import Cardano.Chain.ProtocolConstants (kEpochSlots, kSlotSecurityParam)
import Cardano.Chain.Slotting (EpochNumber (..), EpochSlots, SlotCount)
import Cardano.Chain.Update (ProtocolParameters (..), SoftforkRule (..))
import Cardano.Crypto as Crypto (SigningKey, deterministic)
import Cardano.Prelude
import Data.Time (Day (..), UTCTime (..))
import qualified Test.Cardano.Crypto.Dummy as Dummy

dummyConfig :: Config
dummyGeneratedSecrets :: GeneratedSecrets
(Config
dummyConfig, GeneratedSecrets
dummyGeneratedSecrets) =
  forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => Text -> a
panic forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Show a, ConvertText String b) => a -> b
show) forall (cat :: * -> * -> *) a. Category cat => cat a a
identity
    forall a b. (a -> b) -> a -> b
$ forall a. ByteString -> MonadPseudoRandom ChaChaDRG a -> a
Crypto.deterministic ByteString
seed
    forall a b. (a -> b) -> a -> b
$ forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT -- supply fake entropy to make this pure
    forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadRandom m =>
UTCTime
-> GenesisSpec
-> ExceptT GenesisDataGenerationError m (Config, GeneratedSecrets)
generateGenesisConfigWithEntropy UTCTime
startTime GenesisSpec
dummyGenesisSpec
  where
    seed :: ByteString
    seed :: ByteString
seed = ByteString
"\0"
    startTime :: UTCTime
startTime = Day -> DiffTime -> UTCTime
UTCTime (Integer -> Day
ModifiedJulianDay Integer
0) DiffTime
0

dummyK :: BlockCount
dummyK :: BlockCount
dummyK = Word64 -> BlockCount
BlockCount Word64
10

dummyEpochSlots :: EpochSlots
dummyEpochSlots :: EpochSlots
dummyEpochSlots = BlockCount -> EpochSlots
kEpochSlots BlockCount
dummyK

dummySlotSecurityParam :: SlotCount
dummySlotSecurityParam :: SlotCount
dummySlotSecurityParam = BlockCount -> SlotCount
kSlotSecurityParam BlockCount
dummyK

dummyGenesisSecretsRich :: [SigningKey]
dummyGenesisSecretsRich :: [SigningKey]
dummyGenesisSecretsRich = GeneratedSecrets -> [SigningKey]
gsRichSecrets GeneratedSecrets
dummyGeneratedSecrets

dummyGenesisSecretsPoor :: [PoorSecret]
dummyGenesisSecretsPoor :: [PoorSecret]
dummyGenesisSecretsPoor = GeneratedSecrets -> [PoorSecret]
gsPoorSecrets GeneratedSecrets
dummyGeneratedSecrets

dummyGenesisSigningKeys :: [SigningKey]
dummyGenesisSigningKeys :: [SigningKey]
dummyGenesisSigningKeys = GeneratedSecrets -> [SigningKey]
gsSigningKeys GeneratedSecrets
dummyGeneratedSecrets

dummyGenesisSigningKeysRich :: [SigningKey]
dummyGenesisSigningKeysRich :: [SigningKey]
dummyGenesisSigningKeysRich = GeneratedSecrets -> [SigningKey]
gsRichSecrets GeneratedSecrets
dummyGeneratedSecrets

dummyGenesisSigningKeysPoor :: [SigningKey]
dummyGenesisSigningKeysPoor :: [SigningKey]
dummyGenesisSigningKeysPoor = GeneratedSecrets -> [SigningKey]
gsSigningKeysPoor GeneratedSecrets
dummyGeneratedSecrets

dummyGenesisSpec :: GenesisSpec
dummyGenesisSpec :: GenesisSpec
dummyGenesisSpec =
  UnsafeGenesisSpec
    { gsAvvmDistr :: GenesisAvvmBalances
gsAvvmDistr = GenesisAvvmBalances
dummyGenesisAvvmBalances
    , gsHeavyDelegation :: GenesisDelegation
gsHeavyDelegation = Map KeyHash Certificate -> GenesisDelegation
UnsafeGenesisDelegation forall a. Monoid a => a
mempty
    , gsProtocolParameters :: ProtocolParameters
gsProtocolParameters = ProtocolParameters
dummyProtocolParameters
    , gsK :: BlockCount
gsK = BlockCount
dummyK
    , gsProtocolMagic :: ProtocolMagic
gsProtocolMagic = ProtocolMagic
Dummy.protocolMagic
    , gsInitializer :: GenesisInitializer
gsInitializer = GenesisInitializer
dummyGenesisInitializer
    }

dummyGenesisAvvmBalances :: GenesisAvvmBalances
dummyGenesisAvvmBalances :: GenesisAvvmBalances
dummyGenesisAvvmBalances = Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances
GenesisAvvmBalances forall a. Monoid a => a
mempty

dummyProtocolParameters :: ProtocolParameters
dummyProtocolParameters :: ProtocolParameters
dummyProtocolParameters =
  ProtocolParameters
    { ppScriptVersion :: Word16
ppScriptVersion = Word16
0
    , ppSlotDuration :: Nat
ppSlotDuration = Nat
7000
    , ppMaxBlockSize :: Nat
ppMaxBlockSize = Nat
2000000
    , ppMaxHeaderSize :: Nat
ppMaxHeaderSize = Nat
2000000
    , ppMaxTxSize :: Nat
ppMaxTxSize = Nat
8192
    , ppMaxProposalSize :: Nat
ppMaxProposalSize = Nat
700
    , ppMpcThd :: LovelacePortion
ppMpcThd = Rational -> LovelacePortion
rationalToLovelacePortion Rational
0.01
    , ppHeavyDelThd :: LovelacePortion
ppHeavyDelThd = Rational -> LovelacePortion
rationalToLovelacePortion Rational
0.005
    , ppUpdateVoteThd :: LovelacePortion
ppUpdateVoteThd = Rational -> LovelacePortion
rationalToLovelacePortion Rational
0.001
    , ppUpdateProposalThd :: LovelacePortion
ppUpdateProposalThd = Rational -> LovelacePortion
rationalToLovelacePortion Rational
0.1
    , ppUpdateProposalTTL :: SlotNumber
ppUpdateProposalTTL = SlotNumber
10
    , ppSoftforkRule :: SoftforkRule
ppSoftforkRule =
        SoftforkRule
          { srInitThd :: LovelacePortion
srInitThd = Rational -> LovelacePortion
rationalToLovelacePortion Rational
0.9
          , srMinThd :: LovelacePortion
srMinThd = Rational -> LovelacePortion
rationalToLovelacePortion Rational
0.6
          , srThdDecrement :: LovelacePortion
srThdDecrement = Rational -> LovelacePortion
rationalToLovelacePortion Rational
0.05
          }
    , ppTxFeePolicy :: TxFeePolicy
ppTxFeePolicy =
        TxSizeLinear -> TxFeePolicy
TxFeePolicyTxSizeLinear
          (Lovelace -> Rational -> TxSizeLinear
TxSizeLinear (forall (n :: Nat). (KnownNat n, n <= 45000000000000000) => Lovelace
mkKnownLovelace @155381) Rational
43.946)
    , ppUnlockStakeEpoch :: EpochNumber
ppUnlockStakeEpoch = Word64 -> EpochNumber
EpochNumber forall a. Bounded a => a
maxBound
    }

dummyGenesisInitializer :: GenesisInitializer
dummyGenesisInitializer :: GenesisInitializer
dummyGenesisInitializer =
  GenesisInitializer
    { giTestBalance :: TestnetBalanceOptions
giTestBalance =
        TestnetBalanceOptions
          { tboPoors :: Word
tboPoors = Word
12
          , tboRichmen :: Word
tboRichmen = Word
4
          , tboTotalBalance :: Lovelace
tboTotalBalance = forall (n :: Nat). (KnownNat n, n <= 45000000000000000) => Lovelace
mkKnownLovelace @6000000000000000
          , tboRichmenShare :: Rational
tboRichmenShare = Rational
0.99 :: Rational
          }
    , giFakeAvvmBalance :: FakeAvvmOptions
giFakeAvvmBalance =
        FakeAvvmOptions
          { faoCount :: Word
faoCount = Word
10
          , faoOneBalance :: Lovelace
faoOneBalance = forall (n :: Nat). (KnownNat n, n <= 45000000000000000) => Lovelace
mkKnownLovelace @100000
          }
    , giAvvmBalanceFactor :: Rational
giAvvmBalanceFactor = Rational
1.0 :: Rational
    , giUseHeavyDlg :: Bool
giUseHeavyDlg = Bool
True
    }

dummyGenesisData :: GenesisData
dummyGenesisData :: GenesisData
dummyGenesisData = Config -> GenesisData
configGenesisData Config
dummyConfig

dummyGenesisHash :: GenesisHash
dummyGenesisHash :: GenesisHash
dummyGenesisHash = Config -> GenesisHash
configGenesisHash Config
dummyConfig