diff --git a/hydra-node/src/Hydra/Chain/Direct/State.hs b/hydra-node/src/Hydra/Chain/Direct/State.hs index 659c71e7a3b..09e8ebdc4e2 100644 --- a/hydra-node/src/Hydra/Chain/Direct/State.hs +++ b/hydra-node/src/Hydra/Chain/Direct/State.hs @@ -125,7 +125,7 @@ import Hydra.Snapshot ( genConfirmedSnapshot, getSnapshot, ) -import Test.QuickCheck (choose, frequency, oneof, suchThat, vector) +import Test.QuickCheck (choose, frequency, getPositive, oneof, vector) import Test.QuickCheck.Gen (elements) import Test.QuickCheck.Modifiers (Positive (Positive)) @@ -1045,13 +1045,22 @@ genCollectComTx = do genDecrementTx :: Int -> Gen (ChainContext, OpenState, Tx) genDecrementTx numParties = do ctx <- genHydraContextFor numParties - (_, stOpen@OpenState{headId}) <- genStOpen ctx + (u0, stOpen@OpenState{headId}) <- genStOpen ctx cctx <- pickChainContext ctx - snapshot <- arbitrary `suchThat` (\Snapshot{utxoToDecommit} -> isJust utxoToDecommit) + snapshot <- do + number <- getPositive <$> arbitrary + (utxo, toDecommit) <- splitUTxO u0 + pure Snapshot{headId, number, confirmed = [], utxo, utxoToDecommit = Just toDecommit} signatures <- arbitrary let openUTxO = getKnownUTxO stOpen pure (cctx, stOpen, unsafeDecrement cctx headId (ctxHeadParameters ctx) openUTxO snapshot signatures) +splitUTxO :: UTxO -> Gen (UTxO, UTxO) +splitUTxO utxo = do + ix <- choose (0, length utxo) + let (p1, p2) = splitAt ix (UTxO.pairs utxo) + pure (UTxO.fromPairs p1, UTxO.fromPairs p2) + genCloseTx :: Int -> Gen (ChainContext, OpenState, Tx, ConfirmedSnapshot Tx) genCloseTx numParties = do ctx <- genHydraContextFor numParties diff --git a/hydra-node/src/Hydra/Snapshot.hs b/hydra-node/src/Hydra/Snapshot.hs index 7d0fc1731dc..9c22cfb0ef0 100644 --- a/hydra-node/src/Hydra/Snapshot.hs +++ b/hydra-node/src/Hydra/Snapshot.hs @@ -35,6 +35,7 @@ data Snapshot tx = Snapshot -- ^ The set of transactions that lead to 'utxo' , utxoToDecommit :: Maybe (UTxOType tx) -- ^ UTxO to be decommitted. Spec: Ûω + -- TODO: what is the difference between Noting and (Just mempty) here? } deriving stock (Generic)