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 3ac2592 commit 18d26a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ changes.

## [0.16.0] - UNRELEASED

- **BREAKING** Update to and tested against `cardano-node 8.9.0` and `cardano-cli 8.20.3.0`. This made smoke tests incompatible with public testnets and mainnet.
- Update to and tested against `cardano-node 8.9.0` and `cardano-cli 8.20.3.0`. This made smoke tests incompatible with public testnets and mainnet.

- **BREAKING** Hydra scripts changed due to updates in the `plutus` toolchain:
- Overall slight increase in script size.
Expand Down
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 10 seconds" $ \network -> do
-- NOTE: This implies that withCardanoNodeOnKnownNetwork does not
-- synchronize the whole chain before continuing.
setupTracerAndTempDir $ \(tr, tmp) ->
withCardanoNodeOnKnownNetwork tr tmp network $ \RunningNode{nodeSocket, networkId, blockTime} -> do
networkId `shouldBe` toNetworkId network
blockTime `shouldBe` 20
-- Should synchronize blocks (tip advances)
slot1 <- queryTipSlotNo networkId nodeSocket
threadDelay 10
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 18d26a2

Please sign in to comment.