Skip to content

Commit

Permalink
Add mutator for collectCom output utxo hash
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk committed Jan 18, 2022
1 parent c59d3f5 commit 3d50644
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions hydra-node/test/Hydra/Chain/Direct/ContractSpec.hs
Expand Up @@ -58,6 +58,7 @@ import Hydra.Ledger.Cardano (
TxBodyScriptData (TxBodyNoScriptData, TxBodyScriptData),
TxIn,
TxOut (..),
TxOutDatum (..),
Utxo,
Utxo' (Utxo),
adaOnly,
Expand Down Expand Up @@ -89,6 +90,7 @@ import Hydra.Ledger.Cardano (
toCtxUTxOTxOut,
toLedgerTxIn,
toLedgerTxOut,
toPlutusData,
txOutValue,
unsafeBuildTransaction,
utxoPairs,
Expand Down Expand Up @@ -125,6 +127,7 @@ import Test.QuickCheck (
oneof,
property,
suchThat,
vector,
(===),
)
import Test.QuickCheck.Instances ()
Expand Down Expand Up @@ -422,6 +425,7 @@ healthyCommitOutput party committed =

data CollectComMutation
= MutateOpenOutputValue
| MutateOpenUtxoHash
deriving (Generic, Show, Enum, Bounded)

genCollectComMutation :: (CardanoTx, Utxo) -> Gen SomeMutation
Expand All @@ -430,6 +434,21 @@ genCollectComMutation (tx, _utxo) =
[ SomeMutation MutateOpenOutputValue . ChangeOutput 0 <$> do
mutatedValue <- (mkTxOutValue <$> genValue) `suchThat` (/= collectComOutputValue)
pure $ TxOut collectComOutputAddress mutatedValue collectComOutputDatum
, SomeMutation MutateOpenUtxoHash . ChangeOutput 0 <$> do
mutatedUtxoHash <- BS.pack <$> vector 32
case collectComOutputDatum of
TxOutDatumNone -> error "unexpected empty head datum"
(TxOutDatumHash _sdsie _ha) -> error "unexpected hash-only datum"
(TxOutDatum _sdsie sd) ->
case fromData $ toPlutusData sd of
Nothing -> error "Invalid data"
(Just Head.Open{parties}) ->
pure $
TxOut
collectComOutputAddress
collectComOutputValue
(mkTxOutDatum Head.Open{parties, Head.utxoHash = toBuiltin mutatedUtxoHash})
(Just st) -> error $ "unexpected state " <> show st
]
where
TxOut collectComOutputAddress collectComOutputValue collectComOutputDatum =
Expand Down

0 comments on commit 3d50644

Please sign in to comment.