Skip to content

Commit

Permalink
Fix hydra-node id to be different than zero for darwin systems
Browse files Browse the repository at this point in the history
Because the port is already taken by default on recent macOS devices.
  • Loading branch information
ffakenz committed Jan 2, 2024
1 parent 76532cd commit a2fa58d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ import Network.HTTP.Req qualified as Req
import Network.WebSockets (Connection, receiveData, runClient, sendClose, sendTextData)
import System.FilePath ((<.>), (</>))
import System.IO.Temp (withSystemTempDirectory)
import System.Info (os)
import System.Process (
CreateProcess (..),
ProcessHandle,
StdStream (..),
proc,
withCreateProcess,
)
import Test.Hydra.Prelude (checkProcessHasNotDied, failAfter, failure, withLogFile)
import Test.Hydra.Prelude (checkProcessHasNotDied, failAfter, failure, shouldNotBe, withLogFile)
import Prelude qualified

data HydraClient = HydraClient
Expand Down Expand Up @@ -304,6 +305,11 @@ withHydraNode' ::
(Handle -> Handle -> ProcessHandle -> IO a) ->
IO a
withHydraNode' chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNodeIds pparams mGivenStdOut action = do
case os of
-- XXX: this is to not bind to port 5000 on darwin systems,
-- as it might already be in use on recent macOS devices.
"darwin" -> hydraNodeId `shouldNotBe` 0
_ -> pure ()
withSystemTempDirectory "hydra-node" $ \dir -> do
let cardanoLedgerProtocolParametersFile = dir </> "pparams.json"
writeFileBS cardanoLedgerProtocolParametersFile (writeZeroedPParams pparams)
Expand Down
8 changes: 4 additions & 4 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Data.Aeson (Result (..), Value (Null, Object, String), fromJSON, object,
import Data.Aeson qualified as Aeson
import Data.Aeson.Lens (key, values, _Double, _JSON)
import Data.ByteString qualified as BS
import Data.List ((!!))
import Data.List qualified as List
import Data.Map qualified as Map
import Data.Set qualified as Set
import Data.Text qualified as Text
Expand Down Expand Up @@ -158,7 +158,7 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
, ledgerGenesisFile = Nothing
}
-- Start a hydra-node in offline mode and submit a transaction from alice to bob
aliceToBob <- withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] defaultPParams $ \node -> do
aliceToBob <- withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 1 aliceSk [] [1] defaultPParams $ \node -> do
let Just (aliceSeedTxIn, aliceSeedTxOut) = UTxO.find (isVkTxOut aliceCardanoVk) initialUTxO
let Right aliceToBob =
mkSimpleTx
Expand All @@ -171,9 +171,9 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
pure aliceToBob

-- Restart a hydra-node in offline mode expect we can reverse the transaction (it retains state)
withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] defaultPParams $ \node -> do
withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 1 aliceSk [] [1] defaultPParams $ \node -> do
let
bobTxOut = toUTxOContext $ txOuts' aliceToBob !! 0
bobTxOut = toUTxOContext $ List.head (txOuts' aliceToBob)
Right bobToAlice =
mkSimpleTx
(mkTxIn aliceToBob 0, bobTxOut)
Expand Down

0 comments on commit a2fa58d

Please sign in to comment.