Skip to content

Commit

Permalink
test: update tests due to connect_open_channel decomposition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
enigbe committed Aug 29, 2024
1 parent fc5e626 commit db5456b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
17 changes: 8 additions & 9 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
use ldk_node::io::sqlite_store::SqliteStore;
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentStatus};
use ldk_node::{
Builder, Config, Event, LightningBalance, LogLevel, Node, NodeError, PendingSweepBalance,
sanitize_alias, Builder, Config, Event, LightningBalance, LogLevel, Node, NodeError,
PendingSweepBalance,
};

use lightning::ln::msgs::SocketAddress;
use lightning::ln::{PaymentHash, PaymentPreimage};
use lightning::routing::gossip::NodeAlias;
use lightning::util::persist::KVStore;
use lightning::util::test_utils::TestStore;
use lightning_persister::fs_store::FilesystemStore;
Expand Down Expand Up @@ -193,12 +195,12 @@ pub(crate) fn random_listening_addresses() -> Vec<SocketAddress> {
listening_addresses
}

pub(crate) fn random_node_alias() -> Option<String> {
pub(crate) fn random_node_alias() -> Option<NodeAlias> {
let mut rng = thread_rng();
let ranged_val = rng.gen_range(0..10);
match ranged_val {
0 => None,
val => Some(format!("ldk-node-{}", val)),
val => Some(sanitize_alias(&format!("ldk-node-{}", val)).unwrap()),
}
}

Expand Down Expand Up @@ -391,17 +393,15 @@ pub(crate) fn premine_and_distribute_funds<E: ElectrumApi>(
}

pub fn open_channel(
node_a: &TestNode, node_b: &TestNode, funding_amount_sat: u64, announce: bool,
electrsd: &ElectrsD,
node_a: &TestNode, node_b: &TestNode, funding_amount_sat: u64, electrsd: &ElectrsD,
) {
node_a
.connect_open_channel(
.open_announced_channel(
node_b.node_id(),
node_b.listening_addresses().unwrap().first().unwrap().clone(),
funding_amount_sat,
None,
None,
announce,
)
.unwrap();
assert!(node_a.list_peers().iter().find(|c| { c.node_id == node_b.node_id() }).is_some());
Expand Down Expand Up @@ -440,13 +440,12 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
let funding_amount_sat = 2_080_000;
let push_msat = (funding_amount_sat / 2) * 1000; // balance the channel
node_a
.connect_open_channel(
.open_channel(
node_b.node_id(),
node_b.listening_addresses().unwrap().first().unwrap().clone(),
funding_amount_sat,
Some(push_msat),
None,
true,
)
.unwrap();

Expand Down
11 changes: 2 additions & 9 deletions tests/integration_tests_cln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ fn test_cln() {
// Open the channel
let funding_amount_sat = 1_000_000;

node.connect_open_channel(
cln_node_id,
cln_address,
funding_amount_sat,
Some(500_000_000),
None,
false,
)
.unwrap();
node.open_channel(cln_node_id, cln_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, cln_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid);
Expand Down
19 changes: 9 additions & 10 deletions tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ fn channel_open_fails_when_funds_insufficient() {
println!("\nA -- connect_open_channel -> B");
assert_eq!(
Err(NodeError::InsufficientFunds),
node_a.connect_open_channel(
node_a.open_channel(
node_b.node_id(),
node_b.listening_addresses().unwrap().first().unwrap().clone(),
120000,
None,
None,
true
)
);
}
Expand Down Expand Up @@ -125,16 +124,16 @@ fn multi_hop_sending() {
// \ /
// (1M:0)- N3 -(1M:0)

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

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

Expand Down Expand Up @@ -412,7 +411,7 @@ fn simple_bolt12_send_receive() {
);

node_a.sync_wallets().unwrap();
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
open_channel(&node_a, &node_b, 4_000_000, &electrsd);

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

Expand Down Expand Up @@ -619,7 +618,7 @@ fn generate_bip21_uri() {
);

node_a.sync_wallets().unwrap();
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);

node_a.sync_wallets().unwrap();
Expand Down Expand Up @@ -660,7 +659,7 @@ fn unified_qr_send_receive() {
);

node_a.sync_wallets().unwrap();
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
open_channel(&node_a, &node_b, 4_000_000, &electrsd);
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);

node_a.sync_wallets().unwrap();
Expand Down

0 comments on commit db5456b

Please sign in to comment.