From 489bc628e508dc77ddc3db61fb0f20d9e85e74c3 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 24 Nov 2024 12:17:01 +0800 Subject: [PATCH] add 3 nodes testing for send payment --- src/fiber/tests/channel.rs | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/fiber/tests/channel.rs b/src/fiber/tests/channel.rs index 76a195e6..d24941ba 100644 --- a/src/fiber/tests/channel.rs +++ b/src/fiber/tests/channel.rs @@ -624,6 +624,49 @@ async fn test_network_send_payment_with_dry_run() { assert!(res.is_err()); } +#[tokio::test] +async fn test_send_payment_with_3_nodes() { + init_tracing(); + + let _span = tracing::info_span!("node", node = "test").entered(); + + let (node_a, _node_b, node_c, _, _) = create_3_nodes_with_established_channel( + (100000000000, 100000000000), + (100000000000, 100000000000), + true, + ) + .await; + + // sleep for 2 seconds to make sure the channel is established + tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await; + + let node_c_pubkey = node_c.pubkey.clone(); + let message = |rpc_reply| -> NetworkActorMessage { + NetworkActorMessage::Command(NetworkActorCommand::SendPayment( + SendPaymentCommand { + target_pubkey: Some(node_c_pubkey), + amount: Some(1000000 + 5), + payment_hash: Some(gen_sha256_hash()), + final_htlc_expiry_delta: None, + invoice: None, + timeout: None, + max_fee_amount: None, + max_parts: None, + keysend: None, + udt_type_script: None, + allow_self_payment: false, + dry_run: true, + }, + rpc_reply, + )) + }; + let res = call!(node_a.network_actor, message).expect("node_a alive"); + assert!(res.is_ok()); + let res = res.unwrap(); + assert_eq!(res.status, PaymentSessionStatus::Created); + assert!(res.fee > 0); +} + #[tokio::test] async fn test_stash_broadcast_messages() { init_tracing(); @@ -951,6 +994,34 @@ async fn create_nodes_with_established_channel( (node_a, node_b, channel_id) } +async fn create_3_nodes_with_established_channel( + (channel_1_amount_a, channel_1_amount_b): (u128, u128), + (channel_2_amount_b, channel_2_amount_c): (u128, u128), + public: bool, +) -> (NetworkNode, NetworkNode, NetworkNode, Hash256, Hash256) { + let [mut node_a, mut node_b, mut node_c] = NetworkNode::new_n_interconnected_nodes().await; + + let (channel_id_ab, _funding_tx_ab) = establish_channel_between_nodes( + &mut node_a, + &mut node_b, + channel_1_amount_a, + channel_1_amount_b, + public, + ) + .await; + + let (channel_id_bc, _funding_tx_bc) = establish_channel_between_nodes( + &mut node_b, + &mut node_c, + channel_2_amount_b, + channel_2_amount_c, + public, + ) + .await; + + (node_a, node_b, node_c, channel_id_ab, channel_id_bc) +} + async fn do_test_remove_tlc_with_wrong_hash_algorithm( correct_algorithm: HashAlgorithm, wrong_algorithm: HashAlgorithm,