Skip to content

Commit 9de8ee1

Browse files
committed
Increase frequency of negative Decrement actions being produced
And we also make sure that when we produce positive Decrements its because there is some utxo to decrement and not empty.
1 parent 6ae8b5d commit 9de8ee1

File tree

1 file changed

+32
-44
lines changed

1 file changed

+32
-44
lines changed

hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ prop_traces =
8989
& cover 1 (countContests steps >= 2) "has multiple contests"
9090
& cover 5 (closeNonInitial steps) "close with non initial snapshots"
9191
& cover 5 (hasDecrement steps) "has successful decrements"
92-
& cover 1 (hasNegativeDecrement steps) "has negative decrements"
9392
where
9493
hasFanout =
9594
any $
@@ -125,13 +124,7 @@ prop_traces =
125124
hasDecrement =
126125
any $
127126
\(_ := ActionWithPolarity{polarAction, polarity}) -> case polarAction of
128-
Decrement{} -> polarity == PosPolarity
129-
_ -> False
130-
131-
hasNegativeDecrement =
132-
any $
133-
\(_ := ActionWithPolarity{polarAction, polarity}) -> case polarAction of
134-
Decrement{} -> polarity == NegPolarity
127+
Decrement{snapshot} -> polarity == PosPolarity && (not . null $ decommitUTxO snapshot)
135128
_ -> False
136129

137130
prop_runActions :: Actions Model -> Property
@@ -227,33 +220,38 @@ instance StateModel Model where
227220
arbitraryAction _lookup Model{headState, latestSnapshot, utxoInHead} =
228221
case headState of
229222
Open{} ->
230-
oneof $
231-
[ do
232-
actor <- elements allActors
233-
someUTxOToDecrement <-
234-
if not (null utxoInHead) then oneof $ pure <$> [utxoInHead] else pure $ Set.fromList []
235-
236-
snapshot <-
237-
ModelSnapshot
238-
{ snapshotNumber = latestSnapshot
239-
, snapshotUTxO = utxoInHead
240-
, decommitUTxO = someUTxOToDecrement
241-
}
242-
`orArbitrary` arbitrary
243-
pure $ Some $ Close{actor, snapshot}
244-
]
245-
<> [ do
223+
frequency $
224+
[
225+
( 1
226+
, do
246227
actor <- elements allActors
247-
someUTxOToDecrement <- oneof $ pure <$> Set.toList utxoInHead
228+
someUTxOToDecrement <-
229+
if not (null utxoInHead) then oneof $ pure <$> [utxoInHead] else pure $ Set.fromList []
248230
snapshot <-
249231
ModelSnapshot
250-
{ snapshotNumber = latestSnapshot + 1
251-
, snapshotUTxO = Set.delete someUTxOToDecrement utxoInHead
252-
, decommitUTxO = Set.fromList [someUTxOToDecrement]
232+
{ snapshotNumber = latestSnapshot
233+
, snapshotUTxO = utxoInHead
234+
, decommitUTxO = someUTxOToDecrement
253235
}
254236
`orArbitrary` arbitrary
255-
pure $ Some Decrement{actor, snapshot}
256-
| not (null utxoInHead)
237+
pure $ Some $ Close{actor, snapshot}
238+
)
239+
]
240+
<> [
241+
( 10
242+
, do
243+
actor <- elements allActors
244+
someUTxOToDecrement <-
245+
if not (null utxoInHead) then oneof $ pure <$> [utxoInHead] else pure $ Set.fromList []
246+
snapshot <-
247+
ModelSnapshot
248+
{ snapshotNumber = latestSnapshot + 1
249+
, snapshotUTxO = utxoInHead Set.\\ someUTxOToDecrement
250+
, decommitUTxO = someUTxOToDecrement
251+
}
252+
`orMoreOftenArbitrary` arbitrary
253+
pure $ Some Decrement{actor, snapshot}
254+
)
257255
]
258256
Closed{} ->
259257
oneof $
@@ -313,23 +311,10 @@ instance StateModel Model where
313311
-- False, the action is discarded (e.g. it's invalid or we don't want to see
314312
-- it tried to perform).
315313
validFailingAction :: Model -> Action Model a -> Bool
316-
validFailingAction Model{headState, latestSnapshot, alreadyContested, utxoInHead} = \case
314+
validFailingAction Model{headState, utxoInHead} = \case
317315
Decrement{snapshot} ->
318316
headState == Open
319317
&& decommitUTxO snapshot `Set.isSubsetOf` utxoInHead
320-
-- Close{snapshot} ->
321-
-- headState == Open
322-
-- && snapshotNumber snapshot < latestSnapshot
323-
-- Contest{actor, snapshot} ->
324-
-- headState == Closed
325-
-- && ( snapshotNumber snapshot <= latestSnapshot
326-
-- || actor `elem` alreadyContested
327-
-- )
328-
-- Fanout{snapshot} ->
329-
-- headState == Closed
330-
-- && ( snapshotNumber snapshot /= latestSnapshot
331-
-- || snapshotUTxO snapshot /= utxoInHead
332-
-- )
333318
_ -> True
334319

335320
nextState :: Model -> Action Model a -> Var a -> Model
@@ -720,3 +705,6 @@ expectInvalid = \case
720705
-- the given value.
721706
orArbitrary :: a -> Gen a -> Gen a
722707
orArbitrary a gen = frequency [(1, pure a), (1, gen)]
708+
709+
orMoreOftenArbitrary :: a -> Gen a -> Gen a
710+
orMoreOftenArbitrary a gen = frequency [(1, pure a), (10, gen)]

0 commit comments

Comments
 (0)