Skip to content

Commit 09fca09

Browse files
committed
test: update tests due to connect_open_channel decomposition
What this commit does: + Replaces calls to `connect_open_channel` with `open_channel` and `open_announced_channel` where appropriate. Status: Work In Progress (WIP) Observation: + The integration tests are now flaky and need further investigation to ascertain the reason(s) why and then to fix.
1 parent 059a30e commit 09fca09

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

tests/common/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
use ldk_node::io::sqlite_store::SqliteStore;
1212
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentStatus};
1313
use ldk_node::{
14-
Builder, Config, Event, LightningBalance, LogLevel, Node, NodeError, PendingSweepBalance,
14+
sanitize_alias, Builder, Config, Event, LightningBalance, LogLevel, Node, NodeError,
15+
PendingSweepBalance,
1516
};
1617

1718
use lightning::ln::msgs::SocketAddress;
1819
use lightning::ln::{PaymentHash, PaymentPreimage};
20+
use lightning::routing::gossip::NodeAlias;
1921
use lightning::util::persist::KVStore;
2022
use lightning::util::test_utils::TestStore;
2123
use lightning_persister::fs_store::FilesystemStore;
@@ -200,12 +202,12 @@ pub(crate) fn random_listening_addresses() -> Vec<SocketAddress> {
200202
listening_addresses
201203
}
202204

203-
pub(crate) fn random_node_alias() -> Option<String> {
205+
pub(crate) fn random_node_alias() -> Option<NodeAlias> {
204206
let mut rng = thread_rng();
205207
let ranged_val = rng.gen_range(0..10);
206208
match ranged_val {
207209
0 => None,
208-
val => Some(format!("ldk-node-{}", val)),
210+
val => Some(sanitize_alias(&format!("ldk-node-{}", val)).unwrap()),
209211
}
210212
}
211213

@@ -398,17 +400,15 @@ pub(crate) fn premine_and_distribute_funds<E: ElectrumApi>(
398400
}
399401

400402
pub fn open_channel(
401-
node_a: &TestNode, node_b: &TestNode, funding_amount_sat: u64, announce: bool,
402-
electrsd: &ElectrsD,
403+
node_a: &TestNode, node_b: &TestNode, funding_amount_sat: u64, electrsd: &ElectrsD,
403404
) {
404405
node_a
405-
.connect_open_channel(
406+
.open_announced_channel(
406407
node_b.node_id(),
407408
node_b.listening_addresses().unwrap().first().unwrap().clone(),
408409
funding_amount_sat,
409410
None,
410411
None,
411-
announce,
412412
)
413413
.unwrap();
414414
assert!(node_a.list_peers().iter().find(|c| { c.node_id == node_b.node_id() }).is_some());
@@ -447,13 +447,12 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
447447
let funding_amount_sat = 2_080_000;
448448
let push_msat = (funding_amount_sat / 2) * 1000; // balance the channel
449449
node_a
450-
.connect_open_channel(
450+
.open_channel(
451451
node_b.node_id(),
452452
node_b.listening_addresses().unwrap().first().unwrap().clone(),
453453
funding_amount_sat,
454454
Some(push_msat),
455455
None,
456-
true,
457456
)
458457
.unwrap();
459458

tests/integration_tests_cln.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,8 @@ fn test_cln() {
8282
// Open the channel
8383
let funding_amount_sat = 1_000_000;
8484

85-
node.connect_open_channel(
86-
cln_node_id,
87-
cln_address,
88-
funding_amount_sat,
89-
Some(500_000_000),
90-
None,
91-
false,
92-
)
93-
.unwrap();
85+
node.open_channel(cln_node_id, cln_address, funding_amount_sat, Some(500_000_000), None)
86+
.unwrap();
9487

9588
let funding_txo = common::expect_channel_pending_event!(node, cln_node_id);
9689
common::wait_for_tx(&electrs_client, funding_txo.txid);

tests/integration_tests_rust.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ fn channel_open_fails_when_funds_insufficient() {
8383
println!("\nA -- connect_open_channel -> B");
8484
assert_eq!(
8585
Err(NodeError::InsufficientFunds),
86-
node_a.connect_open_channel(
86+
node_a.open_channel(
8787
node_b.node_id(),
8888
node_b.listening_addresses().unwrap().first().unwrap().clone(),
8989
120000,
9090
None,
9191
None,
92-
true
9392
)
9493
);
9594
}
@@ -132,16 +131,16 @@ fn multi_hop_sending() {
132131
// \ /
133132
// (1M:0)- N3 -(1M:0)
134133

135-
open_channel(&nodes[0], &nodes[1], 100_000, true, &electrsd);
136-
open_channel(&nodes[1], &nodes[2], 1_000_000, true, &electrsd);
134+
open_channel(&nodes[0], &nodes[1], 100_000, &electrsd);
135+
open_channel(&nodes[1], &nodes[2], 1_000_000, &electrsd);
137136
// We need to sync wallets in-between back-to-back channel opens from the same node so BDK
138137
// wallet picks up on the broadcast funding tx and doesn't double-spend itself.
139138
//
140139
// TODO: Remove once fixed in BDK.
141140
nodes[1].sync_wallets().unwrap();
142-
open_channel(&nodes[1], &nodes[3], 1_000_000, true, &electrsd);
143-
open_channel(&nodes[2], &nodes[4], 1_000_000, true, &electrsd);
144-
open_channel(&nodes[3], &nodes[4], 1_000_000, true, &electrsd);
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);
145144

146145
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
147146

@@ -419,7 +418,7 @@ fn simple_bolt12_send_receive() {
419418
);
420419

421420
node_a.sync_wallets().unwrap();
422-
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
421+
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
423422

424423
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
425424

@@ -626,7 +625,7 @@ fn generate_bip21_uri() {
626625
);
627626

628627
node_a.sync_wallets().unwrap();
629-
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
628+
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
630629
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
631630

632631
node_a.sync_wallets().unwrap();
@@ -667,7 +666,7 @@ fn unified_qr_send_receive() {
667666
);
668667

669668
node_a.sync_wallets().unwrap();
670-
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
669+
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
671670
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
672671

673672
node_a.sync_wallets().unwrap();

0 commit comments

Comments
 (0)