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 19, 2024
1 parent a2225a9 commit 9de3443
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 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`.

- **BREAKING** Hydra scripts changed due to updates in the `plutus` toolchain:
- Overall slight increase in script size.
Expand Down
1 change: 1 addition & 0 deletions hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ test-suite tests
Test.Hydra.Cluster.CardanoCliSpec
Test.Hydra.Cluster.FaucetSpec
Test.Hydra.Cluster.MithrilSpec
Test.Hydra.Cluster.Utils
Test.HydraExplorerSpec
Test.OfflineChainSpec

Expand Down
31 changes: 15 additions & 16 deletions hydra-cluster/test/Test/CardanoNodeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ 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)
import Test.Hydra.Cluster.Utils (forEachKnownNetwork)

spec :: Spec
spec = do
Expand All @@ -38,21 +39,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,6 +48,19 @@ 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 ->
Expand Down
8 changes: 1 addition & 7 deletions hydra-cluster/test/Test/Hydra/Cluster/MithrilSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Test.Hydra.Prelude
import Control.Concurrent.Class.MonadSTM (newTVarIO, readTVarIO)
import Control.Lens ((^?!))
import Data.Aeson.Lens (key, _Number)
import Hydra.Cluster.Fixture (KnownNetwork (..))
import Hydra.Cluster.Mithril (MithrilLog (..), downloadLatestSnapshotTo)
import Test.Hydra.Cluster.Utils (forEachKnownNetwork)
import Hydra.Logging (Envelope (..), Tracer, traceInTVar)
import System.Directory (doesDirectoryExist)
import System.FilePath ((</>))
Expand Down Expand Up @@ -44,9 +44,3 @@ captureTracer namespace = do
traces <- newTVarIO []
let tracer = traceInTVar traces namespace
pure (tracer, readTVarIO traces)

-- | Creates test cases for each 'KnownNetwork'.
forEachKnownNetwork :: String -> (KnownNetwork -> IO ()) -> Spec
forEachKnownNetwork msg action =
forM_ (enumFromTo minBound maxBound) $ \network ->
it (msg <> " (" <> show network <> ")") $ action network
12 changes: 12 additions & 0 deletions hydra-cluster/test/Test/Hydra/Cluster/Utils.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Test.Hydra.Cluster.Utils where

import Hydra.Prelude
import Test.Hydra.Prelude

import Hydra.Cluster.Fixture (KnownNetwork (..))

-- | Creates test cases for each 'KnownNetwork'.
forEachKnownNetwork :: String -> (KnownNetwork -> IO ()) -> Spec
forEachKnownNetwork msg action =
forM_ (enumFromTo minBound maxBound) $ \network ->
it (msg <> " (" <> show network <> ")") $ action network

0 comments on commit 9de3443

Please sign in to comment.