Skip to content

Commit

Permalink
ADD explicit error expectations for CollectCom
Browse files Browse the repository at this point in the history
TODO: need to be explicit with the other mutations also
NOTE: note clear what the MutateHeadTransition is trying to exercise
  • Loading branch information
pgrange committed Feb 8, 2023
1 parent 4be6891 commit a35e743
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions hydra-node/test/Hydra/Chain/Direct/Contract/CollectCom.hs
Expand Up @@ -167,7 +167,10 @@ data CollectComMutation
| -- | Test that collectCom cannot collect from an initial UTxO.
MutateCommitToInitial
| MutateHeadTransition
| -- | Test that every party has a chance to commit.
| -- | Every party should have commited and taken into account for the collectCom transaction to be valid
-- Here we increase the number of parties in input and output but keep the commits unchanged. This
-- simulate the situation where one participant would not have commited already or whose commit would
-- have been ignored by the collectCom transaction.
MutateNumberOfParties
| MutateHeadId
| MutateRequiredSigner
Expand All @@ -178,7 +181,7 @@ data CollectComMutation
genCollectComMutation :: (Tx, UTxO) -> Gen SomeMutation
genCollectComMutation (tx, _utxo) =
oneof
[ SomeMutation Nothing MutateOpenUTxOHash . ChangeOutput 0 <$> mutateUTxOHash
[ SomeMutation (Just "incorrect utxo hash") MutateOpenUTxOHash . ChangeOutput 0 <$> mutateUTxOHash
, SomeMutation Nothing MutateHeadTransition <$> do
changeRedeemer <- ChangeHeadRedeemer <$> (Head.Close <$> arbitrary)
differencCurrencySymbol <- arbitrary `suchThat` (/= toPlutusCurrencySymbol testPolicyId)
Expand All @@ -191,7 +194,7 @@ genCollectComMutation (tx, _utxo) =
<*> pure differencCurrencySymbol
)
pure $ Changes [changeRedeemer, changeDatum]
, SomeMutation Nothing MutateNumberOfParties <$> do
, SomeMutation (Just "changed parameters") MutateNumberOfParties <$> do
-- NOTE: This also mutates the contestation period becuase we could not
-- be bothered to decode/lookup the current one.
c <- arbitrary
Expand All @@ -201,17 +204,20 @@ genCollectComMutation (tx, _utxo) =
[ ChangeInputHeadDatum $ Head.Initial c moreParties (toPlutusCurrencySymbol testPolicyId)
, ChangeOutput 0 $ mutatedPartiesHeadTxOut moreParties headTxOut
]
, SomeMutation Nothing MutateHeadId <$> do
, SomeMutation (Just "ST not spent in transaction") MutateHeadId <$> do
illedHeadResolvedInput <-
mkHeadOutput
<$> pure testNetworkId
<*> fmap headPolicyId (arbitrary `suchThat` (/= testSeedInput))
<*> pure (toUTxOContext $ mkTxOutDatum healthyCollectComInitialDatum)
return $ ChangeInput healthyHeadInput illedHeadResolvedInput (Just $ toScriptData Head.CollectCom)
, SomeMutation Nothing MutateRequiredSigner <$> do
, SomeMutation (Just "signer is not a participant") MutateRequiredSigner <$> do
newSigner <- verificationKeyHash <$> genVerificationKey
pure $ ChangeRequiredSigners [newSigner]
, SomeMutation Nothing MutateCommitToInitial <$> do
, SomeMutation (Just "datum not found") MutateCommitToInitial <$> do
-- we're satisfied with "datum not found" as the current version of the validator will consider
-- the initial input as if it were a commit input, hence fetching the datum which is expected
-- in a commit and complaining that it did not find it
(txIn, HealthyCommit{cardanoKey}) <- elements $ Map.toList healthyCommits
pure $ ChangeInput txIn (toUTxOContext $ mkInitialOutput testNetworkId testPolicyId cardanoKey) Nothing
, SomeMutation (Just "minting or burning is forbidden") MutateTokenMintingOrBurning
Expand Down
2 changes: 1 addition & 1 deletion hydra-plutus/src/Hydra/Contract/Head.hs
Expand Up @@ -182,7 +182,7 @@ checkCollectCom ctx@ScriptContext{scriptContextTxInfo = txInfo} (contestationPer
&& mustNotChangeParameters
&& everyoneHasCommitted
&& mustBeSignedByParticipant ctx headId
&& hasST headId outValue
&& traceIfFalse "ST not spent in transaction" (hasST headId outValue)
where
mustCollectUtxoHash =
traceIfFalse "incorrect utxo hash" $
Expand Down

0 comments on commit a35e743

Please sign in to comment.