Skip to content

Commit

Permalink
TxSpec: No need for property tests and suchThat
Browse files Browse the repository at this point in the history
We generate perfect ModelSnapshot anyway and then alter it (or alter the
UTxO) to get expected failures so we don't depend on anything arbitrary
here.
  • Loading branch information
v0d1ch committed Jun 5, 2024
1 parent b658744 commit 8f5a105
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import Hydra.Contract.HeadState qualified as HeadState
import Hydra.Contract.HeadTokens (headPolicyId, mkHeadTokenScript)
import Hydra.Contract.Initial qualified as Initial
import Hydra.Crypto (aggregate, sign)
import Hydra.Data.ContestationPeriod (addContestationPeriod, contestationPeriodFromDiffTime)
import Hydra.Data.ContestationPeriod (contestationPeriodFromDiffTime)
import Hydra.HeadId (HeadId (..))
import Hydra.Ledger (hashUTxO)
import Hydra.Ledger.Cardano (adaOnly, addInputs, addReferenceInputs, addVkInputs, emptyTxBody, genOneUTxOFor, genTxOutWithReferenceScript, genUTxO1, genUTxOAdaOnlyOfSize, genValue, genVerificationKey, unsafeBuildTransaction)
Expand All @@ -108,7 +108,6 @@ import Test.QuickCheck (
forAllBlind,
label,
property,
suchThat,
vectorOf,
withMaxSuccess,
(.&&.),
Expand Down Expand Up @@ -258,7 +257,7 @@ spec =
]

describe "Decrement" $ do
prop "Alter snapshots to trigger validator errors" $
it "Alter snapshots to trigger validator errors" $
forAllBlind arbitrary $ \chainContext -> do
let ctx@ChainContext{scriptRegistry} =
chainContext{ownVerificationKey = alicePVk, networkId = testNetworkId}
Expand Down Expand Up @@ -497,11 +496,10 @@ evaluateAndMatchError tx spendableUTxO expectedError =

genPerfectModelSnapshot :: Gen ModelSnapshot
genPerfectModelSnapshot = do
snapshotNumber <- arbitrary
(decommit, amount) <- arbitrary
let decommitUTxO = Map.fromList [(decommit, amount)]
snapshotUTxO <- arbitrary `suchThat` (\a -> all (> amount) (Map.elems a) && (decommit `elem` Map.keys a))
pure $ ModelSnapshot{snapshotNumber, snapshotUTxO, decommitUTxO}
snapshotUTxO' <- arbitrary
pure $ ModelSnapshot{snapshotNumber = 1, snapshotUTxO = Map.union snapshotUTxO' decommitUTxO, decommitUTxO}

-- | Check auxiliary data of a transaction against 'pparams' and whether the aux
-- data hash is consistent.
Expand Down

0 comments on commit 8f5a105

Please sign in to comment.