Skip to content

Commit cb9404e

Browse files
Add tests for LSPS5 client and service. Also tests for checking the correctness of the signing logic
1 parent 813802c commit cb9404e

File tree

4 files changed

+1428
-0
lines changed

4 files changed

+1428
-0
lines changed

lightning-liquidity/tests/common/mod.rs

+46
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(unused_imports)]
55
#![allow(unused_macros)]
66

7+
use bitcoin::secp256k1::SecretKey;
78
use lightning::chain::Filter;
89
use lightning::sign::EntropySource;
910

@@ -34,6 +35,8 @@ use lightning::util::persist::{
3435
SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
3536
};
3637
use lightning::util::test_utils;
38+
use lightning_liquidity::lsps5::client::{LSPS5ClientConfig, LSPS5ClientHandler};
39+
use lightning_liquidity::lsps5::service::{LSPS5ServiceConfig, LSPS5ServiceHandler};
3740
use lightning_liquidity::{LiquidityClientConfig, LiquidityManager, LiquidityServiceConfig};
3841
use lightning_persister::fs_store::FilesystemStore;
3942

@@ -684,3 +687,46 @@ fn advance_chain(node: &mut Node, num_blocks: u32) {
684687
}
685688
}
686689
}
690+
691+
pub(crate) fn get_client_and_service() -> (
692+
&'static LSPS5ClientHandler<Arc<KeysManager>>,
693+
&'static LSPS5ServiceHandler,
694+
bitcoin::secp256k1::PublicKey,
695+
bitcoin::secp256k1::PublicKey,
696+
&'static Node,
697+
&'static Node,
698+
) {
699+
let signing_key = SecretKey::from_slice(&[42; 32]).unwrap();
700+
let mut lsps5_service_config = LSPS5ServiceConfig::default();
701+
lsps5_service_config.signing_key = signing_key;
702+
let service_config = LiquidityServiceConfig {
703+
#[cfg(lsps1_service)]
704+
lsps1_service_config: None,
705+
lsps2_service_config: None,
706+
lsps5_service_config: Some(lsps5_service_config),
707+
advertise_service: true,
708+
};
709+
710+
let lsps5_client_config = LSPS5ClientConfig::default();
711+
let client_config = LiquidityClientConfig {
712+
lsps1_client_config: None,
713+
lsps2_client_config: None,
714+
lsps5_client_config: Some(lsps5_client_config),
715+
};
716+
717+
let (service_node, client_node) =
718+
create_service_and_client_nodes("webhook_registration_flow", service_config, client_config);
719+
720+
// Leak the nodes to extend their lifetime to 'static since this is test code
721+
let service_node = Box::leak(Box::new(service_node));
722+
let client_node = Box::leak(Box::new(client_node));
723+
724+
let client_handler = client_node.liquidity_manager.lsps5_client_handler().unwrap();
725+
let service_handler = service_node.liquidity_manager.lsps5_service_handler().unwrap();
726+
727+
let secp = bitcoin::secp256k1::Secp256k1::new();
728+
let service_node_id = bitcoin::secp256k1::PublicKey::from_secret_key(&secp, &signing_key);
729+
let client_node_id = client_node.channel_manager.get_our_node_id();
730+
731+
(client_handler, service_handler, service_node_id, client_node_id, service_node, client_node)
732+
}

lightning-liquidity/tests/lsps2_integration_tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ fn invoice_generation_flow() {
8888
#[cfg(lsps1_service)]
8989
lsps1_service_config: None,
9090
lsps2_service_config: Some(lsps2_service_config),
91+
lsps5_service_config: None,
9192
advertise_service: true,
9293
};
9394

9495
let lsps2_client_config = LSPS2ClientConfig::default();
9596
let client_config = LiquidityClientConfig {
9697
lsps1_client_config: None,
9798
lsps2_client_config: Some(lsps2_client_config),
99+
lsps5_client_config: None,
98100
};
99101

100102
let (service_node, client_node) =

0 commit comments

Comments
 (0)