From 7d8d53015b5b5533c9c5c4b55b0b06f9a2d552c1 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Mon, 2 Dec 2024 13:07:57 +0000 Subject: [PATCH] add singlePartyUsesSchnorrkelScriptOnL2 scenario test --- hydra-cluster/hydra-cluster.cabal | 1 + hydra-cluster/src/Hydra/Cluster/Scenarios.hs | 39 ++++++++++++++++++++ hydra-cluster/test/Test/EndToEndSpec.hs | 6 +++ 3 files changed, 46 insertions(+) diff --git a/hydra-cluster/hydra-cluster.cabal b/hydra-cluster/hydra-cluster.cabal index 5fc922554bd..698c182215b 100644 --- a/hydra-cluster/hydra-cluster.cabal +++ b/hydra-cluster/hydra-cluster.cabal @@ -98,6 +98,7 @@ library , hydra-cardano-api , hydra-node , hydra-prelude + , hydra-plutus , hydra-test-utils , hydra-tx , hydra-tx:testlib diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index de3312b4ee8..02f31619d9a 100644 --- a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs +++ b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs @@ -16,6 +16,7 @@ import CardanoClient ( submitTx, waitForUTxO, ) +import Hydra.Contract.Dummy (dummyValidatorHash) import CardanoNode (NodeLog) import Control.Concurrent.Async (mapConcurrently_) import Control.Lens ((^..), (^?)) @@ -38,7 +39,11 @@ import Hydra.Cardano.Api ( File (File), Key (SigningKey), PaymentKey, + StakeAddressReference(..), + PaymentCredential(..), Tx, + shelleyBasedEra, + makeShelleyAddressInEra, TxId, UTxO, getTxBody, @@ -380,6 +385,40 @@ singlePartyCommitsFromExternal tracer workDir node hydraScriptsTxId = where RunningNode{nodeSocket, blockTime} = node +singlePartyUsesSchnorrkelScriptOnL2 :: + Tracer IO EndToEndLog -> + FilePath -> + RunningNode -> + TxId -> + IO () +singlePartyUsesSchnorrkelScriptOnL2 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 hydraNodeId = 1 + let hydraTracer = contramap FromHydraNode tracer + (walletVk, walletSk) <- keysFor AliceFunds + utxoToCommit <- seedFromFaucet node walletVk 5_000_000 (contramap FromFaucet tracer) + withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do + send n1 $ input "Init" [] + headId <- waitMatch (10 * blockTime) n1 $ headIsInitializingWith (Set.fromList [alice]) + requestCommitTx n1 utxoToCommit <&> signTx walletSk >>= submitTx node + waitFor hydraTracer (10 * blockTime) [n1] $ + output "HeadIsOpen" ["utxo" .= toJSON utxoToCommit, "headId" .= headId] + let scriptAddress = makeShelleyAddressInEra shelleyBasedEra networkId (PaymentCredentialByScript dummyValidatorHash) NoStakeAddress + let i = undefined + let o = undefined + let tx = mkSimpleTx (i, o) (scriptAddress, txOutValue o) walletSk + send n1 $ input "NewTx" ["transaction" .= tx] + waitMatch 10 n1 $ \v -> do + guard $ v ^? key "tag" == Just "SnapshotConfirmed" + guard $ + toJSON tx + `elem` (v ^.. key "snapshot" . key "confirmed" . values) + v ^? key "snapshot" . key "utxo" >>= parseMaybe parseJSON + where + RunningNode{networkId, nodeSocket, blockTime} = node + singlePartyCommitsScriptBlueprint :: Tracer IO EndToEndLog -> FilePath -> diff --git a/hydra-cluster/test/Test/EndToEndSpec.hs b/hydra-cluster/test/Test/EndToEndSpec.hs index e3f1d03ed8a..783d886ef08 100644 --- a/hydra-cluster/test/Test/EndToEndSpec.hs +++ b/hydra-cluster/test/Test/EndToEndSpec.hs @@ -72,6 +72,7 @@ import Hydra.Cluster.Scenarios ( singlePartyCommitsFromExternalTxBlueprint, singlePartyCommitsScriptBlueprint, singlePartyHeadFullLifeCycle, + singlePartyUsesSchnorrkelScriptOnL2, testPreventResumeReconfiguredPeer, threeNodesNoErrorsOnOpen, ) @@ -183,6 +184,11 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node -> publishHydraScriptsAs node Faucet >>= singlePartyCommitsFromExternal tracer tmpDir node + it "can use a schnorrkel script on L2" $ \tracer -> do + withClusterTempDir $ \tmpDir -> do + withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node -> + publishHydraScriptsAs node Faucet + >>= singlePartyUsesSchnorrkelScriptOnL2 tracer tmpDir node it "can submit a signed user transaction" $ \tracer -> do withClusterTempDir $ \tmpDir -> do withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node ->