|
4 | 4 | #![allow(unused_imports)]
|
5 | 5 | #![allow(unused_macros)]
|
6 | 6 |
|
| 7 | +use bitcoin::secp256k1::SecretKey; |
7 | 8 | use lightning::chain::Filter;
|
8 | 9 | use lightning::sign::EntropySource;
|
9 | 10 |
|
@@ -34,6 +35,8 @@ use lightning::util::persist::{
|
34 | 35 | SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
|
35 | 36 | };
|
36 | 37 | use lightning::util::test_utils;
|
| 38 | +use lightning_liquidity::lsps5::client::{LSPS5ClientConfig, LSPS5ClientHandler}; |
| 39 | +use lightning_liquidity::lsps5::service::{LSPS5ServiceConfig, LSPS5ServiceHandler, TimeProvider}; |
37 | 40 | use lightning_liquidity::{LiquidityClientConfig, LiquidityManager, LiquidityServiceConfig};
|
38 | 41 | use lightning_persister::fs_store::FilesystemStore;
|
39 | 42 |
|
@@ -400,7 +403,7 @@ fn get_full_filepath(filepath: String, filename: String) -> String {
|
400 | 403 |
|
401 | 404 | pub(crate) fn create_liquidity_node(
|
402 | 405 | i: usize, persist_dir: &str, network: Network, service_config: Option<LiquidityServiceConfig>,
|
403 |
| - client_config: Option<LiquidityClientConfig>, |
| 406 | + client_config: Option<LiquidityClientConfig>, time_provider: Option<Arc<dyn TimeProvider>>, |
404 | 407 | ) -> Node {
|
405 | 408 | let tx_broadcaster = Arc::new(test_utils::TestBroadcaster::new(network));
|
406 | 409 | let fee_estimator = Arc::new(test_utils::TestFeeEstimator::new(253));
|
@@ -459,7 +462,7 @@ pub(crate) fn create_liquidity_node(
|
459 | 462 | Some(chain_params),
|
460 | 463 | service_config,
|
461 | 464 | client_config,
|
462 |
| - None, |
| 465 | + time_provider, |
463 | 466 | ));
|
464 | 467 | let msg_handler = MessageHandler {
|
465 | 468 | chan_handler: Arc::new(test_utils::TestChannelMessageHandler::new(
|
@@ -489,14 +492,23 @@ pub(crate) fn create_liquidity_node(
|
489 | 492 | }
|
490 | 493 |
|
491 | 494 | pub(crate) fn create_service_and_client_nodes(
|
492 |
| - persist_dir: &str, service_config: LiquidityServiceConfig, client_config: LiquidityClientConfig, |
| 495 | + persist_dir: &str, service_config: LiquidityServiceConfig, |
| 496 | + client_config: LiquidityClientConfig, time_provider: Option<Arc<dyn TimeProvider>>, |
493 | 497 | ) -> (Node, Node) {
|
494 | 498 | let persist_temp_path = env::temp_dir().join(persist_dir);
|
495 | 499 | let persist_dir = persist_temp_path.to_string_lossy().to_string();
|
496 | 500 | let network = Network::Bitcoin;
|
497 | 501 |
|
498 |
| - let service_node = create_liquidity_node(1, &persist_dir, network, Some(service_config), None); |
499 |
| - let client_node = create_liquidity_node(2, &persist_dir, network, None, Some(client_config)); |
| 502 | + let service_node = create_liquidity_node( |
| 503 | + 1, |
| 504 | + &persist_dir, |
| 505 | + network, |
| 506 | + Some(service_config), |
| 507 | + None, |
| 508 | + time_provider.clone(), |
| 509 | + ); |
| 510 | + let client_node = |
| 511 | + create_liquidity_node(2, &persist_dir, network, None, Some(client_config), time_provider); |
500 | 512 |
|
501 | 513 | service_node
|
502 | 514 | .channel_manager
|
@@ -672,3 +684,52 @@ fn advance_chain(node: &mut Node, num_blocks: u32) {
|
672 | 684 | }
|
673 | 685 | }
|
674 | 686 | }
|
| 687 | + |
| 688 | +pub(crate) fn get_client_and_service( |
| 689 | + time_provider: Option<Arc<dyn TimeProvider>>, |
| 690 | +) -> ( |
| 691 | + &'static LSPS5ClientHandler<Arc<KeysManager>>, |
| 692 | + &'static LSPS5ServiceHandler<Arc<ChannelManager>>, |
| 693 | + bitcoin::secp256k1::PublicKey, |
| 694 | + bitcoin::secp256k1::PublicKey, |
| 695 | + &'static Node, |
| 696 | + &'static Node, |
| 697 | +) { |
| 698 | + let signing_key = SecretKey::from_slice(&[42; 32]).unwrap(); |
| 699 | + let mut lsps5_service_config = LSPS5ServiceConfig::default(); |
| 700 | + lsps5_service_config.signing_key = signing_key; |
| 701 | + let service_config = LiquidityServiceConfig { |
| 702 | + #[cfg(lsps1_service)] |
| 703 | + lsps1_service_config: None, |
| 704 | + lsps2_service_config: None, |
| 705 | + lsps5_service_config: Some(lsps5_service_config), |
| 706 | + advertise_service: true, |
| 707 | + }; |
| 708 | + |
| 709 | + let lsps5_client_config = LSPS5ClientConfig::default(); |
| 710 | + let client_config = LiquidityClientConfig { |
| 711 | + lsps1_client_config: None, |
| 712 | + lsps2_client_config: None, |
| 713 | + lsps5_client_config: Some(lsps5_client_config), |
| 714 | + }; |
| 715 | + |
| 716 | + let (service_node, client_node) = create_service_and_client_nodes( |
| 717 | + "webhook_registration_flow", |
| 718 | + service_config, |
| 719 | + client_config, |
| 720 | + time_provider, |
| 721 | + ); |
| 722 | + |
| 723 | + // Leak the nodes to extend their lifetime to 'static since this is test code |
| 724 | + let service_node = Box::leak(Box::new(service_node)); |
| 725 | + let client_node = Box::leak(Box::new(client_node)); |
| 726 | + |
| 727 | + let client_handler = client_node.liquidity_manager.lsps5_client_handler().unwrap(); |
| 728 | + let service_handler = service_node.liquidity_manager.lsps5_service_handler().unwrap(); |
| 729 | + |
| 730 | + let secp = bitcoin::secp256k1::Secp256k1::new(); |
| 731 | + let service_node_id = bitcoin::secp256k1::PublicKey::from_secret_key(&secp, &signing_key); |
| 732 | + let client_node_id = client_node.channel_manager.get_our_node_id(); |
| 733 | + |
| 734 | + (client_handler, service_handler, service_node_id, client_node_id, service_node, client_node) |
| 735 | +} |
0 commit comments