Skip to content

Commit

Permalink
Add and use Read.mockRawHeaderHash
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed Apr 18, 2024
1 parent 30c3d00 commit 116d32b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
7 changes: 1 addition & 6 deletions lib/benchmarks/exe/api-bench.hs
Expand Up @@ -144,9 +144,6 @@ import Data.Aeson
, genericToJSON
, (.=)
)
import Data.Maybe
( fromJust
)
import Data.Quantity
( Quantity (..)
)
Expand Down Expand Up @@ -183,10 +180,8 @@ import qualified Cardano.Wallet.DB.Layer as DB
import qualified Cardano.Wallet.DB.Layer as Sqlite
import qualified Cardano.Wallet.Primitive.Types.UTxOStatistics as UTxOStatistics
import qualified Cardano.Wallet.Read as Read
import qualified Cardano.Wallet.Read.Hash as Hash
import qualified Cardano.Wallet.Transaction as Tx
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Char8 as B8
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import qualified Internal.Cardano.Write.Tx as Write
Expand Down Expand Up @@ -554,7 +549,7 @@ mockNetworkLayer = dummyNetworkLayer
}

mockHash :: Read.RawHeaderHash
mockHash = fromJust $ Hash.hashFromBytes (B8.replicate 32 'a')
mockHash = Read.mockRawHeaderHash 0

mockTimeInterpreter :: TimeInterpreter IO
mockTimeInterpreter = dummyTimeInterpreter
Expand Down
1 change: 1 addition & 0 deletions lib/read/lib/Cardano/Wallet/Read/Block.hs
Expand Up @@ -33,6 +33,7 @@ import Cardano.Wallet.Read.Block.HeaderHash
, getEraHeaderHash
, getEraPrevHeaderHash
, getRawHeaderHash
, mockRawHeaderHash
)
import Cardano.Wallet.Read.Block.SlotNo
( SlotNo (..)
Expand Down
10 changes: 10 additions & 0 deletions lib/read/lib/Cardano/Wallet/Read/Block/HeaderHash.hs
Expand Up @@ -16,6 +16,9 @@ module Cardano.Wallet.Read.Block.HeaderHash
, PrevHeaderHash (..)
, PrevHeaderHashT
, getEraPrevHeaderHash

-- * Testing utilities
, mockRawHeaderHash
)
where

Expand Down Expand Up @@ -81,6 +84,8 @@ import Ouroboros.Consensus.Shelley.Protocol.TPraos
import qualified Cardano.Crypto.Hashing as Byron
import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.Shelley.API as Shelley
import qualified Cardano.Wallet.Read.Hash as Hash
import qualified Data.ByteString.Char8 as B8
import qualified Ouroboros.Consensus.Shelley.Ledger.Block as O
import qualified Ouroboros.Consensus.Shelley.Protocol.Abstract as Shelley
import qualified Ouroboros.Network.Block as O
Expand Down Expand Up @@ -131,6 +136,11 @@ data BHeader
-- | Raw hash digest for a block header.
type RawHeaderHash = Hash Blake2b_256 BHeader

-- | Construct a 'RawHeaderHash' that is good enough for testing.
mockRawHeaderHash :: Integer -> RawHeaderHash
mockRawHeaderHash n =
Hash.hashWith (\_ -> B8.pack $ show n) (error "undefined :: BHeader")

{-# INLINABLE getRawHeaderHash #-}
getRawHeaderHash :: forall era. IsEra era => HeaderHash era -> RawHeaderHash
getRawHeaderHash = case theEra @era of
Expand Down
6 changes: 2 additions & 4 deletions lib/unit/test/unit/Cardano/Wallet/Api/ServerSpec.hs
Expand Up @@ -74,8 +74,7 @@ import Data.Either
( isLeft
)
import Data.Maybe
( fromJust
, isJust
( isJust
, isNothing
)
import Data.SOP.Counting
Expand Down Expand Up @@ -143,7 +142,6 @@ import UnliftIO.Concurrent

import qualified Cardano.Wallet.Primitive.SyncProgress as S
import qualified Cardano.Wallet.Read as Read
import qualified Cardano.Wallet.Read.Hash as Hash
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy as BL
import qualified Ouroboros.Consensus.HardFork.History.EraParams as HF
Expand Down Expand Up @@ -278,7 +276,7 @@ networkInfoSpec = describe "getNetworkInformation" $ do
}
where
mockHash :: Read.RawHeaderHash
mockHash = fromJust $ Hash.hashFromBytes $ B8.replicate 32 'a'
mockHash = Read.mockRawHeaderHash 0

forkInterpreter startTime =
let
Expand Down

0 comments on commit 116d32b

Please sign in to comment.