Skip to content

Commit

Permalink
Missing fields,tests, format
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Jan 22, 2025
1 parent e09f618 commit bd11e04
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 179 deletions.
2 changes: 1 addition & 1 deletion hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Test.Hydra.Prelude
import Bench.Summary (Summary (..), makeQuantiles)
import CardanoClient (RunningNode (..), awaitTransaction, submitTransaction, submitTx)
import CardanoNode (findRunningCardanoNode', withCardanoNodeDevnet)
import Hydra.Tx.DepositDeadline (DepositDeadline (UnsafeDepositDeadline))
import Control.Concurrent.Class.MonadSTM (
MonadSTM (readTVarIO),
check,
Expand Down Expand Up @@ -43,6 +42,7 @@ import Hydra.Network (Host)
import Hydra.Tx (HeadId, txId)
import Hydra.Tx.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod))
import Hydra.Tx.Crypto (generateSigningKey)
import Hydra.Tx.DepositDeadline (DepositDeadline (UnsafeDepositDeadline))
import HydraNode (
HydraClient,
HydraNodeLog,
Expand Down
4 changes: 4 additions & 0 deletions hydra-cluster/src/Hydra/Cluster/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Hydra.Cardano.Api qualified as Api
import Hydra.Tx (Party, deriveParty)
import Hydra.Tx.ContestationPeriod (ContestationPeriod (..))
import Hydra.Tx.Crypto (HydraKey, SigningKey, VerificationKey, generateSigningKey, getVerificationKey)
import Hydra.Tx.DepositDeadline (DepositDeadline (..))

alice, bob, carol :: Party
alice = deriveParty aliceSk
Expand All @@ -29,6 +30,9 @@ carolVk = getVerificationKey carolSk
cperiod :: ContestationPeriod
cperiod = UnsafeContestationPeriod 10

ddeadline :: DepositDeadline
ddeadline = UnsafeDepositDeadline 100

-- NOTE: This is hard-coded and needs to correspond to the initial funds set in
-- the genesis-shelley.json file.
availableInitialFunds :: Num a => a
Expand Down
76 changes: 49 additions & 27 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import Hydra.Logging (Tracer, traceWith)
import Hydra.Options (DirectChainConfig (..), networkId, startChainFrom)
import Hydra.Tx (HeadId, IsTx (balance), Party, txId)
import Hydra.Tx.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod), fromNominalDiffTime)
import Hydra.Tx.DepositDeadline (DepositDeadline (..))
import Hydra.Tx.Utils (dummyValidatorScript, verificationKeyToOnChainId)
import HydraNode (
HydraClient (..),
Expand Down Expand Up @@ -138,7 +139,6 @@ import System.FilePath ((</>))
import Test.Hydra.Tx.Fixture (testNetworkId)
import Test.Hydra.Tx.Gen (genKeyPair)
import Test.QuickCheck (choose, elements, generate)
import Hydra.Tx.DepositDeadline (DepositDeadline(..))

data EndToEndLog
= ClusterOptions {options :: Options}
Expand All @@ -163,12 +163,13 @@ restartedNodeCanObserveCommitTx tracer workDir cardanoNode hydraScriptsTxId = do
seedFromFaucet_ cardanoNode bobCardanoVk 100_000_000 (contramap FromFaucet tracer)

let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId

bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId

let hydraTracer = contramap FromHydraNode tracer
Expand All @@ -193,16 +194,17 @@ restartedNodeCanObserveCommitTx tracer workDir cardanoNode hydraScriptsTxId = do
testPreventResumeReconfiguredPeer :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [TxId] -> IO ()
testPreventResumeReconfiguredPeer tracer workDir cardanoNode hydraScriptsTxId = do
let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId

aliceChainConfigWithoutBob <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> setNetworkId networkId

bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId

let hydraTracer = contramap FromHydraNode tracer
Expand Down Expand Up @@ -238,8 +240,9 @@ restartedNodeCanAbort :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [Tx
restartedNodeCanAbort tracer workDir cardanoNode hydraScriptsTxId = do
refuelIfNeeded tracer cardanoNode Alice 100_000_000
let contestationPeriod = UnsafeContestationPeriod 2
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
-- we delibelately do not start from a chain point here to highlight the
-- need for persistence
<&> modifyConfig (\config -> config{networkId, startChainFrom = Nothing})
Expand Down Expand Up @@ -280,8 +283,9 @@ singlePartyHeadFullLifeCycle tracer workDir node hydraScriptsTxId =
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
contestationPeriod <- fromNominalDiffTime $ 10 * blockTime
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> modifyConfig (\config -> config{networkId, startChainFrom = Just tip})
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
-- Initialize & open head
Expand Down Expand Up @@ -336,8 +340,9 @@ singlePartyOpenAHead tracer workDir node hydraScriptsTxId callback =
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> modifyConfig (\config -> config{networkId, startChainFrom = Just tip})

(walletVk, walletSk) <- generate genKeyPair
Expand Down Expand Up @@ -375,7 +380,9 @@ singlePartyCommitsFromExternal tracer workDir node hydraScriptsTxId =
)
$ do
refuelIfNeeded tracer node Alice 25_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -418,7 +425,9 @@ singlePartyUsesScriptOnL2 tracer workDir node hydraScriptsTxId =
)
$ do
refuelIfNeeded tracer node Alice 250_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 1
let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 1
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -552,7 +561,9 @@ singlePartyCommitsScriptBlueprint ::
singlePartyCommitsScriptBlueprint tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
(_, walletSk) <- keysFor AliceFunds
Expand Down Expand Up @@ -639,7 +650,9 @@ persistenceCanLoadWithEmptyCommit ::
persistenceCanLoadWithEmptyCommit tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
headId <- withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -679,7 +692,9 @@ singlePartyCommitsFromExternalTxBlueprint ::
singlePartyCommitsFromExternalTxBlueprint tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
(someExternalVk, someExternalSk) <- generate genKeyPair
Expand Down Expand Up @@ -740,8 +755,9 @@ canCloseWithLongContestationPeriod tracer workDir node hydraScriptsTxId = do
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
let oneWeek = UnsafeContestationPeriod (60 * 60 * 24 * 7)
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] oneWeek
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] oneWeek depositDeadline
<&> modifyConfig (\config -> config{networkId, startChainFrom = Just tip})
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -775,7 +791,9 @@ canSubmitTransactionThroughAPI ::
canSubmitTransactionThroughAPI tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 25_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [hydraNodeId] $ \_ -> do
Expand Down Expand Up @@ -869,8 +887,10 @@ initWithWrongKeys workDir tracer node@RunningNode{nodeSocket} hydraScriptsTxId =
(aliceCardanoVk, _) <- keysFor Alice
(carolCardanoVk, _) <- keysFor Carol

aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Carol] (UnsafeContestationPeriod 2)
bobChainConfig <- chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] (UnsafeContestationPeriod 2)
let contestationPeriod = UnsafeContestationPeriod 2
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Carol] contestationPeriod depositDeadline
bobChainConfig <- chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline

let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir 3 aliceSk [bobVk] [3, 4] $ \n1 -> do
Expand Down Expand Up @@ -902,14 +922,13 @@ canCommit tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Bob) $ do
refuelIfNeeded tracer node Alice 30_000_000
refuelIfNeeded tracer node Bob 30_000_000
-- NOTE: it is important to provide _large_ enough contestation period so that
-- increment tx can be submitted before the deadline
let contestationPeriod = UnsafeContestationPeriod 20
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId
bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk] [2] $ \n1 -> do
withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk] [1] $ \n2 -> do
Expand Down Expand Up @@ -1000,11 +1019,12 @@ canRecoverDeposit tracer workDir node hydraScriptsTxId =
-- NOTE: this value is also used to determine the deposit deadline
let deadline = 5
let contestationPeriod = UnsafeContestationPeriod deadline
let depositDeadline = UnsafeDepositDeadline 5
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId
bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk] [2] $ \n1 -> do
headId <- withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk] [1] $ \n2 -> do
Expand Down Expand Up @@ -1094,11 +1114,12 @@ canSeePendingDeposits tracer workDir node hydraScriptsTxId =
refuelIfNeeded tracer node Bob 30_000_000
let deadline = 1
let contestationPeriod = UnsafeContestationPeriod deadline
let depositDeadline = UnsafeDepositDeadline 1
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId
bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk] [2] $ \n1 -> do
_ <- withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk] [1] $ \n2 -> do
Expand Down Expand Up @@ -1178,8 +1199,9 @@ canDecommit tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 30_000_000
let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
-- Initialize & open head
Expand Down
5 changes: 4 additions & 1 deletion hydra-cluster/src/Hydra/Cluster/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Hydra.Cardano.Api (
import Hydra.Cluster.Fixture (Actor, actorName, fundsOf)
import Hydra.Options (ChainConfig (..), DirectChainConfig (..), defaultDirectChainConfig)
import Hydra.Tx.ContestationPeriod (ContestationPeriod)
import Hydra.Tx.DepositDeadline (DepositDeadline)
import Paths_hydra_cluster qualified as Pkg
import System.FilePath ((<.>), (</>))
import Test.Hydra.Prelude (failure)
Expand Down Expand Up @@ -70,8 +71,9 @@ chainConfigFor ::
[TxId] ->
[Actor] ->
ContestationPeriod ->
DepositDeadline ->
IO ChainConfig
chainConfigFor me targetDir nodeSocket hydraScriptsTxId them contestationPeriod = do
chainConfigFor me targetDir nodeSocket hydraScriptsTxId them contestationPeriod depositDeadline = do
when (me `elem` them) $
failure $
show me <> " must not be in " <> show them
Expand All @@ -91,6 +93,7 @@ chainConfigFor me targetDir nodeSocket hydraScriptsTxId them contestationPeriod
, cardanoSigningKey = actorFilePath me "sk"
, cardanoVerificationKeys = [actorFilePath himOrHer "vk" | himOrHer <- them]
, contestationPeriod
, depositDeadline
}
where
actorFilePath actor fileType = targetDir </> actorFileName actor fileType
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Hydra.Network qualified as Network
import Hydra.Options (ChainConfig (..), DirectChainConfig (..), LedgerConfig (..), RunOptions (..), defaultDirectChainConfig, toArgs)
import Hydra.Tx.ContestationPeriod (ContestationPeriod)
import Hydra.Tx.Crypto (HydraKey)
import Hydra.Tx.DepositDeadline (DepositDeadline)
import Network.HTTP.Conduit (parseUrlThrow)
import Network.HTTP.Req (GET (..), HttpException, JsonResponse, NoReqBody (..), POST (..), ReqBodyJson (..), defaultHttpConfig, responseBody, runReq, (/:))
import Network.HTTP.Req qualified as Req
Expand All @@ -44,7 +45,6 @@ import System.Process (
)
import Test.Hydra.Prelude (checkProcessHasNotDied, failAfter, failure, shouldNotBe, withLogFile)
import Prelude qualified
import Hydra.Tx.DepositDeadline (DepositDeadline)

