tests
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.BehaviorSpec

Synopsis

Documentation

spec :: Spec Source #

waitUntil :: (HasCallStack, MonadThrow m, MonadAsync m, MonadTimer 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 :: (HasCallStack, MonadThrow m, MonadAsync m, MonadTimer m) => [TestHydraClient tx m] -> (ServerOutput tx -> Bool) -> m () Source #

Wait for some output to match some predicate eventually. 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.

waitMatch :: MonadThrow m => TestHydraClient tx m -> (ServerOutput tx -> Maybe a) -> m a Source #

Wait for an output matching the predicate and extracting some value. This will loop forever until a match has been found.

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) => (SimulatedChainNetwork SimpleTx m -> m ()) -> m () 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.

class IsChainState a => IsChainStateTest a where Source #

Class to manipulate the chain state by advancing it's slot in simulatedChainAndNetwork.

Methods

advanceSlot :: ChainStateType a -> ChainStateType a Source #

Instances

Instances details
IsChainStateTest Tx Source # 
Instance details

Defined in Hydra.BehaviorSpec

Methods

advanceSlot :: ChainStateType Tx -> ChainStateType Tx Source #

IsChainStateTest SimpleTx Source # 
Instance details

Defined in Hydra.BehaviorSpec

Methods

advanceSlot :: ChainStateType SimpleTx -> ChainStateType SimpleTx Source #

simulatedChainAndNetwork :: forall m tx. (MonadTime m, MonadDelay m, MonadAsync m, IsChainStateTest tx) => ChainStateType tx -> m (SimulatedChainNetwork tx m) Source #

Creates a simulated chain and network to which HydraNodes can be connected to using $sel:connectNode:SimulatedChainNetwork. NOTE: The $sel:tickThread:SimulatedChainNetwork needs to be canceled after use. Use withSimulatedChainAndNetwork instead where possible.

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

createMockNetwork :: MonadSTM m => DraftHydraNode tx m -> TVar m [HydraNode tx m] -> Network m (Message tx) Source #

toOnChainTx :: 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 ServerOutput and PostChainTx.

testContestationPeriod :: ContestationPeriod Source #

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

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

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

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

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

matchFanout :: PostChainTx tx -> Bool Source #

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

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

shortLabel :: SigningKey HydraKey -> String Source #

Provide a quick and dirty to way to label stuff from a signing key