Skip to content

Commit c9731ed

Browse files
committed
Test basic AMP payments in chanmon_consistency
1 parent 931e33c commit c9731ed

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ pub fn do_test(data: &[u8]) {
422422
test_return!();
423423
}
424424
} };
425-
($source: expr, $middle: expr, $dest: expr) => { {
425+
($source: expr, $middle: expr, $dest: expr, false) => { {
426426
let payment_hash = Sha256::hash(&[payment_id; 1]);
427427
payment_id = payment_id.wrapping_add(1);
428428
if let Err(_) = $source.send_payment(Route {
@@ -445,6 +445,46 @@ pub fn do_test(data: &[u8]) {
445445
// Probably ran out of funds
446446
test_return!();
447447
}
448+
} };
449+
($source: expr, $middle: expr, $dest: expr, true) => { {
450+
let payment_hash = Sha256::hash(&[payment_id; 1]);
451+
payment_id = payment_id.wrapping_add(1);
452+
let payment_secret = Sha256::hash(&[payment_id; 1]);
453+
payment_id = payment_id.wrapping_add(1);
454+
if let Err(_) = $source.send_payment(Route {
455+
paths: vec![vec![RouteHop {
456+
pubkey: $middle.0.get_our_node_id(),
457+
node_features: NodeFeatures::empty(),
458+
short_channel_id: $middle.1,
459+
channel_features: ChannelFeatures::empty(),
460+
fee_msat: 50000,
461+
cltv_expiry_delta: 100,
462+
},RouteHop {
463+
pubkey: $dest.0.get_our_node_id(),
464+
node_features: NodeFeatures::empty(),
465+
short_channel_id: $dest.1,
466+
channel_features: ChannelFeatures::empty(),
467+
fee_msat: 5000000,
468+
cltv_expiry_delta: 200,
469+
}],vec![RouteHop {
470+
pubkey: $middle.0.get_our_node_id(),
471+
node_features: NodeFeatures::empty(),
472+
short_channel_id: $middle.1,
473+
channel_features: ChannelFeatures::empty(),
474+
fee_msat: 50000,
475+
cltv_expiry_delta: 100,
476+
},RouteHop {
477+
pubkey: $dest.0.get_our_node_id(),
478+
node_features: NodeFeatures::empty(),
479+
short_channel_id: $dest.1,
480+
channel_features: ChannelFeatures::empty(),
481+
fee_msat: 5000000,
482+
cltv_expiry_delta: 200,
483+
}]],
484+
}, PaymentHash(payment_hash.into_inner()), Some(&payment_secret.into_inner())) {
485+
// Probably ran out of funds
486+
test_return!();
487+
}
448488
} }
449489
}
450490

@@ -599,12 +639,12 @@ pub fn do_test(data: &[u8]) {
599639
});
600640
for event in events.drain(..) {
601641
match event {
602-
events::Event::PaymentReceived { payment_hash, .. } => {
642+
events::Event::PaymentReceived { payment_hash, payment_secret, .. } => {
603643
if claim_set.insert(payment_hash.0) {
604644
if $fail {
605-
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &None));
645+
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &payment_secret));
606646
} else {
607-
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &None, 5_000_000));
647+
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, 5_000_000));
608648
}
609649
}
610650
},
@@ -650,8 +690,8 @@ pub fn do_test(data: &[u8]) {
650690
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a)),
651691
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b)),
652692
0x0c => send_payment!(nodes[2], (&nodes[1], chan_b)),
653-
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
654-
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
693+
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), false),
694+
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), false),
655695
0x0f => {
656696
if !chan_a_disconnected {
657697
nodes[0].peer_disconnected(&nodes[1].get_our_node_id(), false);
@@ -734,6 +774,8 @@ pub fn do_test(data: &[u8]) {
734774
nodes[2] = node_c.clone();
735775
monitor_c = new_monitor_c;
736776
},
777+
0x22 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), true),
778+
0x23 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), true),
737779
// 0x24 defined above
738780
_ => test_return!(),
739781
}

0 commit comments

Comments
 (0)