Skip to content

Commit

Permalink
Broaden version mutation for collect
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jul 10, 2024
1 parent 4429b42 commit 4a7d6bd
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions hydra-node/test/Hydra/Chain/Direct/Contract/CollectCom.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ genCollectComMutation (tx, _utxo) =
pure $ ChangeOutput 0 (modifyTxOutAddress (const mutatedAddress) headTxOut)
, SomeMutation (pure $ toErrorCode NotAllValueCollected) ExtractSomeValue <$> do
extractHeadOutputValue headTxOut testPolicyId
, SomeMutation (pure $ toErrorCode IncorrectUtxoHash) MutateOpenUTxOHash . ChangeOutput 0 <$> mutateUTxOHash
, SomeMutation (pure $ toErrorCode IncorrectVersion) MutateOpenVersion . ChangeOutput 0 <$> mutateVersion
, SomeMutation (pure $ toErrorCode IncorrectUtxoHash) MutateOpenUTxOHash . ChangeOutput 0 <$> do
mutatedUTxOHash <- genHash
pure $ modifyInlineDatum (mutateState mutatedUTxOHash) headTxOut
, SomeMutation (pure $ toErrorCode IncorrectVersion) MutateOpenVersion . ChangeOutput 0 <$> do
mutatedVersion <- arbitrary `suchThat` (/= 0)
pure $ modifyInlineDatum (mutateStateVersion mutatedVersion) headTxOut
, SomeMutation (pure $ toErrorCode MissingCommits) MutateNumberOfParties <$> do
moreParties <- (: healthyOnChainParties) <$> arbitrary
pure $
Expand Down Expand Up @@ -262,19 +266,11 @@ genCollectComMutation (tx, _utxo) =
Head.Open{Head.parties = parties, snapshotNumber, contestationPeriod, headId, version, utxoHash}
st -> error $ "Unexpected state " <> show st

mutateUTxOHash = do
mutatedUTxOHash <- genHash
pure $ modifyInlineDatum (mutateState mutatedUTxOHash) headTxOut

mutateState mutatedUTxOHash = \case
Head.Open{parties, contestationPeriod, headId, snapshotNumber, version} ->
Head.Open{Head.utxoHash = toBuiltin mutatedUTxOHash, parties, contestationPeriod, headId, snapshotNumber, version}
st -> st

mutateVersion = do
mutatedVersion <- arbitrary `suchThat` (> 0)
pure $ modifyInlineDatum (mutateStateVersion mutatedVersion) headTxOut

mutateStateVersion mutatedVersion = \case
Head.Open{parties, contestationPeriod, headId, snapshotNumber, utxoHash} ->
Head.Open{version = mutatedVersion, parties, contestationPeriod, headId, snapshotNumber, utxoHash}
Expand Down

0 comments on commit 4a7d6bd

Please sign in to comment.