From: Jeffrey Czyz Date: Tue, 24 Aug 2021 04:56:59 +0000 (-0500) Subject: Test InvoicePayer in BackgroundProcessor X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f7f32716068571e676bd9c5a5b45e4390770f5cf;p=rust-lightning Test InvoicePayer in BackgroundProcessor Proof of concept showing InvoicePayer can be used with an Arc passed to BackgroundProcessor. Likely do not need to merge this commit. --- diff --git a/lightning-background-processor/Cargo.toml b/lightning-background-processor/Cargo.toml index 4e45bb2a8..d868f14db 100644 --- a/lightning-background-processor/Cargo.toml +++ b/lightning-background-processor/Cargo.toml @@ -16,4 +16,4 @@ lightning-persister = { version = "0.0.102", path = "../lightning-persister" } [dev-dependencies] lightning = { version = "0.0.102", path = "../lightning", features = ["_test_utils"] } - +lightning-invoice = { version = "0.10.0", path = "../lightning-invoice" } diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 16c5eb4f9..c4f40e933 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -174,7 +174,7 @@ impl BackgroundProcessor { Descriptor: 'static + SocketDescriptor + Send + Sync, CMH: 'static + Deref + Send + Sync, RMH: 'static + Deref + Send + Sync, - EH: 'static + EventHandler + Send + Sync, + EH: 'static + EventHandler + Send, CMP: 'static + Send + ChannelManagerPersister, M: 'static + Deref> + Send + Sync, CM: 'static + Deref> + Send + Sync, @@ -317,6 +317,8 @@ mod tests { use lightning::util::events::{Event, MessageSendEventsProvider, MessageSendEvent}; use lightning::util::ser::Writeable; use lightning::util::test_utils; + use lightning_invoice::payment::{InvoicePayer, RetryAttempts}; + use lightning_invoice::utils::DefaultRouter; use lightning_persister::FilesystemPersister; use std::fs; use std::path::PathBuf; @@ -622,4 +624,20 @@ mod tests { assert!(bg_processor.stop().is_ok()); } + + #[test] + fn test_invoice_payer() { + let nodes = create_nodes(2, "test_invoice_payer".to_string()); + + // Initiate the background processors to watch each node. + let data_dir = nodes[0].persister.get_data_dir(); + let persister = move |node: &ChannelManager, Arc, Arc, Arc, Arc>| FilesystemPersister::persist_manager(data_dir.clone(), node); + let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash())); + let router = DefaultRouter::new(network_graph, Arc::clone(&nodes[0].logger)); + let scorer = Scorer::default(); + let invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, scorer, Arc::clone(&nodes[0].logger), |_: &_| {}, RetryAttempts(2))); + let event_handler = Arc::clone(&invoice_payer); + let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone()); + assert!(bg_processor.stop().is_ok()); + } }