Skip to content

Commit

Permalink
Handle more State/Event pairs
Browse files Browse the repository at this point in the history
Property is still failing because we do not hanlde CloseTx in all states
  • Loading branch information
abailly-iohk committed Jun 11, 2021
1 parent 85113a7 commit 89853fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/HeadLogic.hs
Expand Up @@ -200,7 +200,7 @@ update Environment{party, snapshotStrategy} ledger (HeadState p st) ev = case (s
in if canCollectCom party pt remainingTokens'
then newState p newHeadState [OnChainEffect CollectComTx]
else newState p newHeadState []
(CollectingState{}, OnChainEvent CollectComTx) ->
(_, OnChainEvent CollectComTx) ->
let u0 = initUTxO ledger -- TODO(SN): should construct u0 from the collected utxo
in newState
p
Expand Down Expand Up @@ -277,7 +277,7 @@ update Environment{party, snapshotStrategy} ledger (HeadState p st) ev = case (s
--
(ClosedState utxo, ShouldPostFanout) ->
newState p st [OnChainEffect (FanoutTx utxo)]
(ClosedState{}, OnChainEvent (FanoutTx utxo)) ->
(_, OnChainEvent (FanoutTx utxo)) ->
-- NOTE(SN): we might care if we are not in ClosedState
newState p FinalState [ClientEffect $ HeadIsFinalized utxo]
--
Expand Down
22 changes: 17 additions & 5 deletions hydra-node/test/Hydra/HeadLogicSpec.hs
Expand Up @@ -17,7 +17,7 @@ import Hydra.HeadLogic (
HeadState (..),
HeadStatus (..),
HydraMessage (..),
OnChainTx (InitTx),
OnChainTx (..),
Outcome (..),
SimpleHeadState (..),
Snapshot (..),
Expand All @@ -35,7 +35,7 @@ import Test.Hspec (
)
import Test.Hspec.Core.Spec (pending)
import Test.Hspec.QuickCheck (prop)
import Test.QuickCheck (Gen, Property, forAll, oneof)
import Test.QuickCheck (Gen, Property, elements, forAll)
import Test.QuickCheck.Instances.Time ()
import Test.QuickCheck.Property (collect)

Expand Down Expand Up @@ -77,11 +77,23 @@ spec = describe "Hydra Head Logic" $ do

genOnChainTx :: Gen (OnChainTx MockTx)
genOnChainTx =
oneof
[pure $ InitTx mempty]
elements
[ InitTx mempty
, -- TODO: maybe handle it differently? , CommitTx (ParticipationToken 1 1) 10
CollectComTx
, CloseTx
, ContestTx
, FanoutTx [ValidTx 1]
]

genHeadStatus :: Gen (HeadStatus MockTx)
genHeadStatus = oneof [pure InitState, pure FinalState]
genHeadStatus =
elements
[ InitState
, FinalState
, CollectingState mempty mempty
, OpenState (SimpleHeadState [] mempty mempty (Snapshot 0 mempty mempty))
]

defaultHeadParameters :: HeadParameters
defaultHeadParameters =
Expand Down

0 comments on commit 89853fc

Please sign in to comment.