@@ -32,8 +32,13 @@ pub(crate) const EVENTS_PERSISTENCE_KEY: &str = "events";
3232/// An event emitted by [`LdkLite`] that should be handled by the user.
3333///
3434/// [`LdkLite`]: [`crate::LdkLite`]
35+ <<<<<<< Updated upstream
3536#[ derive ( Debug , Clone ) ]
3637pub enum LdkLiteEvent {
38+ =======
39+ #[ derive ( Debug , Clone , PartialEq ) ]
40+ pub enum Event {
41+ >>>>>>> Stashed changes
3742 /// A payment we sent was successful.
3843 PaymentSuccessful {
3944 /// The hash of the payment.
@@ -564,3 +569,29 @@ impl LdkEventHandler for LdkLiteEventHandler {
564569 }
565570 }
566571}
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