From d6ff585d9536f09cf33d4be713952b9776eddfc8 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 | 4 ++ hydra-cluster/src/Hydra/Cluster/Scenarios.hs | 49 ++++++++++++++++++++ hydra-cluster/test/Test/EndToEndSpec.hs | 6 +++ 3 files changed, 59 insertions(+) diff --git a/hydra-cluster/hydra-cluster.cabal b/hydra-cluster/hydra-cluster.cabal index 5fc922554bd..23a7d1d9a06 100644 --- a/hydra-cluster/hydra-cluster.cabal +++ b/hydra-cluster/hydra-cluster.cabal @@ -88,6 +88,7 @@ library , base >=4.7 && <5 , bytestring , cardano-slotting + , cardano-api , containers , contra-tracer , data-default @@ -98,6 +99,7 @@ library , hydra-cardano-api , hydra-node , hydra-prelude + , hydra-plutus , hydra-test-utils , hydra-tx , hydra-tx:testlib @@ -106,6 +108,8 @@ library , lens , lens-aeson , optparse-applicative + , plutus-ledger-api + , plutus-tx , process , QuickCheck , req diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index de3312b4ee8..8e9f9bb450e 100644 --- a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs +++ b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs @@ -6,6 +6,9 @@ module Hydra.Cluster.Scenarios where import Hydra.Prelude import Test.Hydra.Prelude +import qualified Cardano.Api.Shelley as C +import qualified PlutusTx.Prelude as PlutusTx +import qualified PlutusLedgerApi.V1 as PV1 import Cardano.Api.UTxO qualified as UTxO import CardanoClient ( QueryPoint (QueryTip), @@ -16,6 +19,7 @@ import CardanoClient ( submitTx, waitForUTxO, ) +import Hydra.Contract.Dummy (dummyValidatorHash) import CardanoNode (NodeLog) import Control.Concurrent.Async (mapConcurrently_) import Control.Lens ((^..), (^?)) @@ -38,7 +42,11 @@ import Hydra.Cardano.Api ( File (File), Key (SigningKey), PaymentKey, + StakeAddressReference(..), + PaymentCredential(..), Tx, + shelleyBasedEra, + makeShelleyAddressInEra, TxId, UTxO, getTxBody, @@ -380,6 +388,47 @@ 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] + scriptHash <- unTransScriptHash dummyValidatorHash + let scriptAddress = makeShelleyAddressInEra shelleyBasedEra networkId (PaymentCredentialByScript scriptHash) 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 + unTransScriptHash :: PV1.ScriptHash -> IO C.ScriptHash + unTransScriptHash (PV1.ScriptHash vh) = + case C.deserialiseFromRawBytes C.AsScriptHash $ PlutusTx.fromBuiltin vh of + Left e -> fail $ show e + Right x -> pure x + + 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 ->