Skip to content

Commit

Permalink
Add blockTime to RunningNode to be flexible in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jan 4, 2024
1 parent 277d429 commit 31c517f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions hydra-cluster/src/CardanoClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ mkGenesisTx networkId pparams signingKey initialAmount recipients =
data RunningNode = RunningNode
{ nodeSocket :: SocketPath
, networkId :: NetworkId
, blockTime :: DiffTime
-- ^ Expected time between blocks (varies a lot on testnets)
, pparams :: PParams Api.LedgerEra
}

Expand Down
16 changes: 7 additions & 9 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -232,37 +232,35 @@ singlePartyHeadFullLifeCycle tracer workDir node hydraScriptsTxId =
refuelIfNeeded tracer node Alice 25_000_000
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
let contestationPeriod = UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod $ 5 * truncate blockTime
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
<&> modifyConfig (\config -> config{networkId, startChainFrom = Just tip})
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
-- Initialize & open head
send n1 $ input "Init" []
headId <- waitMatch 600 n1 $ headIsInitializingWith (Set.fromList [alice])
headId <- waitMatch (10 * blockTime) n1 $ headIsInitializingWith (Set.fromList [alice])
-- Commit nothing for now
requestCommitTx n1 mempty >>= submitTx node
waitFor hydraTracer 600 [n1] $
waitFor hydraTracer (10 * blockTime) [n1] $
output "HeadIsOpen" ["utxo" .= object mempty, "headId" .= headId]
-- Close head
send n1 $ input "Close" []
deadline <- waitMatch 600 n1 $ \v -> do
deadline <- waitMatch (10 * blockTime) n1 $ \v -> do
guard $ v ^? key "tag" == Just "HeadIsClosed"
guard $ v ^? key "headId" == Just (toJSON headId)
v ^? key "contestationDeadline" . _JSON
-- Expect to see ReadyToFanout within 600 seconds after deadline.
-- XXX: We still would like to have a network-specific time here
remainingTime <- realToFrac . diffUTCTime deadline <$> getCurrentTime
waitFor hydraTracer (remainingTime + 60) [n1] $
waitFor hydraTracer (remainingTime + 3 * blockTime) [n1] $
output "ReadyToFanout" ["headId" .= headId]
send n1 $ input "Fanout" []
waitFor hydraTracer 600 [n1] $
waitFor hydraTracer (10 * blockTime) [n1] $
output "HeadIsFinalized" ["utxo" .= object mempty, "headId" .= headId]
traceRemainingFunds Alice
where
hydraTracer = contramap FromHydraNode tracer

RunningNode{networkId, nodeSocket} = node
RunningNode{networkId, nodeSocket, blockTime} = node

traceRemainingFunds actor = do
(actorVk, _) <- keysFor actor
Expand Down

0 comments on commit 31c517f

Please sign in to comment.