Skip to content

Commit

Permalink
Test hydra-cluster synchronisation on all networks
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Mar 18, 2024
1 parent 021ca48 commit d6cd24c
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions hydra-cluster/test/Test/CardanoNodeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CardanoNode (

import CardanoClient (RunningNode (..), queryTipSlotNo)
import Hydra.Cardano.Api (NetworkId (Testnet), NetworkMagic (NetworkMagic), unFile)
import Hydra.Cluster.Fixture (KnownNetwork (..))
import Hydra.Cluster.Fixture (KnownNetwork (..), toNetworkId)
import Hydra.Logging (Tracer, showLogsOnFailure)
import System.Directory (doesFileExist)

Expand All @@ -38,21 +38,6 @@ spec = do
slot2 <- queryTipSlotNo networkId nodeSocket
slot2 `shouldSatisfy` (> slot1)

it "withCardanoNodeOnKnownNetwork on mainnet starts synchronizing within 5 seconds" $ \_ ->
pendingWith "cardano-node 8.8 is not supported on mainnet (config mismatch)"

it "withCardanoNodeOnKnownNetwork on preview starts synchronizing within 5 seconds" $ \(tr, tmp) ->
-- NOTE: This implies that withCardanoNodeOnKnownNetwork does not
-- synchronize the whole chain before continuing.
withCardanoNodeOnKnownNetwork tr tmp Preview $ \RunningNode{nodeSocket, networkId, blockTime} -> do
networkId `shouldBe` Testnet (NetworkMagic 2)
blockTime `shouldBe` 20
-- Should synchronize blocks (tip advances)
slot1 <- queryTipSlotNo networkId nodeSocket
threadDelay 1
slot2 <- queryTipSlotNo networkId nodeSocket
slot2 `shouldSatisfy` (> slot1)

describe "findRunningCardanoNode" $ do
it "returns Nothing on non-matching network" $ \(tr, tmp) -> do
withCardanoNodeOnKnownNetwork tr tmp Sanchonet $ \_ -> do
Expand All @@ -62,8 +47,26 @@ spec = do
withCardanoNodeOnKnownNetwork tr tmp Preview $ \runningNode -> do
findRunningCardanoNode tr tmp Preview `shouldReturn` Just runningNode

forEachKnownNetwork "withCardanoNodeOnKnownNetwork starts synchronizing within 5 seconds" $ \network -> do
-- NOTE: This implies that withCardanoNodeOnKnownNetwork does not
-- synchronize the whole chain before continuing.
setupTracerAndTempDir $ \(tr, tmp) ->
withCardanoNodeOnKnownNetwork tr tmp Preview $ \RunningNode{nodeSocket, networkId, blockTime} -> do
networkId `shouldBe` toNetworkId network
blockTime `shouldBe` 20
-- Should synchronize blocks (tip advances)
slot1 <- queryTipSlotNo networkId nodeSocket
threadDelay 1
slot2 <- queryTipSlotNo networkId nodeSocket
slot2 `shouldSatisfy` (> slot1)

setupTracerAndTempDir :: ToJSON msg => ((Tracer IO msg, FilePath) -> IO a) -> IO a
setupTracerAndTempDir action =
showLogsOnFailure "CardanoNodeSpec" $ \tr ->
withTempDir "hydra-cluster" $ \tmp ->
action (tr, tmp)

forEachKnownNetwork :: String -> (KnownNetwork -> IO ()) -> Spec
forEachKnownNetwork msg action =
forM_ (enumFromTo minBound maxBound) $ \network ->
it (msg <> " (" <> show network <> ")") $ action network

0 comments on commit d6cd24c

Please sign in to comment.