Skip to content

Commit

Permalink
Add base e2e draft for external ommit
Browse files Browse the repository at this point in the history
Ignore previously added hydra-node spec.
  • Loading branch information
ffakenz committed Jun 5, 2023
1 parent f693337 commit 3c3f3fb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
47 changes: 45 additions & 2 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Expand Up @@ -5,10 +5,11 @@ module Hydra.Cluster.Scenarios where

import Hydra.Prelude

import CardanoClient (queryTip)
import CardanoClient (queryTip, submitTransaction)
import CardanoNode (RunningNode (..))
import Control.Lens ((^?))
import Control.Lens ((.~), (^?))
import Data.Aeson (Value, object, (.=))
import qualified Data.Aeson as Aeson
import Data.Aeson.Lens (key, _JSON)
import Data.Aeson.Types (parseMaybe)
import qualified Data.Set as Set
Expand Down Expand Up @@ -135,6 +136,48 @@ singlePartyHeadFullLifeCycle tracer workDir node@RunningNode{networkId} hydraScr
(fuelUTxO, otherUTxO) <- queryMarkedUTxO node actorVk
traceWith tracer RemainingFunds{actor = actorName actor, fuelUTxO, otherUTxO}

singlePartyCommitsFromExternal ::
Tracer IO EndToEndLog ->
FilePath ->
RunningNode ->
TxId ->
IO ()
singlePartyCommitsFromExternal tracer workDir node@RunningNode{networkId} hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 25_000_000
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
let contestationPeriod = UnsafeContestationPeriod 100
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket [] contestationPeriod
<&> \config -> config{networkId, startChainFrom = Just tip}
withHydraNode tracer aliceChainConfig workDir 1 aliceSk [] [1] hydraScriptsTxId $ \n1 -> do
-- Initialize & open head
send n1 $ input "Init" []
headId <- waitMatch 600 n1 $ headIsInitializingWith (Set.fromList [alice])

-- Build Draft Commit Tx
send n1 $ input "DraftCommitTx" ["utxo" .= object mempty]

commitTxValue <- waitMatch 10 n1 $ \v -> do
guard $ v ^? key "tag" == Just "CommitTxDrafted"
v ^? key "commitTx" . _JSON

-- Commit Tx from external
-- use cardano-cli to submit drafted commitTx
submitTransaction networkId nodeSocket commitTxValue

waitFor tracer 600 [n1] $
output "HeadIsOpen" ["utxo" .= object mempty, "headId" .= headId]
traceRemainingFunds Alice
where
RunningNode{nodeSocket} = node

traceRemainingFunds actor = do
(actorVk, _) <- keysFor actor
(fuelUTxO, otherUTxO) <- queryMarkedUTxO node actorVk
traceWith tracer RemainingFunds{actor = actorName actor, fuelUTxO, otherUTxO}

-- | Initialize open and close a head on a real network and ensure contestation
-- period longer than the time horizon is possible. For this it is enough that
-- we can close a head and not wait for the deadline.
Expand Down
6 changes: 6 additions & 0 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Expand Up @@ -65,6 +65,7 @@ import Hydra.Cluster.Scenarios (
headIsInitializingWith,
restartedNodeCanAbort,
restartedNodeCanObserveCommitTx,
singlePartyCommitsFromExternal,
singlePartyHeadFullLifeCycle,
)
import Hydra.Cluster.Util (chainConfigFor, keysFor)
Expand Down Expand Up @@ -131,6 +132,11 @@ spec = around showLogsOnFailure $ do
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node ->
publishHydraScriptsAs node Faucet
>>= timedTx tmpDir tracer node
it "commits from external" $ \tracer -> do
withClusterTempDir "single-commits-from-external" $ \tmpDir -> do
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node ->
publishHydraScriptsAs node Faucet
>>= singlePartyCommitsFromExternal tracer tmpDir node

describe "three hydra nodes scenario" $ do
it "inits a Head, processes a single Cardano transaction and closes it again" $ \tracer ->
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Expand Up @@ -140,8 +140,8 @@ spec =
& counterexample (renderTx tx)
& counterexample (show e)

describe "draftCommitTx" $ do
prop "can build valid draft commit tx" $ \chainState initialPubKeyHash intialTxIn committedUTxO party walletUtxo -> do
xdescribe "draftCommitTx" $ do
xprop "can build valid draft commit tx" $ \chainState initialPubKeyHash intialTxIn committedUTxO party walletUtxo -> do
let
initialTxOut = genTxOut `generateWith` 45
scriptRegistry = genScriptRegistry `generateWith` 42
Expand Down

0 comments on commit 3c3f3fb

Please sign in to comment.