From 32760e5a52bcfcf60c8eb06132a9a46ec27e6155 Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Wed, 29 May 2024 12:22:43 +0200 Subject: [PATCH] Contest Mutation: Add utxoToDecommit to the contest snapshot Exercise altering the hashes of utxo and utxoToDecommit to trigger the contestation signature errors `SignatureVerificationFailed`. --- .../Hydra/Chain/Direct/Contract/Contest.hs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/hydra-node/test/Hydra/Chain/Direct/Contract/Contest.hs b/hydra-node/test/Hydra/Chain/Direct/Contract/Contest.hs index fe60dca0f6c..03070e7f5fb 100644 --- a/hydra-node/test/Hydra/Chain/Direct/Contract/Contest.hs +++ b/hydra-node/test/Hydra/Chain/Direct/Contract/Contest.hs @@ -23,11 +23,12 @@ import Hydra.Chain.Direct.Contract.Mutation ( replaceParties, replacePolicyIdWith, replaceSnapshotNumber, - replaceUtxoHash, + replaceUtxoHash, replaceUtxoToDecommitHash, ) import Hydra.Chain.Direct.Fixture (slotLength, systemStart, testNetworkId, testPolicyId) import Hydra.Chain.Direct.Fixture qualified as Fixture import Hydra.Chain.Direct.ScriptRegistry (genScriptRegistry, registryUTxO) +import Hydra.Chain.Direct.State (splitUTxO) import Hydra.Chain.Direct.Tx (ClosedThreadOutput (..), contestTx, mkHeadId, mkHeadOutput) import Hydra.ContestationPeriod (ContestationPeriod, fromChain) import Hydra.Contract.Error (toErrorCode) @@ -104,9 +105,9 @@ healthyContestSnapshot = Snapshot { headId = mkHeadId testPolicyId , number = healthyContestSnapshotNumber - , utxo = healthyContestUTxO + , utxo = fst healthyContestSnapshotUTxO , confirmed = [] - , utxoToDecommit = Nothing + , utxoToDecommit = Just (snd healthyContestSnapshotUTxO) } healthyContestSnapshotNumber :: SnapshotNumber @@ -117,9 +118,16 @@ healthyContestUTxO = (genOneUTxOFor healthyContesterVerificationKey `suchThat` (/= healthyClosedUTxO)) `generateWith` 42 +healthyContestSnapshotUTxO :: (UTxO, UTxO) +healthyContestSnapshotUTxO = generateWith (splitUTxO healthyContestUTxO) 42 + healthyContestUTxOHash :: BuiltinByteString healthyContestUTxOHash = - toBuiltin $ hashUTxO @Tx healthyContestUTxO + toBuiltin $ hashUTxO @Tx (fst healthyContestSnapshotUTxO) + +healthyContestUTxOToDecommitHash :: BuiltinByteString +healthyContestUTxOToDecommitHash = + toBuiltin $ hashUTxO @Tx (snd healthyContestSnapshotUTxO) healthyClosedState :: Head.State healthyClosedState = @@ -306,6 +314,12 @@ genContestMutation (tx, _utxo) = modifyInlineDatum (replaceUtxoHash (toBuiltin mutatedUTxOHash)) headTxOut + , SomeMutation (pure $ toErrorCode SignatureVerificationFailed) MutateContestUTxOHash . ChangeOutput 0 <$> do + mutatedUTxOHash <- genHash `suchThat` ((/= healthyContestUTxOToDecommitHash) . toBuiltin) + pure $ + modifyInlineDatum + (replaceUtxoToDecommitHash (toBuiltin mutatedUTxOHash)) + headTxOut , SomeMutation (pure $ toErrorCode SignatureVerificationFailed) SnapshotNotSignedByAllParties . ChangeInputHeadDatum <$> do mutatedParties <- arbitrary `suchThat` (/= healthyOnChainParties) pure $