Skip to content

Commit

Permalink
Merge contest used and unused mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Oct 30, 2024
1 parent 65680bb commit ef3ffc6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hydra-tx/hydra-tx.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ test-suite tests
Hydra.Tx.Contract.CollectCom
Hydra.Tx.Contract.Commit
Hydra.Tx.Contract.Contest.ContestCurrent
Hydra.Tx.Contract.Contest.ContestUsedDec
Hydra.Tx.Contract.Contest.ContestDec
Hydra.Tx.Contract.Contest.Healthy
Hydra.Tx.Contract.ContractSpec
Hydra.Tx.Contract.Decrement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE DuplicateRecordFields #-}

module Hydra.Tx.Contract.Contest.ContestUsedDec where
module Hydra.Tx.Contract.Contest.ContestDec where

import Hydra.Cardano.Api
import Hydra.Prelude hiding (label)
Expand All @@ -27,24 +27,24 @@ import Test.Hydra.Tx.Mutation (
import Test.QuickCheck (arbitrarySizedNatural, oneof, suchThat)
import Test.QuickCheck.Instances ()

data ContestUsedDecMutation
= AlterRedeemerDecommitHash
| AlterDatumDeltaUTxOHash
| MutateSnapshotVersion
data ContestDecMutation
= ContestUsedDecAlterRedeemerDecommitHash
| ContestUsedDecAlterDatumDeltaUTxOHash
| ContestUsedDecMutateSnapshotVersion
deriving stock (Generic, Show, Enum, Bounded)

genContestUsedDecMutation :: (Tx, UTxO) -> Gen SomeMutation
genContestUsedDecMutation (tx, _utxo) =
genContestDecMutation :: (Tx, UTxO) -> Gen SomeMutation
genContestDecMutation (tx, _utxo) =
oneof
[ SomeMutation (pure $ toErrorCode FailedContestUsedDec) AlterRedeemerDecommitHash <$> do
[ SomeMutation (pure $ toErrorCode FailedContestUsedDec) ContestUsedDecAlterRedeemerDecommitHash <$> do
pure $
ChangeHeadRedeemer $
Head.Contest
Head.ContestUsedDec
{ signature = toPlutusSignatures (healthySignature healthyContestSnapshotNumber)
, alreadyDecommittedUTxOHash = mempty
}
, SomeMutation (pure $ toErrorCode FailedContestUsedDec) AlterRedeemerDecommitHash <$> do
, SomeMutation (pure $ toErrorCode FailedContestUsedDec) ContestUsedDecAlterRedeemerDecommitHash <$> do
mutatedHash <- arbitrary `suchThat` (/= mempty)
pure $
ChangeHeadRedeemer $
Expand All @@ -53,10 +53,10 @@ genContestUsedDecMutation (tx, _utxo) =
{ signature = toPlutusSignatures (healthySignature healthyContestSnapshotNumber)
, alreadyDecommittedUTxOHash = mutatedHash
}
, SomeMutation (pure $ toErrorCode SignatureVerificationFailed) AlterDatumDeltaUTxOHash . ChangeOutput 0 <$> do
, SomeMutation (pure $ toErrorCode SignatureVerificationFailed) ContestUsedDecAlterDatumDeltaUTxOHash . ChangeOutput 0 <$> do
mutatedHash <- arbitrary `suchThat` (/= mempty)
pure $ headTxOut & modifyInlineDatum (replaceDeltaUTxOHash mutatedHash)
, SomeMutation (pure $ toErrorCode MustNotChangeVersion) MutateSnapshotVersion <$> do
, SomeMutation (pure $ toErrorCode MustNotChangeVersion) ContestUsedDecMutateSnapshotVersion <$> do
mutatedSnapshotVersion <- arbitrarySizedNatural `suchThat` (/= healthyCloseSnapshotVersion)
pure $ ChangeOutput 0 $ modifyInlineDatum (replaceSnapshotVersion $ toInteger mutatedSnapshotVersion) headTxOut
]
Expand Down
6 changes: 3 additions & 3 deletions hydra-tx/test/Hydra/Tx/Contract/ContractSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Hydra.Tx.Contract.Close.CloseUsed (genCloseOutdatedMutation, healthyClose
import Hydra.Tx.Contract.CollectCom (genCollectComMutation, healthyCollectComTx)
import Hydra.Tx.Contract.Commit (genCommitMutation, healthyCommitTx)
import Hydra.Tx.Contract.Contest.ContestCurrent (genContestMutation)
import Hydra.Tx.Contract.Contest.ContestUsedDec (genContestUsedDecMutation)
import Hydra.Tx.Contract.Contest.ContestDec (genContestDecMutation)
import Hydra.Tx.Contract.Contest.Healthy (healthyContestTx)
import Hydra.Tx.Contract.Decrement (genDecrementMutation, healthyDecrementTx)
import Hydra.Tx.Contract.Deposit (healthyDepositTx)
Expand Down Expand Up @@ -149,11 +149,11 @@ spec = parallel $ do
propTransactionEvaluates healthyContestTx
prop "does not survive random adversarial mutations" $
propMutation healthyContestTx genContestMutation
describe "ContestUsedDec" $ do
describe "ContestDec" $ do
prop "is healthy" $
propTransactionEvaluates healthyContestTx
prop "does not survive random adversarial mutations" $
propMutation healthyContestTx genContestUsedDecMutation
propMutation healthyContestTx genContestDecMutation
describe "Fanout" $ do
prop "is healthy" $
propTransactionEvaluates healthyFanoutTx
Expand Down

0 comments on commit ef3ffc6

Please sign in to comment.