Skip to main content

lexe_common/api/
test_event.rs

1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5/// An enum for calling various `TestEventReceiver` methods.
6#[derive(Debug, Serialize, Deserialize)]
7pub enum TestEventOp {
8    Clear,
9    Wait(TestEvent),
10    WaitN(TestEvent, usize),
11    WaitAll(Vec<TestEvent>),
12    WaitAllN(Vec<(TestEvent, usize)>),
13    WaitTimeout(TestEvent, Duration),
14    WaitNTimeout(TestEvent, usize, Duration),
15    WaitAllTimeout(Vec<TestEvent>, Duration),
16    WaitAllNTimeout(Vec<(TestEvent, usize)>, Duration),
17}
18
19/// Test events emitted throughout the node that allow test to know when
20/// something has happened, obviating the need for sleeps (which introduce
21/// flakiness) while keeping tests reasonably fast.
22// This is named `TestEvent` (not `LxEvent`) in case we need a `LxEvent` later.
23#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
24pub enum TestEvent {
25    /// A [`FundingGenerationReady`] event was handled.
26    ///
27    /// [`FundingGenerationReady`]: lightning::events::Event::FundingGenerationReady
28    FundingGenerationHandled,
29    /// An on-chain transaction was successfully broadcasted by `LexeEsplora`.
30    TxBroadcasted,
31    /// A [`ChannelPending`] event was handled.
32    ///
33    /// [`ChannelPending`]: lightning::events::Event::ChannelPending
34    ChannelPending,
35    /// A [`ChannelReady`] event was handled.
36    ///
37    /// [`ChannelReady`]: lightning::events::Event::ChannelReady
38    ChannelReady,
39    /// A [`PaymentClaimable`] event was handled.
40    ///
41    /// [`PaymentClaimable`]: lightning::events::Event::PaymentClaimable
42    PaymentClaimable,
43    /// A [`PaymentClaimed`] event was handled.
44    ///
45    /// [`PaymentClaimed`]: lightning::events::Event::PaymentClaimed
46    PaymentClaimed,
47    /// A [`PaymentSent`] event was handled.
48    ///
49    /// [`PaymentSent`]: lightning::events::Event::PaymentSent
50    PaymentSent,
51    /// A [`PaymentFailed`] event was handled.
52    ///
53    /// [`PaymentFailed`]: lightning::events::Event::PaymentFailed
54    PaymentFailed,
55    /// A payment was enqueued for retry after a transient failure.
56    PaymentRetried,
57    /// A [`ChannelClosed`] event was handled.
58    ///
59    /// [`ChannelClosed`]: lightning::events::Event::ChannelClosed
60    ChannelClosed,
61    /// A [`SpendableOutputs`] event was handled.
62    ///
63    /// [`SpendableOutputs`]: lightning::events::Event::SpendableOutputs
64    SpendableOutputs,
65}
66
67impl From<TestEvent> for Vec<TestEvent> {
68    fn from(event: TestEvent) -> Self {
69        vec![event]
70    }
71}