@@ -32,8 +32,13 @@ pub(crate) const EVENTS_PERSISTENCE_KEY: &str = "events";
32
32
/// An event emitted by [`LdkLite`] that should be handled by the user.
33
33
///
34
34
/// [`LdkLite`]: [`crate::LdkLite`]
35
+ <<<<<<< Updated upstream
35
36
#[ derive ( Debug , Clone ) ]
36
37
pub enum LdkLiteEvent {
38
+ =======
39
+ #[ derive ( Debug , Clone , PartialEq ) ]
40
+ pub enum Event {
41
+ >>>>>>> Stashed changes
37
42
/// A payment we sent was successful.
38
43
PaymentSuccessful {
39
44
/// The hash of the payment.
@@ -564,3 +569,29 @@ impl LdkEventHandler for LdkLiteEventHandler {
564
569
}
565
570
}
566
571
}
572
+
573
+ #[ cfg( test) ]
574
+ mod tests {
575
+ use super:: * ;
576
+ use crate :: test_utils:: TestPersister ;
577
+
578
+ #[ test]
579
+ fn event_queue_persistence ( ) {
580
+ let test_persister = Arc : : new( TestPersister :: new( ) ) ;
581
+ let event_queue = EventQueue :: new( Arc :: clone( & test_persister) ) ;
582
+
583
+ let expected_event = Event :: ChannelReady { channel_id : [ 23u8 ; 32 ] , user_channel_id : 2323 } ;
584
+ event_queue. add_event( expected_event. clone( ) ) . unwrap( ) ;
585
+ assert ! ( test_persister. get_and_clear_pending_persist( ) ) ;
586
+
587
+ // Check we get the expected event and that it is returned until we mark it handled.
588
+ for _ in 0 ..5 {
589
+ assert_eq!( event_queue. next_event( ) , expected_event) ;
590
+ assert_eq ! ( false , test_persister. get_and_clear_pending_persist( ) ) ;
591
+ }
592
+
593
+ // Check we persisted on `event_handled()`
594
+ event_queue. event_handled( ) . unwrap( ) ;
595
+ assert!( test_persister. get_and_clear_pending_persist( ) ) ;
596
+ }
597
+ }
0 commit comments