-- * Client to interact with a hydra-node

Expand Down
4 changes: 2 additions & 2 deletions hydra-cluster/test/Test/ChainObserverSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Hydra.Tx.IsTx (txId)
import HydraNode (HydraNodeLog, input, output, requestCommitTx, send, waitFor, waitMatch, withHydraNode)
import System.IO.Error (isEOFError, isIllegalOperation)
import System.Process (CreateProcess (std_out), StdStream (..), proc, withCreateProcess)
import Test.Hydra.Tx.Fixture (aliceSk, cperiod)
import Test.Hydra.Tx.Fixture (aliceSk, cperiod, ddeadline)
import Test.Hydra.Tx.Gen (genKeyPair)
import Test.QuickCheck (generate)

Expand All @@ -45,7 +45,7 @@ spec = do
let hydraTracer = contramap FromHydraNode tracer
hydraScriptsTxId <- publishHydraScriptsAs cardanoNode Faucet
(aliceCardanoVk, _) <- keysFor Alice
aliceChainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod
aliceChainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod ddeadline
withHydraNode hydraTracer aliceChainConfig tmpDir 1 aliceSk [] [1] $ \hydraNode -> do
withChainObserver cardanoNode $ \observer -> do
seedFromFaucet_ cardanoNode aliceCardanoVk 100_000_000 (contramap FromFaucet tracer)
Expand Down
Loading

0 comments on commit bd11e04

Please sign in to comment.