Skip to content

Commit

Permalink
Decrement mutation: Check value in the Head is preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Mar 11, 2024
1 parent e59afa0 commit c4ec54a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hydra-node/test/Hydra/Chain/Direct/Contract/Decrement.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Hydra.Data.Party qualified as OnChain
import Hydra.Ledger (IsTx (hashUTxO, withoutUTxO))
import Hydra.Ledger.Cardano (
adaOnly,
genTxOut,
genUTxOSized,
genValue,
genVerificationKey,
Expand Down Expand Up @@ -152,6 +151,11 @@ data DecrementMutation
MutateRequiredSigner
| -- | Mutate the output value to produce different 'UTxO' hash to the one in the signed 'Snapshot'.
MutateChangeOutputValue
| -- | Invalidates the tx by changing the output values arbitrarily to be
-- different (not preserved) from the head.
--
-- Ensures values are preserved between head input and output.
MutateValueInOutput
deriving stock (Generic, Show, Enum, Bounded)

genDecrementMutation :: (Tx, UTxO) -> Gen SomeMutation
Expand All @@ -174,6 +178,9 @@ genDecrementMutation (tx, _utxo) =
(ix, out) <- elements (zip [1 .. length outs - 1] outs)
value' <- genValue `suchThat` (/= txOutValue out)
pure $ ChangeOutput (fromIntegral ix) (modifyTxOutValue (const value') out)
, SomeMutation (Just $ toErrorCode HeadValueIsNotPreserved) MutateValueInOutput <$> do
newValue <- genValue
pure $ ChangeOutput 0 (headTxOut{txOutValue = newValue})
]
where
headTxOut = fromJust $ txOuts' tx !!? 0

0 comments on commit c4ec54a

Please sign in to comment.