Skip to content

Commit

Permalink
TxTrace: increase number of positive actions
Browse files Browse the repository at this point in the history
This should provide "happier" paths, while still trying unhappy paths
~20% of the time.
  • Loading branch information
ch1bo authored and v0d1ch committed May 7, 2024
1 parent 523305e commit f8fa354
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,21 @@ instance StateModel Model where
oneof
[ do
actor <- elements allActors
snapshotNumber <- arbitrary
snapshotNumber <- latestSnapshot `orSometimes` arbitrary
pure $ Some $ Close{actor, snapshotNumber}
, do
actor <- elements allActors
snapshotNumber <- arbitrary
snapshotNumber <- (latestSnapshot + 1) `orSometimes` arbitrary
pure $ Some Decrement{actor, snapshotNumber}
]
Closed{} ->
oneof
[ do
snapshotNumber <-
frequency
[ (2, pure latestSnapshot)
, (1, arbitrary)
]
snapshotNumber <- latestSnapshot `orSometimes` arbitrary
pure . Some $ Fanout{snapshotNumber}
, do
actor <- elements allActors
snapshotNumber <- arbitrary
snapshotNumber <- (latestSnapshot + 1) `orSometimes` arbitrary
pure $ Some Contest{actor, snapshotNumber}
]
Final -> pure $ Some Stop
Expand Down Expand Up @@ -508,3 +504,8 @@ expectInvalid :: Monad m => TxResult -> PostconditionM m Bool
expectInvalid = \case
TxResult{validationError = Nothing} -> False <$ counterexamplePost "Expected to fail validation"
_ -> pure True

-- | Generate sometimes a value with given generator, bur more often just use
-- the given value.
orSometimes :: a -> Gen a -> Gen a
orSometimes a gen = frequency [(2, pure a), (1, gen)]

0 comments on commit f8fa354

Please sign in to comment.