Skip to content

Commit

Permalink
TxTrace: Use a Maybe (Var UTxO) for the spendable utxo
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo authored and v0d1ch committed May 7, 2024
1 parent c446c88 commit 1608266
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import Test.QuickCheck.StateModel (
Step ((:=)),
Var,
VarContext,
mkVar,
runActions,
)
import Text.Pretty.Simple (pShowNoColor)
Expand Down Expand Up @@ -104,8 +103,8 @@ prop_runActions actions =
data Model = Model
{ snapshots :: [SnapshotNumber]
, headState :: State
, utxoV :: Var UTxO
-- ^ Last known, spendable UTxO.
, utxoV :: Maybe (Var UTxO)
-- ^ Last known, spendable UTxO. Use 'openHeadUTxO' if not defined.
, alreadyContested :: [Actor]
}
deriving (Show)
Expand Down Expand Up @@ -171,7 +170,7 @@ instance StateModel Model where
Model
{ snapshots = []
, headState = Open
, utxoV = mkVar (-1)
, utxoV = Nothing
, alreadyContested = []
}

Expand All @@ -180,18 +179,23 @@ instance StateModel Model where
nextState m t result =
case t of
ProduceSnapshots snapshots -> m{snapshots = snapshots}
Decrement{} -> m{headState = Open}
Decrement{} ->
m
{ headState = Open
, utxoV = Just result
-- TODO: filter snapshots
}
Close{snapshotNumber} ->
m
{ headState = Closed
, utxoV = result
, utxoV = Just result
, snapshots = filter (> snapshotNumber) $ snapshots m
, alreadyContested = []
}
Contest{actor, snapshotNumber} ->
m
{ headState = Closed
, utxoV = result
, utxoV = Just result
, snapshots = filter (> snapshotNumber) $ snapshots m
, alreadyContested = actor : alreadyContested m
}
Expand Down Expand Up @@ -219,23 +223,23 @@ instance RunModel Model IO where
case action of
ProduceSnapshots _snapshots -> pure ()
Decrement{actor, snapshotNumber} -> do
-- FIXME: use lookupVar utxoV
let utxo = lookupVar utxoV
let utxo = maybe openHeadUTxO lookupVar utxoV
tx <- newDecrementTx utxo actor $ signedSnapshot snapshotNumber
validateTx utxo tx
observeTxMatching openHeadUTxO tx $ \case
Tx.Decrement{} -> Just ()
_ -> Nothing
pure $ adjustUTxO tx utxo
Close{actor, snapshotNumber} -> do
tx <- newCloseTx actor $ confirmedSnapshot snapshotNumber
validateTx openHeadUTxO tx
observeTxMatching openHeadUTxO tx $ \case
let utxo = maybe openHeadUTxO lookupVar utxoV
tx <- newCloseTx utxo actor $ confirmedSnapshot snapshotNumber
validateTx utxo tx
observeTxMatching utxo tx $ \case
Tx.Close{} -> Just ()
_ -> Nothing
pure $ adjustUTxO tx openHeadUTxO
pure $ adjustUTxO tx utxo
Contest{actor, snapshotNumber} -> do
let utxo = lookupVar utxoV
let utxo = maybe openHeadUTxO lookupVar utxoV
tx <- newContestTx utxo actor $ confirmedSnapshot snapshotNumber
validateTx utxo tx
observation@Tx.ContestObservation{contesters} <-
Expand Down Expand Up @@ -340,12 +344,12 @@ newDecrementTx utxo actor (snapshot, signatures) =
-- NOTE: This uses fixtures for headId, parties (alice, bob, carol),
-- contestation period and also claims to close at time 0 resulting in a
-- contestation deadline of 0 + cperiod.
newCloseTx :: HasCallStack => Actor -> ConfirmedSnapshot Tx -> IO Tx
newCloseTx actor snapshot =
newCloseTx :: HasCallStack => UTxO -> Actor -> ConfirmedSnapshot Tx -> IO Tx
newCloseTx utxo actor snapshot =
either (failure . show) pure $
close
(actorChainContext actor)
openHeadUTxO
utxo
(mkHeadId Fixture.testPolicyId)
Fixture.testHeadParameters
snapshot
Expand Down

0 comments on commit 1608266

Please sign in to comment.