From 18d26a27102ea75c032525e16054d0be8d72d881 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Mon, 18 Mar 2024 10:27:33 +0000 Subject: [PATCH] Test hydra-cluster synchronisation on all networks --- CHANGELOG.md | 2 +- hydra-cluster/test/Test/CardanoNodeSpec.hs | 35 ++++++++++++---------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11cd153125b..aed9f962652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/hydra-cluster/test/Test/CardanoNodeSpec.hs b/hydra-cluster/test/Test/CardanoNodeSpec.hs index 49d4f25f454..5cdad5afe5f 100644 --- a/hydra-cluster/test/Test/CardanoNodeSpec.hs +++ b/hydra-cluster/test/Test/CardanoNodeSpec.hs @@ -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) @@ -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 @@ -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