Skip to content

Commit d5ac680

Browse files
committed
Fix genDecrementTx to use correct snapshots
1 parent 795b0d3 commit d5ac680

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

hydra-node/src/Hydra/Chain/Direct/State.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ import Hydra.Snapshot (
125125
genConfirmedSnapshot,
126126
getSnapshot,
127127
)
128-
import Test.QuickCheck (choose, frequency, oneof, suchThat, vector)
128+
import Test.QuickCheck (choose, frequency, getPositive, oneof, vector)
129129
import Test.QuickCheck.Gen (elements)
130130
import Test.QuickCheck.Modifiers (Positive (Positive))
131131

@@ -1045,13 +1045,22 @@ genCollectComTx = do
10451045
genDecrementTx :: Int -> Gen (ChainContext, OpenState, Tx)
10461046
genDecrementTx numParties = do
10471047
ctx <- genHydraContextFor numParties
1048-
(_, stOpen@OpenState{headId}) <- genStOpen ctx
1048+
(u0, stOpen@OpenState{headId}) <- genStOpen ctx
10491049
cctx <- pickChainContext ctx
1050-
snapshot <- arbitrary `suchThat` (\Snapshot{utxoToDecommit} -> isJust utxoToDecommit)
1050+
snapshot <- do
1051+
number <- getPositive <$> arbitrary
1052+
(utxo, toDecommit) <- splitUTxO u0
1053+
pure Snapshot{headId, number, confirmed = [], utxo, utxoToDecommit = Just toDecommit}
10511054
signatures <- arbitrary
10521055
let openUTxO = getKnownUTxO stOpen
10531056
pure (cctx, stOpen, unsafeDecrement cctx headId (ctxHeadParameters ctx) openUTxO snapshot signatures)
10541057

1058+
splitUTxO :: UTxO -> Gen (UTxO, UTxO)
1059+
splitUTxO utxo = do
1060+
ix <- choose (0, length utxo)
1061+
let (p1, p2) = splitAt ix (UTxO.pairs utxo)
1062+
pure (UTxO.fromPairs p1, UTxO.fromPairs p2)
1063+
10551064
genCloseTx :: Int -> Gen (ChainContext, OpenState, Tx, ConfirmedSnapshot Tx)
10561065
genCloseTx numParties = do
10571066
ctx <- genHydraContextFor numParties

hydra-node/src/Hydra/Snapshot.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ data Snapshot tx = Snapshot
3535
-- ^ The set of transactions that lead to 'utxo'
3636
, utxoToDecommit :: Maybe (UTxOType tx)
3737
-- ^ UTxO to be decommitted. Spec: Ûω
38+
-- TODO: what is the difference between Noting and (Just mempty) here?
3839
}
3940
deriving stock (Generic)
4041

@@ -179,6 +180,7 @@ genConfirmedSnapshot headId minSn utxo sks
179180
-- snapshots
180181
number <- arbitrary `suchThat` (> minSn)
181182
-- TODO: check whether we are fine with this not producing any decommitting utxo ever
183+
-- TODO: use splitUTxO generator
182184
let snapshot = Snapshot{headId, number, utxo, confirmed = [], utxoToDecommit = mempty}
183185
let signatures = aggregate $ fmap (`sign` snapshot) sks
184186
pure $ ConfirmedSnapshot{snapshot, signatures}

hydra-node/test/Hydra/Chain/Direct/Contract/Decrement.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ healthySnapshotNumber = 1
9999

100100
healthySnapshot :: Snapshot Tx
101101
healthySnapshot =
102+
-- TODO: use splitUTxO generator
102103
let (utxoToDecommit', utxo) = splitDecommitUTxO healthyUTxO
103104
in Snapshot
104105
{ headId = mkHeadId testPolicyId

0 commit comments

Comments
 (0)