From 814bd2ccfad814d8b14ac67f9d866dbe3857dbf7 Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Wed, 30 Oct 2024 12:37:39 +0100 Subject: [PATCH] ContestUseDec AlterDatumDeltaUTxOHash --- .../Tx/Contract/Contest/ContestUsedDec.hs | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/hydra-tx/test/Hydra/Tx/Contract/Contest/ContestUsedDec.hs b/hydra-tx/test/Hydra/Tx/Contract/Contest/ContestUsedDec.hs index a3b04076251..f610377cacf 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Contest/ContestUsedDec.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Contest/ContestUsedDec.hs @@ -5,6 +5,8 @@ module Hydra.Tx.Contract.Contest.ContestUsedDec where import Hydra.Cardano.Api import Hydra.Prelude hiding (label) +import Data.Maybe (fromJust) + import Hydra.Contract.Error (toErrorCode) import Hydra.Contract.HeadError (HeadError (..)) import Hydra.Contract.HeadState qualified as Head @@ -14,20 +16,40 @@ import Hydra.Tx.Contract.Contest.Healthy (healthyContestSnapshotNumber, healthyS import Test.Hydra.Tx.Mutation ( Mutation (..), SomeMutation (..), + modifyInlineDatum, + replaceDeltaUTxOHash, ) +import Test.QuickCheck (oneof, suchThat) import Test.QuickCheck.Instances () data ContestUsedDecMutation = AlterRedeemerDecommitHash + | AlterDatumDeltaUTxOHash deriving stock (Generic, Show, Enum, Bounded) genContestUsedDecMutation :: (Tx, UTxO) -> Gen SomeMutation -genContestUsedDecMutation (_tx, _utxo) = - SomeMutation (pure $ toErrorCode FailedContestUsedDec) AlterRedeemerDecommitHash <$> do - pure $ - ChangeHeadRedeemer $ - Head.Contest - Head.ContestUsedDec - { signature = toPlutusSignatures (healthySignature healthyContestSnapshotNumber) - , alreadyDecommittedUTxOHash = mempty - } +genContestUsedDecMutation (tx, _utxo) = + oneof + [ SomeMutation (pure $ toErrorCode FailedContestUsedDec) AlterRedeemerDecommitHash <$> do + pure $ + ChangeHeadRedeemer $ + Head.Contest + Head.ContestUsedDec + { signature = toPlutusSignatures (healthySignature healthyContestSnapshotNumber) + , alreadyDecommittedUTxOHash = mempty + } + , SomeMutation (pure $ toErrorCode FailedContestUsedDec) AlterRedeemerDecommitHash <$> do + mutatedHash <- arbitrary `suchThat` (/= mempty) + pure $ + ChangeHeadRedeemer $ + Head.Contest + Head.ContestUsedDec + { signature = toPlutusSignatures (healthySignature healthyContestSnapshotNumber) + , alreadyDecommittedUTxOHash = mutatedHash + } + , SomeMutation (pure $ toErrorCode SignatureVerificationFailed) AlterDatumDeltaUTxOHash . ChangeOutput 0 <$> do + mutatedHash <- arbitrary `suchThat` (/= mempty) + pure $ headTxOut & modifyInlineDatum (replaceDeltaUTxOHash mutatedHash) + ] + where + headTxOut = fromJust $ txOuts' tx !!? 0