Skip to content

Commit

Permalink
Fix the failing close with initial snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Apr 25, 2024
1 parent 1883d3a commit d109b65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 0 additions & 2 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,9 @@ closeTx scriptRegistry vk closing startSlotNo (endSlotNo, utcTime) openThreadOut
}

headOutputAfter =
traceShow headOutputBefore $
modifyTxOutDatum (const headDatumAfter) headOutputBefore

headDatumAfter =
traceShow snapshotNumber $
mkTxOutDatumInline
Head.Closed
{ snapshotNumber
Expand Down
22 changes: 13 additions & 9 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Close.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ healthyCloseTx =
openThreadOutput
(mkHeadId Fixture.testPolicyId)

datum = toUTxOContext (mkTxOutDatumInline healthyOpenHeadDatum)

lookupUTxO =
UTxO.singleton (healthyOpenHeadTxIn, healthyOpenHeadTxOut)
UTxO.singleton (healthyOpenHeadTxIn, healthyOpenHeadTxOut datum)
<> registryUTxO scriptRegistry

scriptRegistry = genScriptRegistry `generateWith` 42

openThreadOutput =
OpenThreadOutput
{ openThreadUTxO = (healthyOpenHeadTxIn, healthyOpenHeadTxOut)
{ openThreadUTxO = (healthyOpenHeadTxIn, healthyOpenHeadTxOut datum)
, openParties = healthyOnChainParties
, openContestationPeriod = healthyContestationPeriod
}
Expand Down Expand Up @@ -105,15 +107,17 @@ healthyCloseInitialTx =
openThreadOutput
(mkHeadId Fixture.testPolicyId)

initialDatum = toUTxOContext (mkTxOutDatumInline $ healthyOpenHeadDatum{Head.snapshotNumber = 0})

lookupUTxO =
UTxO.singleton (healthyOpenHeadTxIn, healthyOpenHeadTxOut)
UTxO.singleton (healthyOpenHeadTxIn, healthyOpenHeadTxOut initialDatum)
<> registryUTxO scriptRegistry

scriptRegistry = genScriptRegistry `generateWith` 42

openThreadOutput =
OpenThreadOutput
{ openThreadUTxO = (healthyOpenHeadTxIn, healthyOpenHeadTxOut)
{ openThreadUTxO = (healthyOpenHeadTxIn, healthyOpenHeadTxOut initialDatum)
, openParties = healthyOnChainParties
, openContestationPeriod = healthyContestationPeriod
}
Expand All @@ -134,12 +138,10 @@ healthyCloseUpperBoundPointInTime :: PointInTime
healthyOpenHeadTxIn :: TxIn
healthyOpenHeadTxIn = generateWith arbitrary 42

healthyOpenHeadTxOut :: TxOut CtxUTxO
healthyOpenHeadTxOut =
healthyOpenHeadTxOut :: TxOutDatum CtxUTxO -> TxOut CtxUTxO
healthyOpenHeadTxOut headTxOutDatum =
mkHeadOutput Fixture.testNetworkId Fixture.testPolicyId headTxOutDatum
& addParticipationTokens healthyParticipants
where
headTxOutDatum = toUTxOContext (mkTxOutDatumInline healthyOpenHeadDatum)

healthySnapshot :: Snapshot Tx
healthySnapshot =
Expand Down Expand Up @@ -359,7 +361,7 @@ genCloseMutation (tx, _utxo) =
[ ChangeOutput 0 (replacePolicyIdWith Fixture.testPolicyId otherHeadId headTxOut)
, ChangeInput
healthyOpenHeadTxIn
(replacePolicyIdWith Fixture.testPolicyId otherHeadId healthyOpenHeadTxOut)
(replacePolicyIdWith Fixture.testPolicyId otherHeadId $ healthyOpenHeadTxOut datum)
( Just $
toScriptData
( Head.Close
Expand Down Expand Up @@ -390,6 +392,8 @@ genCloseMutation (tx, _utxo) =

headTxOut = fromJust $ txOuts' tx !!? 0

datum = toUTxOContext (mkTxOutDatumInline healthyOpenHeadDatum)

data CloseInitialMutation
= MutateCloseContestationDeadline'
deriving stock (Generic, Show, Enum, Bounded)
Expand Down

0 comments on commit d109b65

Please sign in to comment.