Skip to content

Commit

Permalink
add 3 nodes testing for send payment
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Nov 24, 2024
1 parent c3a4ac7 commit 489bc62
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/fiber/tests/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 489bc62

Please sign in to comment.