diff --git a/src/fiber/tests/channel.rs b/src/fiber/tests/channel.rs index 76a195e6..b1fdee25 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(); @@ -929,6 +972,7 @@ async fn establish_channel_between_nodes( .get_tx_from_hash(funding_tx_outpoint.tx_hash()) .await .expect("tx found"); + (new_channel_id, funding_tx) } @@ -951,6 +995,39 @@ 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 res = node_c.submit_tx(funding_tx_ab).await; + assert_eq!(res, Status::Committed); + + 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; + + let res = node_a.submit_tx(funding_tx_bc).await; + assert_eq!(res, Status::Committed); + (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,