Skip to content

Commit

Permalink
Add Read.mockGenesisDataMainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed Oct 7, 2024
1 parent 99606f7 commit 6b485dc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/customer-deposit-wallet/customer-deposit-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ library
, mtl
, OddWord
, text
, time

reexported-modules: Cardano.Wallet.Address.BIP32
exposed-modules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ findTheDepositWalletOnDisk dir action = do
fromXPubAndGenesis
identity
(fromIntegral @Int users)
(error "FIXME")
Read.mockGenesisDataMainnet
store <- newStore
writeS store state
action $ Right store
Expand Down
51 changes: 51 additions & 0 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Read.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TypeApplications #-}

-- | Indirection module that re-exports types
-- used for reading data from the blockchain,
Expand Down Expand Up @@ -49,6 +51,7 @@ module Cardano.Wallet.Deposit.Read

, GenesisData
, GenesisHash
, mockGenesisDataMainnet

-- * Dummy Values useful for testing
, dummyAddress
Expand Down Expand Up @@ -79,11 +82,17 @@ import Data.Map
import Data.Maybe
( fromJust
)
import Data.Time.Clock
( UTCTime (..)
)
import Data.Word
( Word8
)

import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Chain.Genesis as Byron
import qualified Cardano.Chain.Slotting as Byron
import qualified Cardano.Chain.Update as Byron
import qualified Cardano.Wallet.Read as Read
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as B8
Expand Down Expand Up @@ -151,3 +160,45 @@ mockNextBlock old txs =
-- GenesisData is not part of the ledger specification proper
type GenesisData = Byron.GenesisData
type GenesisHash = Byron.GenesisHash

mockGenesisDataMainnet :: GenesisData
mockGenesisDataMainnet = Byron.GenesisData
{ Byron.gdGenesisKeyHashes = mempty
, Byron.gdHeavyDelegation = Byron.UnsafeGenesisDelegation mempty
, Byron.gdStartTime = UTCTime (toEnum 0) 0
, Byron.gdNonAvvmBalances = mempty
, Byron.gdProtocolParameters = protocolParametersMainnet
, gdK = toEnum 2160
, gdProtocolMagicId = Byron.mainnetProtocolMagicId
, Byron.gdAvvmDistr = Byron.GenesisAvvmBalances mempty
}

protocolParametersMainnet :: Byron.ProtocolParameters
protocolParametersMainnet = Byron.ProtocolParameters
{ ppHeavyDelThd = mkLovelacePortionFromGenesisJSON 300000000000
, ppMaxBlockSize = 2000000
, ppMaxHeaderSize = 2000000
, ppMaxProposalSize = 700
, ppMaxTxSize = 4096
, ppMpcThd = mkLovelacePortionFromGenesisJSON 20000000000000
, ppScriptVersion = 0
, ppSlotDuration = 20000
, ppSoftforkRule = Byron.SoftforkRule
{ srInitThd = mkLovelacePortionFromGenesisJSON 900000000000000
, srMinThd = mkLovelacePortionFromGenesisJSON 600000000000000
, srThdDecrement = mkLovelacePortionFromGenesisJSON 50000000000000
}
, ppTxFeePolicy = Byron.TxFeePolicyTxSizeLinear
$ Byron.TxSizeLinear
(Byron.mkKnownLovelace @155381000000000) -- don't ask
43946000000
,ppUnlockStakeEpoch = Byron.EpochNumber 18446744073709551615
, ppUpdateProposalThd = mkLovelacePortionFromGenesisJSON 100000000000000
, ppUpdateVoteThd = mkLovelacePortionFromGenesisJSON 1000000000000
, ppUpdateProposalTTL = 1000 -- "updateImplicit" in JSON representation
}

-- Make a 'LovelacePortion' from the numerical value in the genesis JSON file.
mkLovelacePortionFromGenesisJSON :: Rational -> Byron.LovelacePortion
mkLovelacePortionFromGenesisJSON n =
Byron.rationalToLovelacePortion (n / 10^(15 :: Integer))
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ withScenarioEnvMock action = do
networkEnv <- mapBlock Read.EraValue <$> newNetworkEnvMock
action
$ ScenarioEnv
{ genesisData = error "TODO: Mock Genesis Data"
{ genesisData = Read.mockGenesisDataMainnet
, networkEnv
, faucet = Faucet{xprv = error "TODO: Faucet xprv"}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ testXPub =
------------------------------------------------------------------------------}

testGenesis :: Read.GenesisData
testGenesis = undefined
testGenesis = Read.mockGenesisDataMainnet

spendOneTxOut :: UTxO.UTxO -> Read.Tx
spendOneTxOut utxo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import qualified Cardano.Wallet.Deposit.Read as Read
import qualified Data.ByteString.Char8 as B8

fakeBootEnv :: WalletBootEnv IO
fakeBootEnv = WalletBootEnv undefined undefined undefined
fakeBootEnv = WalletBootEnv nullTracer Read.mockGenesisDataMainnet undefined

xpub :: XPub
xpub =
Expand Down

0 comments on commit 6b485dc

Please sign in to comment.