Skip to content

Commit

Permalink
Contest Mutation: Add utxoToDecommit to the contest snapshot
Browse files Browse the repository at this point in the history
Exercise altering the hashes of utxo and utxoToDecommit to trigger the
contestation signature errors `SignatureVerificationFailed`.
  • Loading branch information
v0d1ch committed May 29, 2024
1 parent 2cb99a3 commit 32760e5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Contest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import Hydra.Chain.Direct.Contract.Mutation (
replaceParties,
replacePolicyIdWith,
replaceSnapshotNumber,
replaceUtxoHash,
replaceUtxoHash, replaceUtxoToDecommitHash,
)
import Hydra.Chain.Direct.Fixture (slotLength, systemStart, testNetworkId, testPolicyId)
import Hydra.Chain.Direct.Fixture qualified as Fixture
import Hydra.Chain.Direct.ScriptRegistry (genScriptRegistry, registryUTxO)
import Hydra.Chain.Direct.State (splitUTxO)
import Hydra.Chain.Direct.Tx (ClosedThreadOutput (..), contestTx, mkHeadId, mkHeadOutput)
import Hydra.ContestationPeriod (ContestationPeriod, fromChain)
import Hydra.Contract.Error (toErrorCode)
Expand Down Expand Up @@ -104,9 +105,9 @@ healthyContestSnapshot =
Snapshot
{ headId = mkHeadId testPolicyId
, number = healthyContestSnapshotNumber
, utxo = healthyContestUTxO
, utxo = fst healthyContestSnapshotUTxO
, confirmed = []
, utxoToDecommit = Nothing
, utxoToDecommit = Just (snd healthyContestSnapshotUTxO)
}

healthyContestSnapshotNumber :: SnapshotNumber
Expand All @@ -117,9 +118,16 @@ healthyContestUTxO =
(genOneUTxOFor healthyContesterVerificationKey `suchThat` (/= healthyClosedUTxO))
`generateWith` 42

healthyContestSnapshotUTxO :: (UTxO, UTxO)
healthyContestSnapshotUTxO = generateWith (splitUTxO healthyContestUTxO) 42

healthyContestUTxOHash :: BuiltinByteString
healthyContestUTxOHash =
toBuiltin $ hashUTxO @Tx healthyContestUTxO
toBuiltin $ hashUTxO @Tx (fst healthyContestSnapshotUTxO)

healthyContestUTxOToDecommitHash :: BuiltinByteString
healthyContestUTxOToDecommitHash =
toBuiltin $ hashUTxO @Tx (snd healthyContestSnapshotUTxO)

healthyClosedState :: Head.State
healthyClosedState =
Expand Down Expand Up @@ -306,6 +314,12 @@ genContestMutation (tx, _utxo) =
modifyInlineDatum
(replaceUtxoHash (toBuiltin mutatedUTxOHash))
headTxOut
, SomeMutation (pure $ toErrorCode SignatureVerificationFailed) MutateContestUTxOHash . ChangeOutput 0 <$> do
mutatedUTxOHash <- genHash `suchThat` ((/= healthyContestUTxOToDecommitHash) . toBuiltin)
pure $
modifyInlineDatum
(replaceUtxoToDecommitHash (toBuiltin mutatedUTxOHash))
headTxOut
, SomeMutation (pure $ toErrorCode SignatureVerificationFailed) SnapshotNotSignedByAllParties . ChangeInputHeadDatum <$> do
mutatedParties <- arbitrary `suchThat` (/= healthyOnChainParties)
pure $
Expand Down

0 comments on commit 32760e5

Please sign in to comment.