Skip to content

Commit 0c343b1

Browse files
committed
f yet moar test
1 parent d2d150d commit 0c343b1

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use chain::{BestBlock, Confirm, Listen, Watch};
1414
use chain::channelmonitor::ChannelMonitor;
1515
use chain::transaction::OutPoint;
1616
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
17-
use ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure};
17+
use ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, PaymentId};
1818
use routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
1919
use routing::router::{Route, get_route};
2020
use routing::scorer::Scorer;
@@ -1156,10 +1156,11 @@ macro_rules! expect_payment_failed {
11561156
}
11571157
}
11581158

1159-
pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) {
1160-
origin_node.node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap();
1159+
pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId {
1160+
let payment_id = origin_node.node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap();
11611161
check_added_monitors!(origin_node, expected_paths.len());
11621162
pass_along_route(origin_node, expected_paths, recv_value, our_payment_hash, our_payment_secret);
1163+
payment_id
11631164
}
11641165

11651166
pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent, payment_received_expected: bool, expected_preimage: Option<PaymentPreimage>) {
@@ -1222,10 +1223,10 @@ pub fn pass_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_rou
12221223
}
12231224
}
12241225

1225-
pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) {
1226+
pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
12261227
let (our_payment_preimage, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(expected_route.last().unwrap());
1227-
send_along_route_with_secret(origin_node, route, &[expected_route], recv_value, our_payment_hash, our_payment_secret);
1228-
(our_payment_preimage, our_payment_hash, our_payment_secret)
1228+
let payment_id = send_along_route_with_secret(origin_node, route, &[expected_route], recv_value, our_payment_hash, our_payment_secret);
1229+
(our_payment_preimage, our_payment_hash, our_payment_secret, payment_id)
12291230
}
12301231

12311232
pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_preimage: PaymentPreimage) {
@@ -1339,7 +1340,8 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
13391340
assert_eq!(hop.pubkey, node.node.get_our_node_id());
13401341
}
13411342

1342-
send_along_route(origin_node, route, expected_route, recv_value)
1343+
let res = send_along_route(origin_node, route, expected_route, recv_value);
1344+
(res.0, res.1, res.2)
13431345
}
13441346

13451347
pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3689,7 +3689,7 @@ fn test_funding_peer_disconnect() {
36893689
nodes[0].net_graph_msg_handler.handle_channel_update(&as_update).unwrap();
36903690

36913691
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
3692-
let (payment_preimage, _, _) = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000);
3692+
let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
36933693
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
36943694

36953695
// Check that after deserialization and reconnection we can still generate an identical

lightning/src/ln/onion_route_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ fn test_onion_failure() {
479479

480480
// Test a positive test-case with one extra msat, meeting the minimum.
481481
bogus_route.paths[0][route_len-1].fee_msat = amt_to_forward + 1;
482-
let (preimage, _, _) = send_along_route(&nodes[0], bogus_route, &[&nodes[1], &nodes[2]], amt_to_forward+1);
482+
let preimage = send_along_route(&nodes[0], bogus_route, &[&nodes[1], &nodes[2]], amt_to_forward+1).0;
483483
claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], preimage);
484484

485485
//TODO: with new config API, we will be able to generate both valid and

lightning/src/ln/payment_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
301301

302302
// Send two payments - one which will get to nodes[2] and will be claimed, one which we'll time
303303
// out and retry.
304-
let payment_preimage_1 = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000).0;
305304
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000);
305+
let (payment_preimage_1, _, _, payment_id_1) = send_along_route(&nodes[0], route.clone(), &[&nodes[1], &nodes[2]], 1_000_000);
306306
let payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)).unwrap();
307307
check_added_monitors!(nodes[0], 1);
308308

@@ -445,6 +445,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
445445
// received and claimed at the recipient just like any other payment.
446446
let (new_route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000);
447447

448+
assert!(nodes[0].node.retry_payment(&new_route, payment_id_1).is_err()); // Shouldn't be allowed to retry a fulfilled payment
448449
nodes[0].node.retry_payment(&new_route, payment_id).unwrap();
449450
check_added_monitors!(nodes[0], 1);
450451
let mut events = nodes[0].node.get_and_clear_pending_msg_events();

0 commit comments

Comments
 (0)