Skip to content

Commit 534b1ac

Browse files
committed
Make announcing channels in tests a choice again
Previously, we always opened announced channels in tests, but it should be a deliberate choice depending on the scenario we're trying to test for.
1 parent 58f40b9 commit 534b1ac

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

tests/common/mod.rs

+29-21
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,11 @@ pub(crate) fn random_listening_addresses() -> Vec<SocketAddress> {
203203

204204
pub(crate) fn random_node_alias() -> Option<NodeAlias> {
205205
let mut rng = thread_rng();
206-
let ranged_val = rng.gen_range(0..10);
207-
match ranged_val {
208-
0 => None,
209-
val => {
210-
let alias = format!("ldk-node-{}", val);
211-
let mut bytes = [0u8; 32];
212-
bytes[..alias.as_bytes().len()].copy_from_slice(alias.as_bytes());
213-
Some(NodeAlias(bytes))
214-
},
215-
}
206+
let rand_val = rng.gen_range(0..1000);
207+
let alias = format!("ldk-node-{}", rand_val);
208+
let mut bytes = [0u8; 32];
209+
bytes[..alias.as_bytes().len()].copy_from_slice(alias.as_bytes());
210+
Some(NodeAlias(bytes))
216211
}
217212

218213
pub(crate) fn random_config(anchor_channels: bool) -> Config {
@@ -404,17 +399,30 @@ pub(crate) fn premine_and_distribute_funds<E: ElectrumApi>(
404399
}
405400

406401
pub fn open_channel(
407-
node_a: &TestNode, node_b: &TestNode, funding_amount_sat: u64, electrsd: &ElectrsD,
402+
node_a: &TestNode, node_b: &TestNode, funding_amount_sat: u64, should_announce: bool,
403+
electrsd: &ElectrsD,
408404
) {
409-
node_a
410-
.open_announced_channel(
411-
node_b.node_id(),
412-
node_b.listening_addresses().unwrap().first().unwrap().clone(),
413-
funding_amount_sat,
414-
None,
415-
None,
416-
)
417-
.unwrap();
405+
if should_announce {
406+
node_a
407+
.open_announced_channel(
408+
node_b.node_id(),
409+
node_b.listening_addresses().unwrap().first().unwrap().clone(),
410+
funding_amount_sat,
411+
None,
412+
None,
413+
)
414+
.unwrap();
415+
} else {
416+
node_a
417+
.open_channel(
418+
node_b.node_id(),
419+
node_b.listening_addresses().unwrap().first().unwrap().clone(),
420+
funding_amount_sat,
421+
None,
422+
None,
423+
)
424+
.unwrap();
425+
}
418426
assert!(node_a.list_peers().iter().find(|c| { c.node_id == node_b.node_id() }).is_some());
419427

420428
let funding_txo_a = expect_channel_pending_event!(node_a, node_b.node_id());
@@ -451,7 +459,7 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
451459
let funding_amount_sat = 2_080_000;
452460
let push_msat = (funding_amount_sat / 2) * 1000; // balance the channel
453461
node_a
454-
.open_channel(
462+
.open_announced_channel(
455463
node_b.node_id(),
456464
node_b.listening_addresses().unwrap().first().unwrap().clone(),
457465
funding_amount_sat,

tests/integration_tests_rust.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,16 @@ fn multi_hop_sending() {
131131
// \ /
132132
// (1M:0)- N3 -(1M:0)
133133

134-
open_channel(&nodes[0], &nodes[1], 100_000, &electrsd);
135-
open_channel(&nodes[1], &nodes[2], 1_000_000, &electrsd);
134+
open_channel(&nodes[0], &nodes[1], 100_000, true, &electrsd);
135+
open_channel(&nodes[1], &nodes[2], 1_000_000, true, &electrsd);
136136
// We need to sync wallets in-between back-to-back channel opens from the same node so BDK
137137
// wallet picks up on the broadcast funding tx and doesn't double-spend itself.
138138
//
139139
// TODO: Remove once fixed in BDK.
140140
nodes[1].sync_wallets().unwrap();
141-
open_channel(&nodes[1], &nodes[3], 1_000_000, &electrsd);
142-
open_channel(&nodes[2], &nodes[4], 1_000_000, &electrsd);
143-
open_channel(&nodes[3], &nodes[4], 1_000_000, &electrsd);
141+
open_channel(&nodes[1], &nodes[3], 1_000_000, true, &electrsd);
142+
open_channel(&nodes[2], &nodes[4], 1_000_000, true, &electrsd);
143+
open_channel(&nodes[3], &nodes[4], 1_000_000, true, &electrsd);
144144

145145
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
146146

@@ -418,7 +418,7 @@ fn simple_bolt12_send_receive() {
418418
);
419419

420420
node_a.sync_wallets().unwrap();
421-
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
421+
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
422422

423423
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
424424

@@ -625,7 +625,7 @@ fn generate_bip21_uri() {
625625
);
626626

627627
node_a.sync_wallets().unwrap();
628-
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
628+
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
629629
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
630630

631631
node_a.sync_wallets().unwrap();
@@ -666,7 +666,7 @@ fn unified_qr_send_receive() {
666666
);
667667

668668
node_a.sync_wallets().unwrap();
669-
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
669+
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
670670
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
671671

672672
node_a.sync_wallets().unwrap();

0 commit comments

Comments
 (0)