Skip to content

Commit d979d3f

Browse files
committed
add test support for amp
1 parent 1308ff5 commit d979d3f

File tree

5 files changed

+85
-20
lines changed

5 files changed

+85
-20
lines changed

crates/fiber-lib/src/fiber/network.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,7 @@ where
25192519
attempt.hash = children[i].hash;
25202520
attempts_routers[i] = (attempt, route);
25212521
}
2522+
debug!("finished set custom records for amp_mpp");
25222523
}
25232524

25242525
async fn send_payment_onion_packet(

crates/fiber-lib/src/fiber/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod amp;
12
mod channel;
23
mod features;
34
mod gossip;

crates/fiber-lib/src/fiber/tests/mpp.rs

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
create_n_nodes_network, establish_channel_between_nodes, init_tracing, ChannelParameters,
2727
NetworkNode, MIN_RESERVED_CKB,
2828
},
29-
NetworkServiceEvent, HUGE_CKB_AMOUNT,
29+
MppMode, NetworkServiceEvent, HUGE_CKB_AMOUNT,
3030
};
3131

3232
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
@@ -1998,7 +1998,13 @@ async fn test_send_mpp_dry_run_will_be_ok_with_single_path() {
19981998
.await;
19991999
let [node_0, _node_1, mut node_2] = nodes.try_into().expect("ok nodes");
20002000
let res = node_0
2001-
.send_mpp_payment_with_dry_run_option(&mut node_2, amount, None, true)
2001+
.send_mpp_payment_with_dry_run_option(
2002+
&mut node_2,
2003+
amount,
2004+
None,
2005+
true,
2006+
MppMode::BasicMpp,
2007+
)
20022008
.await;
20032009

20042010
if let Some(count) = expect_routers_count {
@@ -2040,7 +2046,13 @@ async fn test_send_mpp_direct_channels_dry_run() {
20402046
let [node_0, mut node_1, _node_2] = nodes.try_into().expect("ok nodes");
20412047

20422048
let res = node_0
2043-
.send_mpp_payment_with_dry_run_option(&mut node_1, amount, None, true)
2049+
.send_mpp_payment_with_dry_run_option(
2050+
&mut node_1,
2051+
amount,
2052+
None,
2053+
true,
2054+
MppMode::BasicMpp,
2055+
)
20442056
.await;
20452057

20462058
if let Some(count) = expect_routers_count {
@@ -2085,7 +2097,13 @@ async fn test_send_mpp_dry_run_single_path_mixed_with_multiple_paths() {
20852097
.await;
20862098
let [node_0, _node_1, mut node_2] = nodes.try_into().expect("ok nodes");
20872099
let res = node_0
2088-
.send_mpp_payment_with_dry_run_option(&mut node_2, amount, None, true)
2100+
.send_mpp_payment_with_dry_run_option(
2101+
&mut node_2,
2102+
amount,
2103+
None,
2104+
true,
2105+
MppMode::BasicMpp,
2106+
)
20892107
.await;
20902108

20912109
if let Some(count) = expect_routers_count {
@@ -2135,7 +2153,7 @@ async fn test_send_mpp_will_succeed_with_retry_first_hops() {
21352153
let [node_0, mut node_1] = nodes.try_into().expect("ok nodes");
21362154

21372155
let res = node_0
2138-
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true)
2156+
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true, MppMode::BasicMpp)
21392157
.await;
21402158

21412159
let query_res = res.unwrap();
@@ -2190,7 +2208,7 @@ async fn test_send_mpp_will_succeed_with_retry_2_channels() {
21902208
let [node_0, mut node_1] = nodes.try_into().expect("ok nodes");
21912209

21922210
let res = node_0
2193-
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true)
2211+
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true, MppMode::BasicMpp)
21942212
.await;
21952213

21962214
let query_res = res.unwrap();
@@ -2247,7 +2265,7 @@ async fn test_send_mpp_will_fail_with_retry_3_channels() {
22472265
let [node_0, mut node_1] = nodes.try_into().expect("ok nodes");
22482266

22492267
let res = node_0
2250-
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true)
2268+
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true, MppMode::BasicMpp)
22512269
.await;
22522270

22532271
let query_res = res.unwrap();
@@ -2293,7 +2311,7 @@ async fn test_send_mpp_will_success_with_retry_split_channels() {
22932311
let [node_0, mut node_1] = nodes.try_into().expect("ok nodes");
22942312

22952313
let res = node_0
2296-
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true)
2314+
.send_mpp_payment_with_dry_run_option(&mut node_1, 300000, None, true, MppMode::BasicMpp)
22972315
.await;
22982316

22992317
let query_res = res.unwrap();
@@ -2339,7 +2357,7 @@ async fn test_send_mpp_will_fail_with_disable_single_path() {
23392357
let [node_0, _node_1, mut node_2] = nodes.try_into().expect("ok nodes");
23402358

23412359
let res = node_0
2342-
.send_mpp_payment_with_dry_run_option(&mut node_2, 30000, None, true)
2360+
.send_mpp_payment_with_dry_run_option(&mut node_2, 30000, None, true, MppMode::BasicMpp)
23432361
.await;
23442362

23452363
let query_res = res.unwrap();
@@ -2390,7 +2408,7 @@ async fn test_send_mpp_will_success_with_middle_hop_capacity_not_enough() {
23902408
let [node_0, _node_1, mut node_2] = nodes.try_into().expect("ok nodes");
23912409

23922410
let res = node_0
2393-
.send_mpp_payment_with_dry_run_option(&mut node_2, 300000, None, true)
2411+
.send_mpp_payment_with_dry_run_option(&mut node_2, 300000, None, true, MppMode::BasicMpp)
23942412
.await;
23952413

23962414
let query_res = res.unwrap();
@@ -3163,6 +3181,7 @@ async fn test_send_payment_custom_records_not_in_range() {
31633181
max_parts: Some(2),
31643182
..Default::default()
31653183
},
3184+
MppMode::BasicMpp,
31663185
)
31673186
.await;
31683187

@@ -3188,7 +3207,13 @@ async fn test_mpp_can_not_find_path_filter_target_node_features() {
31883207
let [mut node_0, mut node_1] = nodes.try_into().expect("2 nodes");
31893208

31903209
let res = node_0
3191-
.send_mpp_payment_with_dry_run_option(&mut node_1, 20000000000, Some(2), true)
3210+
.send_mpp_payment_with_dry_run_option(
3211+
&mut node_1,
3212+
20000000000,
3213+
Some(2),
3214+
true,
3215+
MppMode::BasicMpp,
3216+
)
31923217
.await;
31933218
eprintln!("query res: {:?}", res);
31943219

@@ -3202,7 +3227,13 @@ async fn test_mpp_can_not_find_path_filter_target_node_features() {
32023227
.await;
32033228

32043229
let res = node_0
3205-
.send_mpp_payment_with_dry_run_option(&mut node_1, 20000000000, Some(2), true)
3230+
.send_mpp_payment_with_dry_run_option(
3231+
&mut node_1,
3232+
20000000000,
3233+
Some(2),
3234+
true,
3235+
MppMode::BasicMpp,
3236+
)
32063237
.await;
32073238
eprintln!("query res: {:?}", res);
32083239

@@ -3312,6 +3343,7 @@ async fn test_mpp_can_not_find_path_filter_middle_node_features() {
33123343
200 * CKB_SHANNONS as u128,
33133344
Some(2),
33143345
true,
3346+
MppMode::BasicMpp,
33153347
)
33163348
.await;
33173349
eprintln!("query res: {:?}", res);
@@ -3342,6 +3374,7 @@ async fn test_mpp_can_not_find_path_filter_middle_node_features() {
33423374
200 * CKB_SHANNONS as u128,
33433375
Some(2),
33443376
true,
3377+
MppMode::BasicMpp,
33453378
)
33463379
.await;
33473380
eprintln!("query res: {:?}", res);
@@ -3530,14 +3563,14 @@ async fn test_send_mpp_respect_min_tlc_value() {
35303563
assert!(res.is_ok());
35313564

35323565
let res = node_0
3533-
.send_mpp_payment_with_dry_run_option(&mut node_2, 28000, Some(3), true)
3566+
.send_mpp_payment_with_dry_run_option(&mut node_2, 28000, Some(3), true, MppMode::BasicMpp)
35343567
.await;
35353568

35363569
eprintln!("res: {:?}", res);
35373570
assert!(res.is_err());
35383571

35393572
let res = node_0
3540-
.send_mpp_payment_with_dry_run_option(&mut node_2, 30000, None, true)
3573+
.send_mpp_payment_with_dry_run_option(&mut node_2, 30000, None, true, MppMode::BasicMpp)
35413574
.await;
35423575
debug!("res: {:?}", res);
35433576
assert!(res.is_ok());

crates/fiber-lib/src/fiber/tests/payment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6360,6 +6360,7 @@ async fn test_send_payment_mpp_can_not_be_keysend() {
63606360
dry_run: false,
63616361
..Default::default()
63626362
},
6363+
MppMode::BasicMpp,
63636364
)
63646365
.await;
63656366
eprintln!("res: {:?}", res);

crates/fiber-lib/src/tests/test_utils.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ pub(crate) async fn create_n_nodes_network_with_params(
614614
(nodes, channels)
615615
}
616616

617+
pub enum MppMode {
618+
BasicMpp,
619+
AtomicMpp,
620+
}
621+
617622
#[allow(clippy::type_complexity)]
618623
pub async fn create_n_nodes_network(
619624
amounts: &[((usize, usize), (u128, u128))],
@@ -726,6 +731,26 @@ impl NetworkNode {
726731
dry_run: false,
727732
..Default::default()
728733
},
734+
MppMode::BasicMpp,
735+
)
736+
.await
737+
}
738+
739+
pub async fn send_atomic_mpp_payment(
740+
&self,
741+
target_node: &mut NetworkNode,
742+
amount: u128,
743+
max_parts: Option<u64>,
744+
) -> Result<SendPaymentResponse, String> {
745+
self.send_mpp_payment_with_command(
746+
target_node,
747+
amount,
748+
SendPaymentCommand {
749+
max_parts,
750+
dry_run: false,
751+
..Default::default()
752+
},
753+
MppMode::AtomicMpp,
729754
)
730755
.await
731756
}
@@ -736,6 +761,7 @@ impl NetworkNode {
736761
amount: u128,
737762
max_parts: Option<u64>,
738763
dry_run: bool,
764+
mode: MppMode,
739765
) -> Result<SendPaymentResponse, String> {
740766
self.send_mpp_payment_with_command(
741767
target_node,
@@ -745,6 +771,7 @@ impl NetworkNode {
745771
dry_run,
746772
..Default::default()
747773
},
774+
mode,
748775
)
749776
.await
750777
}
@@ -754,18 +781,20 @@ impl NetworkNode {
754781
target_node: &mut NetworkNode,
755782
amount: u128,
756783
command: SendPaymentCommand,
784+
mode: MppMode,
757785
) -> Result<SendPaymentResponse, String> {
758786
let target_pubkey = target_node.get_public_key();
759787
let preimage = gen_rand_sha256_hash();
760-
let ckb_invoice = InvoiceBuilder::new(Currency::Fibd)
788+
let mut builder = InvoiceBuilder::new(Currency::Fibd)
761789
.amount(Some(amount))
762790
.payment_preimage(preimage)
763791
.payee_pub_key(target_pubkey.into())
764-
.allow_mpp(true)
765-
.payment_secret(gen_rand_sha256_hash())
766-
.build()
767-
.expect("build invoice success");
768-
792+
.payment_secret(gen_rand_sha256_hash());
793+
match mode {
794+
MppMode::BasicMpp => builder = builder.allow_mpp(true),
795+
MppMode::AtomicMpp => builder = builder.allow_atomic_mpp(true),
796+
}
797+
let ckb_invoice = builder.build().expect("build invoice success");
769798
target_node.insert_invoice(ckb_invoice.clone(), Some(preimage));
770799
let mut command = command.clone();
771800
command.invoice = Some(ckb_invoice.to_string());

0 commit comments

Comments
 (0)