Skip to content

Commit

Permalink
Add mutation spec to check validator fails if the list of contesters …
Browse files Browse the repository at this point in the history
…is wrong in the output datum
  • Loading branch information
ffakenz committed Feb 6, 2023
1 parent 7ae84bb commit e0a6853
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion hydra-node/test/Hydra/Chain/Direct/Contract/Close.hs
Expand Up @@ -40,7 +40,10 @@ import Hydra.Ledger.Cardano.Evaluate (genValidityBoundsFromContestationPeriod)
import Hydra.Party (Party, deriveParty, partyToChain)
import Hydra.Snapshot (Snapshot (..), SnapshotNumber)
import Plutus.Orphans ()
<<<<<<< HEAD
import qualified Plutus.V1.Ledger.Api as Plutus
=======
>>>>>>> b306ecada (Add mutation spec to check validator fails if the list of contesters is wrong in the output datum)
import Plutus.V1.Ledger.Time (DiffMilliSeconds (..), fromMilliSeconds)
import Plutus.V2.Ledger.Api (BuiltinByteString, POSIXTime, toBuiltin, toData)
import Test.Hydra.Fixture (aliceSk, bobSk, carolSk)
Expand Down Expand Up @@ -280,7 +283,7 @@ genCloseMutation (tx, _utxo) =
]
, SomeMutation (Just "minting or burning is forbidden") MutateTokenMintingOrBurning
<$> (changeMintedTokens tx =<< genMintedOrBurnedValue)
, SomeMutation Nothing MutateContestors . ChangeOutput 0 <$> mutateCloseContesters
, SomeMutation Nothing MutateContesters . ChangeOutput 0 <$> mutateCloseContesters
]
where
genOversizedTransactionValidity = do
Expand Down
23 changes: 22 additions & 1 deletion hydra-node/test/Hydra/Chain/Direct/Contract/Contest.hs
Expand Up @@ -35,9 +35,10 @@ import Hydra.Ledger.Cardano.Evaluate (slotNoToUTCTime)
import Hydra.Party (Party, deriveParty, partyToChain)
import Hydra.Snapshot (Snapshot (..), SnapshotNumber)
import Plutus.Orphans ()
import qualified Plutus.V1.Ledger.Api as Plutus
import Plutus.V2.Ledger.Api (BuiltinByteString, toBuiltin, toData)
import Test.Hydra.Fixture (aliceSk, bobSk, carolSk)
import Test.QuickCheck (elements, oneof, suchThat)
import Test.QuickCheck (elements, oneof, suchThat, vectorOf)
import Test.QuickCheck.Gen (choose)
import Test.QuickCheck.Instances ()

Expand Down Expand Up @@ -242,10 +243,30 @@ genContestMutation
, headId = toPlutusCurrencySymbol testPolicyId
, contesters = [contester]
}
, SomeMutation Nothing MutateContesters . ChangeOutput 0 <$> mutateClosedContesters
]
where
headTxOut = fromJust $ txOuts' tx !!? 0

mutateClosedContesters :: Gen (TxOut CtxTx)
mutateClosedContesters = do
n <- elements [0, 2]
hashes <- vectorOf n genHash
let mutatedContesters = Plutus.PubKeyHash . toBuiltin <$> hashes
pure $ changeHeadOutputDatum (mutateContesters mutatedContesters) headTxOut

mutateContesters mutatedContesters = \case
Head.Closed{snapshotNumber, parties, contestationDeadline, headId, utxoHash} ->
Head.Closed
{ snapshotNumber
, utxoHash
, parties
, contestationDeadline
, headId
, contesters = mutatedContesters
}
st -> error $ "unexpected state " <> show st

mutateCloseUTxOHash :: Gen (TxOut CtxTx)
mutateCloseUTxOHash = do
mutatedUTxOHash <- genHash `suchThat` ((/= healthyContestUTxOHash) . toBuiltin)
Expand Down

0 comments on commit e0a6853

Please sign in to comment.