Skip to content

Commit

Permalink
ContestUseDec AlterDatumDeltaUTxOHash
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Oct 30, 2024
1 parent 01db7c4 commit 814bd2c
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions hydra-tx/test/Hydra/Tx/Contract/Contest/ContestUsedDec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 814bd2c

Please sign in to comment.