Skip to content

Commit

Permalink
Test InvoicePayer in BackgroundProcessor
Browse files Browse the repository at this point in the history
Proof of concept showing InvoicePayer can be used with an
Arc<ChannelManager> passed to BackgroundProcessor. Likely do not need to
merge this commit.
  • Loading branch information
jkczyz committed Sep 21, 2021
1 parent 964f5c7 commit 4caedcf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lightning-background-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ lightning-persister = { version = "0.0.100", path = "../lightning-persister" }

[dev-dependencies]
lightning = { version = "0.0.100", path = "../lightning", features = ["_test_utils"] }

lightning-invoice = { version = "0.8.0", path = "../lightning-invoice" }
19 changes: 18 additions & 1 deletion lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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<Signer, CW, T, K, F, L>,
M: 'static + Deref<Target = ChainMonitor<Signer, CF, T, F, L, P>> + Send + Sync,
CM: 'static + Deref<Target = ChannelManager<Signer, CW, T, K, F, L>> + Send + Sync,
Expand Down Expand Up @@ -315,6 +315,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;
use lightning_invoice::utils::DefaultRouter;
use lightning_persister::FilesystemPersister;
use std::fs;
use std::path::PathBuf;
Expand Down Expand Up @@ -619,4 +621,19 @@ 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<InMemorySigner, Arc<ChainMonitor>, Arc<test_utils::TestBroadcaster>, Arc<KeysManager>, Arc<test_utils::TestFeeEstimator>, Arc<test_utils::TestLogger>>| 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 invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, Arc::clone(&nodes[0].logger), |_: &_| {}).with_retry_attempts(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());
}
}

0 comments on commit 4caedcf

Please sign in to comment.