Skip to content

Commit 2e22006

Browse files
committed
f - functions instead of macros
1 parent cacfa05 commit 2e22006

File tree

1 file changed

+31
-37
lines changed

1 file changed

+31
-37
lines changed

lightning/src/ln/offers_tests.rs

+31-37
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,35 @@ macro_rules! expect_recent_payment {
3838
}
3939
}
4040

41-
macro_rules! route_payment {
42-
($node: expr, $path: expr, $invoice: expr) => {
43-
{
44-
// Monitor added when handling the invoice onion message.
45-
check_added_monitors($node, 1);
46-
47-
let mut events = $node.node.get_and_clear_pending_msg_events();
48-
assert_eq!(events.len(), 1);
49-
let ev = remove_first_msg_event_to_node(&$path[0].node.get_our_node_id(), &mut events);
50-
51-
// Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
52-
// invoice contains the payment_hash but it was encrypted inside an onion message.
53-
let amount_msats = $invoice.amount_msats();
54-
let payment_hash = $invoice.payment_hash();
55-
do_pass_along_path(
56-
$node, $path, amount_msats, payment_hash, None, ev, false, false, None, false
57-
);
58-
}
59-
}
41+
fn route_bolt12_payment<'a, 'b, 'c>(
42+
node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice
43+
) {
44+
// Monitor added when handling the invoice onion message.
45+
check_added_monitors(node, 1);
46+
47+
let mut events = node.node.get_and_clear_pending_msg_events();
48+
assert_eq!(events.len(), 1);
49+
let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
50+
51+
// Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
52+
// invoice contains the payment_hash but it was encrypted inside an onion message.
53+
let amount_msats = invoice.amount_msats();
54+
let payment_hash = invoice.payment_hash();
55+
do_pass_along_path(
56+
node, path, amount_msats, payment_hash, None, ev, false, false, None, false
57+
);
6058
}
6159

62-
macro_rules! claim_payment {
63-
($node: expr, $path: expr) => {
64-
{
65-
let recipient = &$path[$path.len() - 1];
66-
match get_event!(recipient, Event::PaymentClaimable) {
67-
Event::PaymentClaimable {
68-
purpose: PaymentPurpose::InvoicePayment {
69-
payment_preimage: Some(payment_preimage), ..
70-
}, ..
71-
} => claim_payment($node, $path, payment_preimage),
72-
_ => panic!(),
73-
};
74-
}
75-
}
60+
fn claim_bolt12_payment<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>]) {
61+
let recipient = &path[path.len() - 1];
62+
match get_event!(recipient, Event::PaymentClaimable) {
63+
Event::PaymentClaimable {
64+
purpose: PaymentPurpose::InvoicePayment {
65+
payment_preimage: Some(payment_preimage), ..
66+
}, ..
67+
} => claim_payment(node, path, payment_preimage),
68+
_ => panic!(),
69+
};
7670
}
7771

7872
fn extract_invoice_request<'a, 'b, 'c>(
@@ -157,10 +151,10 @@ fn creates_and_pays_for_offer_using_blinded_paths() {
157151
assert_eq!(path.introduction_node_id, alice_id);
158152
}
159153

160-
route_payment!(bob, &[alice], invoice);
154+
route_bolt12_payment(bob, &[alice], &invoice);
161155
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
162156

163-
claim_payment!(bob, &[alice]);
157+
claim_bolt12_payment(bob, &[alice]);
164158
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
165159
}
166160

@@ -211,9 +205,9 @@ fn creates_and_pays_for_refund_using_blinded_paths() {
211205
assert_eq!(path.introduction_node_id, alice_id);
212206
}
213207

214-
route_payment!(bob, &[alice], invoice);
208+
route_bolt12_payment(bob, &[alice], &invoice);
215209
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
216210

217-
claim_payment!(bob, &[alice]);
211+
claim_bolt12_payment(bob, &[alice]);
218212
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
219213
}

0 commit comments

Comments
 (0)