hydra-node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.BehaviorSpec

Synopsis

Documentation

spec :: Spec Source #

waitUntil :: (HasCallStack, MonadThrow m, MonadAsync m, MonadTimer m, MonadLabelledSTM m, IsChainState tx) => [TestHydraClient tx m] -> ServerOutput tx -> m () Source #

Wait for some output at some node(s) to be produced eventually. See waitUntilMatch for how long it waits.

waitUntilMatch :: (Show (ServerOutput tx), HasCallStack, MonadThrow m, MonadAsync m, MonadTimer m, MonadLabelledSTM m, Eq a, Show a, IsChainState tx) => [TestHydraClient tx m] -> (ServerOutput tx -> Maybe a) -> m a Source #

Wait for a server output to match some predicate eventually. If a client message is received instead, this fails. This will not wait forever, but for a long time (1 month) to get a nice error location. Should not be an issue when used within shouldRunInSim, this was even 1000 years before - but we since we are having the protocol produce Tick events constantly this would be fully simulated to the end.

newtype NodeId Source #

Constructors

Node Natural 

data TestHydraClient tx m Source #

A thin client layer around HydraNode to be interact with it through $sel:send:TestHydraClient, $sel:waitForNext:TestHydraClient, access all outputs and inject events through the test chain.

Constructors

TestHydraClient 

Fields

data SimulatedChainNetwork tx m Source #

A simulated chain that just echoes PostChainTx as Observations of OnChainTx onto all connected nodes. It can also $sel:rollbackAndForward:SimulatedChainNetwork any number of these "transactions".

Constructors

SimulatedChainNetwork 

Fields

withSimulatedChainAndNetwork :: (MonadTime m, MonadDelay m, MonadAsync m, MonadThrow m, MonadLabelledSTM m) => (SimulatedChainNetwork SimpleTx m -> m a) -> m a Source #

With-pattern wrapper around simulatedChainAndNetwork which does cancel the $sel:tickThread:SimulatedChainNetwork. Also, this will fix tx to SimpleTx so that it can pick an initial chain state to play back to our test nodes. NOTE: The simulated network has a block time of 20 (simulated) seconds.

withSimulatedChainAndSlowNetwork Source #

Arguments

:: (MonadTime m, MonadDelay m, MonadAsync m, MonadThrow m, MonadLabelledSTM m) 
=> DiffTime

Network message delay

-> DiffTime

Chain observation delay

-> (SimulatedChainNetwork SimpleTx m -> m a) 
-> m a 

Simulated chain and network where the network and/or chain observations can be delivered with a configurable delay. Handy to reproduce race conditions related to message ordering.

simulatedChainAndNetworkUsing :: forall m. (MonadTime m, MonadDelay m, MonadAsync m, MonadLabelledSTM m) => (DraftHydraNode SimpleTx m -> TVar m [HydraNode SimpleTx m] -> Network m (Message SimpleTx)) -> DiffTime -> ChainStateType SimpleTx -> m (SimulatedChainNetwork SimpleTx m) Source #

Like simulatedChainAndNetwork but accepts a custom network factory and an optional chain observation delay. When chainDelay > 0, each chain event is delivered to nodes asynchronously after that delay, allowing tests to reproduce races where nodes observe the same on-chain event at different times.

handleChainEvent :: HydraNode tx m -> ChainEvent tx -> m () Source #

createMockNetworkWithDelay :: (MonadAsync m, MonadDelay m) => DiffTime -> DraftHydraNode tx m -> TVar m [HydraNode tx m] -> Network m (Message tx) Source #

Delivers messages asynchronously after a configurable delay. When the delay exceeds the chain's block time (20s), on-chain events arrive at nodes before network echoes, reproducing version-race conditions seen in production.

toOnChainTx :: IsTx tx => UTCTime -> PostChainTx tx -> OnChainTx tx Source #

Derive an OnChainTx from PostChainTx to simulate a "perfect" chain. NOTE: This implementation announces hard-coded contestationDeadlines. Also, all heads will have the same OpenState and OpenState.

nothingHappensFor :: (MonadTimer m, MonadThrow m, IsChainState tx) => TestHydraClient tx m -> NominalDiffTime -> m () Source #

withHydraNode :: forall s a. Secret (SigningKey HydraKey) -> [Party] -> SimulatedChainNetwork SimpleTx (IOSim s) -> (TestHydraClient SimpleTx (IOSim s) -> IOSim s a) -> IOSim s a Source #

withHydraNode' :: DepositPeriod -> Secret (SigningKey HydraKey) -> [Party] -> SimulatedChainNetwork SimpleTx (IOSim s) -> (TestHydraClient SimpleTx (IOSim s) -> IOSim s b) -> IOSim s b Source #

createTestHydraClient :: MonadSTM m => TQueue m (ServerOutput tx) -> TQueue m (ClientMessage tx) -> TVar m [ServerOutput tx] -> HydraNode tx m -> TestHydraClient tx m Source #

createHydraNode :: (IsChainState tx, MonadDelay m, MonadAsync m, MonadLabelledSTM m, MonadThrow m) => Tracer m (HydraNodeLog tx) -> Ledger tx -> ChainStateType tx -> Secret (SigningKey HydraKey) -> [Party] -> TQueue m (ServerOutput tx) -> TQueue m (ClientMessage tx) -> TVar m [ServerOutput tx] -> SimulatedChainNetwork tx m -> ContestationPeriod -> DepositPeriod -> m (HydraNode tx m) Source #

openHead :: TestHydraClient SimpleTx (IOSim s) -> IOSim s () Source #

openHead2 :: TestHydraClient SimpleTx (IOSim s) -> TestHydraClient SimpleTx (IOSim s) -> IOSim s () Source #

depositHead :: SimulatedChainNetwork SimpleTx (IOSim s) -> [TestHydraClient SimpleTx (IOSim s)] -> UTxOType SimpleTx -> IOSim s () Source #

headIsClosed :: HeadId -> ServerOutput tx -> Bool Source #

assertHeadIsClosed :: (HasCallStack, MonadThrow m) => ServerOutput tx -> m () Source #

assertHeadIsClosedWith :: (HasCallStack, MonadThrow m) => SnapshotNumber -> ServerOutput tx -> m () Source #

shortLabel :: Secret (SigningKey HydraKey) -> String Source #

Provide a quick and dirty way to label stuff from a signing key. Uses the *verification* key (which is public) for the label, since Show on a 'SigningKey HydraKey' is forbidden by the type system.

getHeadUTxO :: HeadState tx -> Maybe (UTxOType tx) Source #

Get the head UTxO from open HeadState.

getConfirmedSnapshotFromNode :: (HasCallStack, MonadThrow m) => TestHydraClient tx m -> m (ConfirmedSnapshot tx) Source #

Get the latest confirmed snapshot from an open node, failing if the node is not in an open state.