Skip to content

Commit

Permalink
Bring back the old functions' names in Close
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch authored and ch1bo committed Nov 29, 2022
1 parent 7696a1a commit 167feb0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Close.hs
Expand Up @@ -27,7 +27,6 @@ import Plutus.Orphans ()
import Plutus.V2.Ledger.Api (toBuiltin, toData)
import Test.Hydra.Fixture (aliceSk, bobSk, carolSk)
import Test.QuickCheck (arbitrarySizedNatural, elements, oneof, suchThat)
import Test.QuickCheck.Instances ()

--
-- CloseTx
Expand All @@ -41,16 +40,16 @@ healthyCloseTx =
closeTx
somePartyCardanoVerificationKey
healthyClosingSnapshot
pointInTime
startSlot
pointInTime
openThreadOutput

headInput = generateWith arbitrary 42
-- here we need to pass in contestation period when generating start/end tx validity slots/time
-- since if tx validity bound difference is bigger than contestation period our close validator
-- will fail
(startSlot, pointInTime) =
genPointInTimeWithSlotDifference (fromIntegral genContestationPeriodSeconds) `generateWith` 42
genPointInTimeWithSlotDifference (fromIntegral healthyContestationPeriodSeconds) `generateWith` 42
headResolvedInput =
mkHeadOutput testNetworkId testPolicyId headTxOutDatum
& addParticipationTokens healthyParties
Expand All @@ -74,15 +73,15 @@ healthyCloseUpperBoundSlotNo = arbitrary `generateWith` 42
healthyClosingSnapshot :: ClosingSnapshot
healthyClosingSnapshot =
CloseWithConfirmedSnapshot
{ snapshotNumber = genSnapshotNumber
{ snapshotNumber = healthySnapshotNumber
, closeUtxoHash = UTxOHash $ hashUTxO @Tx healthyCloseUTxO
, signatures = healthySignature genSnapshotNumber
, signatures = healthySignature healthySnapshotNumber
}

healthySnapshot :: Snapshot Tx
healthySnapshot =
Snapshot
{ number = genSnapshotNumber
{ number = healthySnapshotNumber
, utxo = healthyCloseUTxO
, confirmed = []
}
Expand All @@ -92,8 +91,8 @@ healthyCloseUTxO =
(genOneUTxOFor somePartyCardanoVerificationKey `suchThat` (/= healthyUTxO))
`generateWith` 42

genSnapshotNumber :: SnapshotNumber
genSnapshotNumber = genSnapShot `generateWith` 42
healthySnapshotNumber :: SnapshotNumber
healthySnapshotNumber = genSnapShot `generateWith` 42

healthyCloseDatum :: Head.State
healthyCloseDatum =
Expand All @@ -104,12 +103,12 @@ healthyCloseDatum =
}

healthyContestationPeriod :: OnChain.ContestationPeriod
healthyContestationPeriod = OnChain.contestationPeriodFromDiffTime $ fromInteger genContestationPeriodSeconds
healthyContestationPeriod = OnChain.contestationPeriodFromDiffTime $ fromInteger healthyContestationPeriodSeconds

-- NB: We don't want to wait too long for contestation period to pass
-- so constraining this to < 100
genContestationPeriodSeconds :: Integer
genContestationPeriodSeconds = arbitrary `suchThat` (< 100) `generateWith` 42
healthyContestationPeriodSeconds :: Integer
healthyContestationPeriodSeconds = arbitrary `suchThat` (< 100) `generateWith` 42

healthyUTxO :: UTxO
healthyUTxO = genOneUTxOFor somePartyCardanoVerificationKey `generateWith` 42
Expand Down Expand Up @@ -160,8 +159,8 @@ genCloseMutation (tx, _utxo) =
[ SomeMutation MutateSignatureButNotSnapshotNumber . ChangeHeadRedeemer <$> do
closeRedeemer (number healthySnapshot) <$> (arbitrary :: Gen (MultiSignature (Snapshot Tx)))
, SomeMutation MutateSnapshotNumberButNotSignature . ChangeHeadRedeemer <$> do
mutatedSnapshotNumber <- arbitrarySizedNatural `suchThat` (\n -> n /= genSnapshotNumber && n > 0)
pure (closeRedeemer mutatedSnapshotNumber $ healthySignature genSnapshotNumber)
mutatedSnapshotNumber <- arbitrarySizedNatural `suchThat` (\n -> n /= healthySnapshotNumber && n > 0)
pure (closeRedeemer mutatedSnapshotNumber $ healthySignature healthySnapshotNumber)
, SomeMutation MutateSnapshotToIllFormedValue . ChangeHeadRedeemer <$> do
mutatedSnapshotNumber <- arbitrary `suchThat` (< 0)
let mutatedSignature =
Expand Down Expand Up @@ -192,9 +191,9 @@ genCloseMutation (tx, _utxo) =
, SomeMutation MutateUpperValidityToBeFarInTheFuture <$> do
muchGreaterThanContestationPeriod <-
SlotNo . fromIntegral
<$> arbitrary `suchThat` (> genContestationPeriodSeconds)
<$> arbitrary `suchThat` (> healthyContestationPeriodSeconds)
let mutatedUpperBound = healthyCloseUpperBoundSlotNo + muchGreaterThanContestationPeriod
deadlineUTCTime = addUTCTime (fromInteger genContestationPeriodSeconds) (slotNoToUTCTime mutatedUpperBound)
deadlineUTCTime = addUTCTime (fromInteger healthyContestationPeriodSeconds) (slotNoToUTCTime mutatedUpperBound)
let doMutation = \case
Head.Closed{snapshotNumber, utxoHash, parties} ->
Head.Closed
Expand Down Expand Up @@ -239,7 +238,7 @@ genCloseMutation (tx, _utxo) =
mutateClosedContestationDeadline = do
-- NOTE: we need to be sure the generated contestation period is large enough to have an impact on the on-chain
-- deadline computation, which means having a resolution of seconds instead of the default picoseconds
contestationPeriodSeconds <- arbitrary @Integer `suchThat` (/= genContestationPeriodSeconds)
contestationPeriodSeconds <- arbitrary @Integer `suchThat` (/= healthyContestationPeriodSeconds)
pure $ changeHeadOutputDatum (mutateContestationDeadline contestationPeriodSeconds) headTxOut

mutateContestationDeadline contestationPeriod = \case
Expand Down

0 comments on commit 167feb0

Please sign in to comment.