Skip to content

Commit

Permalink
add singlePartyUsesSchnorrkelScriptOnL2 scenario test
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Dec 2, 2024
1 parent 8ab3b61 commit d6ff585
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ library
, base >=4.7 && <5
, bytestring
, cardano-slotting
, cardano-api
, containers
, contra-tracer
, data-default
Expand All @@ -98,6 +99,7 @@ library
, hydra-cardano-api
, hydra-node
, hydra-prelude
, hydra-plutus
, hydra-test-utils
, hydra-tx
, hydra-tx:testlib
Expand All @@ -106,6 +108,8 @@ library
, lens
, lens-aeson
, optparse-applicative
, plutus-ledger-api
, plutus-tx
, process
, QuickCheck
, req
Expand Down
49 changes: 49 additions & 0 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -16,6 +19,7 @@ import CardanoClient (
submitTx,
waitForUTxO,
)
import Hydra.Contract.Dummy (dummyValidatorHash)
import CardanoNode (NodeLog)
import Control.Concurrent.Async (mapConcurrently_)
import Control.Lens ((^..), (^?))
Expand All @@ -38,7 +42,11 @@ import Hydra.Cardano.Api (
File (File),
Key (SigningKey),
PaymentKey,
StakeAddressReference(..),
PaymentCredential(..),
Tx,
shelleyBasedEra,
makeShelleyAddressInEra,
TxId,
UTxO,
getTxBody,
Expand Down Expand Up @@ -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 ->
Expand Down
6 changes: 6 additions & 0 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import Hydra.Cluster.Scenarios (
singlePartyCommitsFromExternalTxBlueprint,
singlePartyCommitsScriptBlueprint,
singlePartyHeadFullLifeCycle,
singlePartyUsesSchnorrkelScriptOnL2,
testPreventResumeReconfiguredPeer,
threeNodesNoErrorsOnOpen,
)
Expand Down Expand Up @@ -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 ->
Expand Down

0 comments on commit d6ff585

Please sign in to comment.