Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- spec :: Spec
- waitUntil :: (HasCallStack, MonadThrow m, MonadAsync m, MonadTimer m, IsChainState tx) => [TestHydraClient tx m] -> ServerOutput tx -> m ()
- waitUntilMatch :: (Show (ServerOutput tx), HasCallStack, MonadThrow m, MonadAsync m, MonadTimer m) => [TestHydraClient tx m] -> (ServerOutput tx -> Bool) -> m ()
- waitMatch :: MonadThrow m => TestHydraClient tx m -> (ServerOutput tx -> Maybe a) -> m a
- data TestHydraClient tx m = TestHydraClient {
- send :: ClientInput tx -> m ()
- waitForNext :: m (ServerOutput tx)
- injectChainEvent :: ChainEvent tx -> m ()
- serverOutputs :: m [ServerOutput tx]
- queryState :: m (HeadState tx)
- data SimulatedChainNetwork tx m = SimulatedChainNetwork {
- connectNode :: DraftHydraNode tx m -> m (HydraNode tx m)
- tickThread :: Async m ()
- rollbackAndForward :: Natural -> m ()
- simulateCommit :: (Party, UTxOType tx) -> m ()
- closeWithInitialSnapshot :: (Party, UTxOType tx) -> m ()
- dummySimulatedChainNetwork :: SimulatedChainNetwork tx m
- withSimulatedChainAndNetwork :: (MonadTime m, MonadDelay m, MonadAsync m) => (SimulatedChainNetwork SimpleTx m -> m ()) -> m ()
- class IsChainState a => IsChainStateTest a where
- advanceSlot :: ChainStateType a -> ChainStateType a
- simulatedChainAndNetwork :: forall m tx. (MonadTime m, MonadDelay m, MonadAsync m, IsChainStateTest tx) => ChainStateType tx -> m (SimulatedChainNetwork tx m)
- handleChainEvent :: HydraNode tx m -> ChainEvent tx -> m ()
- createMockNetwork :: MonadSTM m => DraftHydraNode tx m -> TVar m [HydraNode tx m] -> Network m (Message tx)
- toOnChainTx :: IsTx tx => UTCTime -> PostChainTx tx -> OnChainTx tx
- testContestationPeriod :: ContestationPeriod
- nothingHappensFor :: (MonadTimer m, MonadThrow m, IsChainState tx) => TestHydraClient tx m -> NominalDiffTime -> m ()
- withHydraNode :: forall s a. SigningKey HydraKey -> [Party] -> SimulatedChainNetwork SimpleTx (IOSim s) -> (TestHydraClient SimpleTx (IOSim s) -> IOSim s a) -> IOSim s a
- createTestHydraClient :: MonadSTM m => TQueue m (ServerOutput tx) -> TVar m [ServerOutput tx] -> HydraNode tx m -> TestHydraClient tx m
- 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)
- openHead :: SimulatedChainNetwork SimpleTx (IOSim s) -> TestHydraClient SimpleTx (IOSim s) -> TestHydraClient SimpleTx (IOSim s) -> IOSim s ()
- matchFanout :: PostChainTx tx -> Bool
- assertHeadIsClosed :: (HasCallStack, MonadThrow m) => ServerOutput tx -> m ()
- assertHeadIsClosedWith :: (HasCallStack, MonadThrow m) => SnapshotNumber -> ServerOutput tx -> m ()
- shortLabel :: SigningKey HydraKey -> String
Documentation
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 :: (Show (ServerOutput tx), 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.
TestHydraClient | |
|
data SimulatedChainNetwork tx m Source #
A simulated chain that just echoes PostChainTx
as Observation
s of
OnChainTx
onto all connected nodes. It can also $sel:rollbackAndForward:SimulatedChainNetwork
any
number of these "transactions".
SimulatedChainNetwork | |
|
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.
NOTE: The simulated network has a block time of 20 (simulated) seconds.
class IsChainState a => IsChainStateTest a where Source #
Class to manipulate the chain state by advancing it's slot in
simulatedChainAndNetwork
.
advanceSlot :: ChainStateType a -> ChainStateType a Source #
Instances
IsChainStateTest Tx Source # | |
Defined in Hydra.BehaviorSpec advanceSlot :: ChainStateType Tx -> ChainStateType Tx Source # | |
IsChainStateTest SimpleTx Source # | |
Defined in Hydra.BehaviorSpec 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 HydraNode
s can be
connected to using $sel:connectNode:SimulatedChainNetwork
. NOTE: The $sel:tickThread:SimulatedChainNetwork
needs to be
cancel
ed 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 :: 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 OnChainTx
and OnChainTx
.
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