Skip to content

Commit b1b15db

Browse files
committed
Test basic AMP payments in chanmon_consistency
1 parent fe620cb commit b1b15db

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

@@ -601,12 +641,12 @@ pub fn do_test(data: &[u8]) {
601641
});
602642
for event in events.drain(..) {
603643
match event {
604-
events::Event::PaymentReceived { payment_hash, .. } => {
644+
events::Event::PaymentReceived { payment_hash, payment_secret, .. } => {
605645
if claim_set.insert(payment_hash.0) {
606646
if $fail {
607-
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &None));
647+
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &payment_secret));
608648
} else {
609-
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &None, 5_000_000));
649+
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, 5_000_000));
610650
}
611651
}
612652
},
@@ -635,8 +675,8 @@ pub fn do_test(data: &[u8]) {
635675
0x0a => send_payment!(nodes[1], (&nodes[0], chan_a)),
636676
0x0b => send_payment!(nodes[1], (&nodes[2], chan_b)),
637677
0x0c => send_payment!(nodes[2], (&nodes[1], chan_b)),
638-
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
639-
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
678+
0x0d => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), false),
679+
0x0e => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), false),
640680
0x0f => {
641681
if !chan_a_disconnected {
642682
nodes[0].peer_disconnected(&nodes[1].get_our_node_id(), false);
@@ -719,6 +759,8 @@ pub fn do_test(data: &[u8]) {
719759
nodes[2] = node_c.clone();
720760
monitor_c = new_monitor_c;
721761
},
762+
0x22 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), true),
763+
0x23 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), true),
722764
_ => test_return!(),
723765
}
724766

0 commit comments

Comments
 (0)