Skip to content

Commit 72f647a

Browse files
committed
Test basic AMP payments in chanmon_consistency
1 parent 596afd1 commit 72f647a

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
@@ -427,7 +427,7 @@ pub fn do_test(data: &[u8]) {
427427
test_return!();
428428
}
429429
} };
430-
($source: expr, $middle: expr, $dest: expr) => { {
430+
($source: expr, $middle: expr, $dest: expr, false) => { {
431431
let payment_hash = Sha256::hash(&[payment_id; 1]);
432432
payment_id = payment_id.wrapping_add(1);
433433
if let Err(_) = $source.send_payment(Route {
@@ -450,6 +450,46 @@ pub fn do_test(data: &[u8]) {
450450
// Probably ran out of funds
451451
test_return!();
452452
}
453+
} };
454+
($source: expr, $middle: expr, $dest: expr, true) => { {
455+
let payment_hash = Sha256::hash(&[payment_id; 1]);
456+
payment_id = payment_id.wrapping_add(1);
457+
let payment_secret = Sha256::hash(&[payment_id; 1]);
458+
payment_id = payment_id.wrapping_add(1);
459+
if let Err(_) = $source.send_payment(Route {
460+
paths: vec![vec![RouteHop {
461+
pubkey: $middle.0.get_our_node_id(),
462+
node_features: NodeFeatures::empty(),
463+
short_channel_id: $middle.1,
464+
channel_features: ChannelFeatures::empty(),
465+
fee_msat: 50000,
466+
cltv_expiry_delta: 100,
467+
},RouteHop {
468+
pubkey: $dest.0.get_our_node_id(),
469+
node_features: NodeFeatures::empty(),
470+
short_channel_id: $dest.1,
471+
channel_features: ChannelFeatures::empty(),
472+
fee_msat: 5000000,
473+
cltv_expiry_delta: 200,
474+
}],vec![RouteHop {
475+
pubkey: $middle.0.get_our_node_id(),
476+
node_features: NodeFeatures::empty(),
477+
short_channel_id: $middle.1,
478+
channel_features: ChannelFeatures::empty(),
479+
fee_msat: 50000,
480+
cltv_expiry_delta: 100,
481+
},RouteHop {
482+
pubkey: $dest.0.get_our_node_id(),
483+
node_features: NodeFeatures::empty(),
484+
short_channel_id: $dest.1,
485+
channel_features: ChannelFeatures::empty(),
486+
fee_msat: 5000000,
487+
cltv_expiry_delta: 200,
488+
}]],
489+
}, PaymentHash(payment_hash.into_inner()), Some(&payment_secret.into_inner())) {
490+
// Probably ran out of funds
491+
test_return!();
492+
}
453493
} }
454494
}
455495

@@ -604,12 +644,12 @@ pub fn do_test(data: &[u8]) {
604644
});
605645
for event in events.drain(..) {
606646
match event {
607-
events::Event::PaymentReceived { payment_hash, .. } => {
647+
events::Event::PaymentReceived { payment_hash, payment_secret, .. } => {
608648
if claim_set.insert(payment_hash.0) {
609649
if $fail {
610-
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &None));
650+
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &payment_secret));
611651
} else {
612-
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &None, 5_000_000));
652+
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, 5_000_000));
613653
}
614654
}
615655
},
@@ -638,8 +678,8 @@ pub fn do_test(data: &[u8]) {
638678
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a)),
639679
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b)),
640680
0x0c => send_payment!(nodes[2], (&nodes[1], chan_b)),
641-
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
642-
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
681+
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), false),
682+
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), false),
643683
0x0f => {
644684
if !chan_a_disconnected {
645685
nodes[0].peer_disconnected(&nodes[1].get_our_node_id(), false);
@@ -722,6 +762,8 @@ pub fn do_test(data: &[u8]) {
722762
nodes[2] = node_c.clone();
723763
monitor_c = new_monitor_c;
724764
},
765+
0x22 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), true),
766+
0x23 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), true),
725767
_ => test_return!(),
726768
}
727769

0 commit comments

Comments
 (0)