Skip to content

Commit 0b4079d

Browse files
authored
Merge pull request #967 from valentinewallace/2021-06-keysend
Keysend
2 parents d37b1dd + 6dd6289 commit 0b4079d

10 files changed

+872
-242
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

+43-18
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler};
2828
use routing::router::get_route;
2929
use util::config::UserConfig;
3030
use util::enforcing_trait_impls::EnforcingSigner;
31-
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider};
31+
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose};
3232
use util::errors::APIError;
3333
use util::ser::{ReadableArgs, Writeable};
3434
use util::test_utils::TestBroadcaster;
@@ -220,11 +220,16 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail
220220
let events_3 = nodes[1].node.get_and_clear_pending_events();
221221
assert_eq!(events_3.len(), 1);
222222
match events_3[0] {
223-
Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
223+
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
224224
assert_eq!(payment_hash_1, *payment_hash);
225-
assert!(payment_preimage.is_none());
226-
assert_eq!(payment_secret_1, *payment_secret);
227225
assert_eq!(amt, 1000000);
226+
match &purpose {
227+
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
228+
assert!(payment_preimage.is_none());
229+
assert_eq!(payment_secret_1, *payment_secret);
230+
},
231+
_ => panic!("expected PaymentPurpose::InvoicePayment")
232+
}
228233
},
229234
_ => panic!("Unexpected event"),
230235
}
@@ -589,11 +594,16 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
589594
let events_5 = nodes[1].node.get_and_clear_pending_events();
590595
assert_eq!(events_5.len(), 1);
591596
match events_5[0] {
592-
Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
597+
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
593598
assert_eq!(payment_hash_2, *payment_hash);
594-
assert!(payment_preimage.is_none());
595-
assert_eq!(payment_secret_2, *payment_secret);
596599
assert_eq!(amt, 1000000);
600+
match &purpose {
601+
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
602+
assert!(payment_preimage.is_none());
603+
assert_eq!(payment_secret_2, *payment_secret);
604+
},
605+
_ => panic!("expected PaymentPurpose::InvoicePayment")
606+
}
597607
},
598608
_ => panic!("Unexpected event"),
599609
}
@@ -704,11 +714,16 @@ fn test_monitor_update_fail_cs() {
704714
let events = nodes[1].node.get_and_clear_pending_events();
705715
assert_eq!(events.len(), 1);
706716
match events[0] {
707-
Event::PaymentReceived { payment_hash, payment_preimage, payment_secret, amt, user_payment_id: _ } => {
717+
Event::PaymentReceived { payment_hash, ref purpose, amt } => {
708718
assert_eq!(payment_hash, our_payment_hash);
709-
assert!(payment_preimage.is_none());
710-
assert_eq!(our_payment_secret, payment_secret);
711719
assert_eq!(amt, 1000000);
720+
match &purpose {
721+
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
722+
assert!(payment_preimage.is_none());
723+
assert_eq!(our_payment_secret, *payment_secret);
724+
},
725+
_ => panic!("expected PaymentPurpose::InvoicePayment")
726+
}
712727
},
713728
_ => panic!("Unexpected event"),
714729
};
@@ -1712,20 +1727,30 @@ fn test_monitor_update_fail_claim() {
17121727
let events = nodes[0].node.get_and_clear_pending_events();
17131728
assert_eq!(events.len(), 2);
17141729
match events[0] {
1715-
Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
1730+
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
17161731
assert_eq!(payment_hash_2, *payment_hash);
1717-
assert!(payment_preimage.is_none());
1718-
assert_eq!(payment_secret_2, *payment_secret);
17191732
assert_eq!(1_000_000, amt);
1733+
match &purpose {
1734+
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
1735+
assert!(payment_preimage.is_none());
1736+
assert_eq!(payment_secret_2, *payment_secret);
1737+
},
1738+
_ => panic!("expected PaymentPurpose::InvoicePayment")
1739+
}
17201740
},
17211741
_ => panic!("Unexpected event"),
17221742
}
17231743
match events[1] {
1724-
Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
1744+
Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
17251745
assert_eq!(payment_hash_3, *payment_hash);
1726-
assert!(payment_preimage.is_none());
1727-
assert_eq!(payment_secret_3, *payment_secret);
17281746
assert_eq!(1_000_000, amt);
1747+
match &purpose {
1748+
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
1749+
assert!(payment_preimage.is_none());
1750+
assert_eq!(payment_secret_3, *payment_secret);
1751+
},
1752+
_ => panic!("expected PaymentPurpose::InvoicePayment")
1753+
}
17291754
},
17301755
_ => panic!("Unexpected event"),
17311756
}
@@ -2014,15 +2039,15 @@ fn test_path_paused_mpp() {
20142039
// Pass the first HTLC of the payment along to nodes[3].
20152040
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
20162041
assert_eq!(events.len(), 1);
2017-
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 0, payment_hash.clone(), payment_secret, events.pop().unwrap(), false);
2042+
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 0, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), false, None);
20182043

20192044
// And check that, after we successfully update the monitor for chan_2 we can pass the second
20202045
// HTLC along to nodes[3] and claim the whole payment back to nodes[0].
20212046
let (outpoint, latest_update) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_2_id).unwrap().clone();
20222047
nodes[0].node.channel_monitor_updated(&outpoint, latest_update);
20232048
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
20242049
assert_eq!(events.len(), 1);
2025-
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), payment_secret, events.pop().unwrap(), true);
2050+
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), true, None);
20262051

20272052
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
20282053
}

0 commit comments

Comments
 (0)