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 0a069c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 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,14 +204,14 @@ 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
Expand Down
9 changes: 5 additions & 4 deletions hydra-plutus/src/Hydra/Contract/Util.hs
Expand Up @@ -20,10 +20,11 @@ hydraHeadV1 = "HydraHeadV1"
-- 'CurrencySymbol' and 'TokenName' of 'hydraHeadV1'
hasST :: CurrencySymbol -> Value -> Bool
hasST headPolicyId v =
isJust $
find
(\(cs, tokenMap) -> cs == headPolicyId && hasHydraToken tokenMap)
(Map.toList $ getValue v)
traceIfFalse "ST not spent in transaction" $
isJust $
find
(\(currencySymbol, tokenMap) -> currencySymbol == headPolicyId && hasHydraToken tokenMap)
(Map.toList $ getValue v)
where
hasHydraToken tm =
isJust $ find (\(tn, q) -> q == 1 && TokenName hydraHeadV1 == tn) (Map.toList tm)
Expand Down

0 comments on commit 0a069c3

Please sign in to comment.