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 package was successfully broadcasted by
30 /// `LexeEsplora`.
31 TxsBroadcasted,
32 /// A [`ChannelPending`] event was handled.
33 ///
34 /// [`ChannelPending`]: lightning::events::Event::ChannelPending
35 ChannelPending,
36 /// A [`ChannelReady`] event was handled.
37 ///
38 /// [`ChannelReady`]: lightning::events::Event::ChannelReady
39 ChannelReady,
40 /// A [`PaymentClaimable`] event was handled.
41 ///
42 /// [`PaymentClaimable`]: lightning::events::Event::PaymentClaimable
43 PaymentClaimable,
44 /// A [`PaymentClaimed`] event was handled.
45 ///
46 /// [`PaymentClaimed`]: lightning::events::Event::PaymentClaimed
47 PaymentClaimed,
48 /// A [`PaymentSent`] event was handled.
49 ///
50 /// [`PaymentSent`]: lightning::events::Event::PaymentSent
51 PaymentSent,
52 /// A [`PaymentFailed`] event was handled.
53 ///
54 /// [`PaymentFailed`]: lightning::events::Event::PaymentFailed
55 PaymentFailed,
56 /// A [`ChannelClosed`] event was handled.
57 ///
58 /// [`ChannelClosed`]: lightning::events::Event::ChannelClosed
59 ChannelClosed,
60 /// A [`SpendableOutputs`] event was handled.
61 ///
62 /// [`SpendableOutputs`]: lightning::events::Event::SpendableOutputs
63 SpendableOutputs,
64}
65
66impl From<TestEvent> for Vec<TestEvent> {
67 fn from(event: TestEvent) -> Self {
68 vec![event]
69 }
70}