Skip to content

Commit e027783

Browse files
committed
Clean up tests which rely on block count constants indirectly
Over the years we've built up a few tests which rely on block count constants but without making direct references to those constants. Here we fix three such tests to ensure changing block count constants in the next commit do not break tests.
1 parent d18fc72 commit e027783

8 files changed

+56
-10
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,13 @@ fn async_receive_mpp() {
540540
create_announced_chan_between_nodes(&nodes, 0, 2);
541541
create_unannounced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0);
542542
create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0);
543+
544+
// Ensure all nodes start at the same height.
545+
connect_blocks(&nodes[0], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
546+
connect_blocks(&nodes[1], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
547+
connect_blocks(&nodes[2], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
548+
connect_blocks(&nodes[3], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
549+
543550
let (offer, static_invoice) = create_static_invoice(&nodes[1], &nodes[3], None, &secp_ctx);
544551

545552
// In other tests we hardcode the sender's random bytes so we can predict the keysend preimage to
@@ -622,6 +629,12 @@ fn amount_doesnt_match_invreq() {
622629
create_unannounced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0);
623630
create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0);
624631

632+
// Ensure all nodes start at the same height.
633+
connect_blocks(&nodes[0], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
634+
connect_blocks(&nodes[1], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
635+
connect_blocks(&nodes[2], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
636+
connect_blocks(&nodes[3], 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
637+
625638
let (offer, static_invoice) = create_static_invoice(&nodes[1], &nodes[3], None, &secp_ctx);
626639

627640
// Set the random bytes so we can predict the payment preimage and hash.
@@ -815,9 +828,15 @@ fn invalid_async_receive_with_retry<F1, F2>(
815828
let node_chanmgrs =
816829
create_node_chanmgrs(3, &node_cfgs, &[None, Some(allow_priv_chan_fwds_cfg), None]);
817830
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
831+
818832
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
819833
create_unannounced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0);
820834

835+
// Ensure all nodes start at the same height.
836+
connect_blocks(&nodes[0], 2 * CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
837+
connect_blocks(&nodes[1], 2 * CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
838+
connect_blocks(&nodes[2], 2 * CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
839+
821840
let blinded_paths_to_always_online_node = nodes[1]
822841
.message_router
823842
.create_blinded_paths(

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ fn mpp_to_one_hop_blinded_path() {
204204
let chan_upd_1_3 = create_announced_chan_between_nodes(&nodes, 1, 3).0.contents;
205205
create_announced_chan_between_nodes(&nodes, 2, 3).0.contents;
206206

207+
// Ensure all nodes start at the same height.
208+
connect_blocks(&nodes[0], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
209+
connect_blocks(&nodes[1], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
210+
connect_blocks(&nodes[2], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
211+
connect_blocks(&nodes[3], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
212+
207213
let amt_msat = 15_000_000;
208214
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
209215
let payee_tlvs = UnauthenticatedReceiveTlvs {
@@ -267,6 +273,14 @@ fn mpp_to_three_hop_blinded_paths() {
267273
let chan_upd_3_5 = create_announced_chan_between_nodes(&nodes, 3, 5).0.contents;
268274
let chan_upd_4_5 = create_announced_chan_between_nodes(&nodes, 4, 5).0.contents;
269275

276+
// Start every node on the same block height to make reasoning about timeouts easier
277+
connect_blocks(&nodes[0], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
278+
connect_blocks(&nodes[1], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
279+
connect_blocks(&nodes[2], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
280+
connect_blocks(&nodes[3], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
281+
connect_blocks(&nodes[4], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[4].best_block_info().1);
282+
connect_blocks(&nodes[5], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[5].best_block_info().1);
283+
270284
let amt_msat = 15_000_000;
271285
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[5], Some(amt_msat), None);
272286
let route_params = {
@@ -1070,6 +1084,12 @@ fn blinded_path_retries() {
10701084
let chan_1_3 = create_announced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0);
10711085
let chan_2_3 = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0);
10721086

1087+
// Ensure all nodes start at the same height.
1088+
connect_blocks(&nodes[0], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
1089+
connect_blocks(&nodes[1], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
1090+
connect_blocks(&nodes[2], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
1091+
connect_blocks(&nodes[3], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
1092+
10731093
let amt_msat = 5000;
10741094
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
10751095
let route_params = {

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15994,15 +15994,15 @@ mod tests {
1599415994
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
1599515995
let result = create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive(msgs::InboundOnionReceivePayload {
1599615996
sender_intended_htlc_amt_msat: 100,
15997-
cltv_expiry_height: 22,
15997+
cltv_expiry_height: TEST_FINAL_CLTV,
1599815998
payment_metadata: None,
1599915999
keysend_preimage: None,
1600016000
payment_data: Some(msgs::FinalOnionHopData {
1600116001
payment_secret: PaymentSecret([0; 32]),
1600216002
total_msat: 100,
1600316003
}),
1600416004
custom_tlvs: Vec::new(),
16005-
}), [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None, current_height);
16005+
}), [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, current_height);
1600616006

1600716007
// Should not return an error as this condition:
1600816008
// https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7828,7 +7828,7 @@ pub fn test_bump_penalty_txn_on_revoked_commitment() {
78287828
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
78297829

78307830
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
7831-
let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 30)
7831+
let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), TEST_FINAL_CLTV)
78327832
.with_bolt11_features(nodes[0].node.bolt11_invoice_features()).unwrap();
78337833
let (route,_, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_params, 3000000);
78347834
send_along_route(&nodes[1], route, &vec!(&nodes[0])[..], 3000000);

lightning/src/ln/invoice_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ mod test {
711711
use bitcoin::hashes::sha256::Hash as Sha256;
712712
use bitcoin::network::Network;
713713
use crate::sign::PhantomKeysManager;
714+
use crate::chain::channelmonitor::HTLC_FAIL_BACK_BUFFER;
714715
use crate::types::payment::{PaymentHash, PaymentPreimage};
715716
use crate::ln::channelmanager::{Bolt11InvoiceParameters, PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
716717
use crate::ln::functional_test_utils::*;
@@ -843,7 +844,7 @@ mod test {
843844
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
844845
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
845846

846-
let custom_min_final_cltv_expiry_delta = Some(21);
847+
let custom_min_final_cltv_expiry_delta = Some(HTLC_FAIL_BACK_BUFFER as u16);
847848
let description = Bolt11InvoiceDescription::Direct(Description::empty());
848849
let invoice_params = Bolt11InvoiceParameters {
849850
amount_msats: Some(10_000),

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ fn one_hop_blinded_path_with_custom_tlv() {
156156
create_announced_chan_between_nodes(&nodes, 0, 1);
157157
let chan_upd_1_2 = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0).0.contents;
158158

159+
// Start with all nodes at the same height
160+
connect_blocks(&nodes[0], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
161+
connect_blocks(&nodes[1], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
162+
connect_blocks(&nodes[2], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
163+
159164
// Construct the route parameters for sending to nodes[2]'s 1-hop blinded path.
160165
let amt_msat = 100_000;
161166
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);

lightning/src/ln/onion_payment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ mod tests {
493493
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
494494
use crate::ln::types::ChannelId;
495495
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
496-
use crate::ln::channelmanager::RecipientOnionFields;
496+
use crate::ln::channelmanager::{RecipientOnionFields, MIN_CLTV_EXPIRY_DELTA};
497+
use crate::ln::functional_test_utils::TEST_FINAL_CLTV;
497498
use crate::types::features::{ChannelFeatures, NodeFeatures};
498499
use crate::ln::msgs;
499500
use crate::ln::onion_utils::create_payment_onion;
@@ -624,7 +625,7 @@ mod tests {
624625
RouteHop {
625626
pubkey: hop_pk,
626627
fee_msat: hop_fee,
627-
cltv_expiry_delta: 42,
628+
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA as u32,
628629
short_channel_id: 1,
629630
node_features: NodeFeatures::empty(),
630631
channel_features: ChannelFeatures::empty(),
@@ -633,7 +634,7 @@ mod tests {
633634
RouteHop {
634635
pubkey: recipient_pk,
635636
fee_msat: recipient_amount,
636-
cltv_expiry_delta: 42,
637+
cltv_expiry_delta: TEST_FINAL_CLTV,
637638
short_channel_id: 2,
638639
node_features: NodeFeatures::empty(),
639640
channel_features: ChannelFeatures::empty(),

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn test_routed_scid_alias() {
246246
htlc_maximum_msat: None,
247247
htlc_minimum_msat: None,
248248
}])];
249-
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
249+
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
250250
.with_bolt11_features(nodes[2].node.bolt11_invoice_features()).unwrap()
251251
.with_route_hints(hop_hints).unwrap();
252252
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
@@ -412,7 +412,7 @@ fn test_inbound_scid_privacy() {
412412
htlc_maximum_msat: None,
413413
htlc_minimum_msat: None,
414414
}])];
415-
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
415+
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
416416
.with_bolt11_features(nodes[2].node.bolt11_invoice_features()).unwrap()
417417
.with_route_hints(hop_hints.clone()).unwrap();
418418
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
@@ -428,7 +428,7 @@ fn test_inbound_scid_privacy() {
428428
// what channel we're talking about.
429429
hop_hints[0].0[0].short_channel_id = last_hop[0].short_channel_id.unwrap();
430430

431-
let payment_params_2 = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
431+
let payment_params_2 = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
432432
.with_bolt11_features(nodes[2].node.bolt11_invoice_features()).unwrap()
433433
.with_route_hints(hop_hints).unwrap();
434434
let (route_2, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params_2, 100_000);

0 commit comments

Comments
 (0)