hydra-node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.HeadLogicSpec

Description

Unit tests of the protocol logic in HeadLogic. These are very fine grained and specific to individual steps in the protocol. More high-level of the protocol logic, especially between multiple parties can be found in BehaviorSpec.

Synopsis

Documentation

spec :: Spec Source #

Properties

genClosedState :: Gen (NodeState SimpleTx) Source #

Utilities

receiveMessage :: Message tx -> Input tx Source #

Create a network input about a received protocol message with default ttl and alice as the sender.

receiveMessageFrom :: Party -> Message tx -> Input tx Source #

Create a network input about a received protocol message with default ttl from given sender.

chainEffect :: PostChainTx SimpleTx -> Effect SimpleTx Source #

Create a chain effect with fixed chain state and slot.

observeTxAtSlot :: ChainSlot -> OnChainTx SimpleTx -> Input SimpleTx Source #

Create an observation chain input with chain state at given slot.

observeTx :: OnChainTx SimpleTx -> Input SimpleTx Source #

Create an observation chain input with fixed chain state and slot.

connectivityChanged :: TTL -> Connectivity -> Input SimpleTx Source #

inIdleState :: NodeState SimpleTx Source #

inUnsyncedIdleState :: NodeState SimpleTx Source #

inOpenState :: [Party] -> NodeState SimpleTx Source #

reqDecDecommitTx :: SimpleTx Source #

The decommit the reqDec pending-commit tests request. No inputs, so it applies to any CoordinatedHeadState and the outcome turns purely on the pending-commit guard.

reqDecDepositTxId :: TxIdType SimpleTx Source #

reqDecDepositedUTxO :: UTxOType SimpleTx Source #

The UTxO the registered deposit records, so the tests can assert the reported WaitReason instead of the mempty that a failed lookup would yield whether or not the guard is right.

reqDecStateWith :: [Party] -> Maybe DepositStatus -> NodeState SimpleTx Source #

An open state whose $sel:currentDepositTxId:CoordinatedHeadState is set, with the deposit registered at the given status. Nothing registers no deposit at all, modelling one that has already been recovered: DepositRecovered deletes the map entry but leaves $sel:currentDepositTxId:CoordinatedHeadState pointing at it.

inOpenState' :: [Party] -> CoordinatedHeadState SimpleTx -> NodeState SimpleTx Source #

inClosedState :: [Party] -> NodeState SimpleTx Source #

inClosedState' :: [Party] -> ConfirmedSnapshot SimpleTx -> NodeState SimpleTx Source #

inFanoutProgressWith :: [Party] -> Set SimpleTxOut -> FanoutMode SimpleTx -> NodeState SimpleTx Source #

A head mid partial-fanout (on-chain FanoutProgress) with the given still-to-distribute set and FanoutMode. StateChanged is a non-empty placeholder so the head datum is treated as FanoutProgress (some outputs already distributed).

inAutoDrainProgress :: [Party] -> Set SimpleTxOut -> NodeState SimpleTx Source #

Like inFanoutProgressWith but in AutoDrain mode, as if a plain Fanout kicked off the (chunked) fanout.

getConfirmedSnapshot :: IsTx tx => NodeState tx -> Maybe (Snapshot tx) Source #

data StepState tx Source #

Constructors

StepState 

Fields

runHeadLogic :: Monad m => Environment -> Ledger tx -> NodeState tx -> StateT (StepState tx) m a -> m a Source #

getState :: MonadState (StepState tx) m => m (NodeState tx) Source #

Retrieves the latest NodeState from within runHeadLogic.

step :: (MonadState (StepState tx) m, IsChainState tx, MonadTime m) => Input tx -> m (Outcome tx) Source #

Calls update and aggregate to drive the runHeadLogic monad forward.

hasEffect :: (HasCallStack, IsChainState tx) => Outcome tx -> Effect tx -> IO () Source #

assertWait :: (HasCallStack, IsChainState tx) => Outcome tx -> WaitReason tx -> IO () Source #

effectsOf :: Outcome tx -> [Effect tx] Source #

The effects produced by an outcome (empty for Wait/Error).

hasEffectSatisfying :: (HasCallStack, IsChainState tx) => Outcome tx -> (Effect tx -> Bool) -> IO () Source #

hasNoEffectSatisfying :: (HasCallStack, IsChainState tx) => Outcome tx -> (Effect tx -> Bool) -> IO () Source #

hasStateChangedSatisfying :: (HasCallStack, IsChainState tx) => Outcome tx -> (StateChanged tx -> Bool) -> IO () Source #

hasNoStateChangedSatisfying :: (HasCallStack, IsChainState tx) => Outcome tx -> (StateChanged tx -> Bool) -> IO () Source #

nowFromSlot :: (MonadFail m, MonadTime m) => ChainSlot -> m UTCTime Source #

mkTimeHandleAt :: SlotNo -> UTCTime -> TimeHandle Source #

Create a TimeHandle for a given slot and current wall-clock time. * Assumes 1-second slots (as in the devnet). * SystemStart is derived so that the given slot corresponds to the given time. * EraHistory is constructed to have a horizon sufficiently far in the future to accommodate time conversions.

catchingUp :: IsTx tx => HeadState tx -> NodeState tx Source #

inSync :: IsTx tx => HeadState tx -> NodeState tx Source #

zeroChainPointTime :: ChainPointTime Source #

testSnapshot :: forall tx. IsTx tx => SnapshotNumber -> SnapshotVersion -> [tx] -> UTxOType tx -> Snapshot tx Source #