diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b9f9693f7..ea65ed9bd 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -171,6 +171,8 @@ pub(crate) fn setup_bitcoind_and_electrsd() -> (BitcoinD, ElectrsD) { electrsd_conf.http_enabled = true; electrsd_conf.network = "regtest"; let electrsd = ElectrsD::with_conf(electrs_exe, &bitcoind, &electrsd_conf).unwrap(); + + generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 101); (bitcoind, electrsd) } @@ -371,10 +373,19 @@ where pub(crate) fn premine_and_distribute_funds( bitcoind: &BitcoindClient, electrs: &E, addrs: Vec
, amount: Amount, ) { + premine(bitcoind, electrs); + distribute_funds(bitcoind, electrs, addrs, amount); +} + +pub(crate) fn premine(bitcoind: &BitcoindClient, electrs: &E) { let _ = bitcoind.create_wallet("ldk_node_test", None, None, None, None); let _ = bitcoind.load_wallet("ldk_node_test"); generate_blocks_and_wait(bitcoind, electrs, 101); +} +pub(crate) fn distribute_funds( + bitcoind: &BitcoindClient, electrs: &E, addrs: Vec
, amount: Amount, +) { for addr in addrs { let txid = bitcoind.send_to_address(&addr, amount, None, None, None, None, None, None).unwrap(); @@ -415,7 +426,7 @@ pub(crate) fn do_channel_full_cycle( let premine_amount_sat = if expect_anchor_channel { 2_125_000 } else { 2_100_000 }; - premine_and_distribute_funds( + distribute_funds( &bitcoind, electrsd, vec![addr_a, addr_b], diff --git a/tests/integration_tests_cln.rs b/tests/integration_tests_cln.rs index bcb84833f..f29ed18bb 100644 --- a/tests/integration_tests_cln.rs +++ b/tests/integration_tests_cln.rs @@ -40,7 +40,7 @@ fn test_cln() { let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap(); // Give electrs a kick. - common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1); + common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 101); // Setup LDK Node let config = common::random_config(true); diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index 6243f00a8..4d8ec2f0d 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -8,10 +8,10 @@ mod common; use common::{ - do_channel_full_cycle, expect_channel_ready_event, expect_event, expect_payment_received_event, - expect_payment_successful_event, generate_blocks_and_wait, open_channel, - premine_and_distribute_funds, random_config, setup_bitcoind_and_electrsd, setup_builder, - setup_node, setup_two_nodes, wait_for_tx, TestSyncStore, + distribute_funds, do_channel_full_cycle, expect_channel_ready_event, expect_event, + expect_payment_received_event, expect_payment_successful_event, generate_blocks_and_wait, + open_channel, premine, random_config, setup_bitcoind_and_electrsd, setup_builder, setup_node, + setup_two_nodes, wait_for_tx, TestSyncStore, }; use ldk_node::payment::{PaymentKind, QrPaymentResult, SendingParameters}; @@ -27,6 +27,8 @@ use std::sync::Arc; #[test] fn channel_full_cycle() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, false); } @@ -34,6 +36,8 @@ fn channel_full_cycle() { #[test] fn channel_full_cycle_force_close() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, true); } @@ -41,6 +45,8 @@ fn channel_full_cycle_force_close() { #[test] fn channel_full_cycle_force_close_trusted_no_reserve() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, true); do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, true); } @@ -48,6 +54,8 @@ fn channel_full_cycle_force_close_trusted_no_reserve() { #[test] fn channel_full_cycle_0conf() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, true, true, false); do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, true, true, false) } @@ -55,6 +63,8 @@ fn channel_full_cycle_0conf() { #[test] fn channel_full_cycle_legacy_staticremotekey() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, false, false); do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, false, false); } @@ -62,6 +72,8 @@ fn channel_full_cycle_legacy_staticremotekey() { #[test] fn channel_open_fails_when_funds_insufficient() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); let addr_a = node_a.onchain_payment().new_address().unwrap(); @@ -69,7 +81,7 @@ fn channel_open_fails_when_funds_insufficient() { let premine_amount_sat = 100_000; - premine_and_distribute_funds( + distribute_funds( &bitcoind.client, &electrsd.client, vec![addr_a, addr_b], @@ -97,6 +109,8 @@ fn channel_open_fails_when_funds_insufficient() { #[test] fn multi_hop_sending() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap()); // Setup and fund 5 nodes @@ -112,7 +126,7 @@ fn multi_hop_sending() { let addresses = nodes.iter().map(|n| n.onchain_payment().new_address().unwrap()).collect(); let premine_amount_sat = 5_000_000; - premine_and_distribute_funds( + distribute_funds( &bitcoind.client, &electrsd.client, addresses, @@ -192,6 +206,8 @@ fn connect_to_public_testnet_esplora() { #[test] fn start_stop_reinit() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let config = random_config(true); let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap()); @@ -213,12 +229,7 @@ fn start_stop_reinit() { assert_eq!(node.list_balances().total_onchain_balance_sats, 0); let expected_amount = Amount::from_sat(100000); - premine_and_distribute_funds( - &bitcoind.client, - &electrsd.client, - vec![funding_address], - expected_amount, - ); + distribute_funds(&bitcoind.client, &electrsd.client, vec![funding_address], expected_amount); node.sync_wallets().unwrap(); assert_eq!(node.list_balances().spendable_onchain_balance_sats, expected_amount.to_sat()); @@ -260,12 +271,14 @@ fn start_stop_reinit() { #[test] fn onchain_spend_receive() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); let addr_a = node_a.onchain_payment().new_address().unwrap(); let addr_b = node_b.onchain_payment().new_address().unwrap(); - premine_and_distribute_funds( + distribute_funds( &bitcoind.client, &electrsd.client, vec![addr_b.clone()], @@ -307,7 +320,9 @@ fn onchain_spend_receive() { #[test] fn sign_verify_msg() { - let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let config = random_config(true); let node = setup_node(&electrsd, config); @@ -325,7 +340,9 @@ fn connection_restart_behavior() { } fn do_connection_restart_behavior(persist: bool) { - let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, false, false); let node_id_a = node_a.node_id(); @@ -376,7 +393,9 @@ fn do_connection_restart_behavior(persist: bool) { #[test] fn concurrent_connections_succeed() { - let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); let node_a = Arc::new(node_a); @@ -407,11 +426,13 @@ fn concurrent_connections_succeed() { #[test] fn simple_bolt12_send_receive() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); let address_a = node_a.onchain_payment().new_address().unwrap(); let premine_amount_sat = 5_000_000; - premine_and_distribute_funds( + distribute_funds( &bitcoind.client, &electrsd.client, vec![address_a], @@ -614,12 +635,14 @@ fn simple_bolt12_send_receive() { #[test] fn generate_bip21_uri() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); let address_a = node_a.onchain_payment().new_address().unwrap(); let premined_sats = 5_000_000; - premine_and_distribute_funds( + distribute_funds( &bitcoind.client, &electrsd.client, vec![address_a], @@ -655,12 +678,14 @@ fn generate_bip21_uri() { #[test] fn unified_qr_send_receive() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + premine(&bitcoind.client, &electrsd.client); + let (node_a, node_b) = setup_two_nodes(&electrsd, false, true, false); let address_a = node_a.onchain_payment().new_address().unwrap(); let premined_sats = 5_000_000; - premine_and_distribute_funds( + distribute_funds( &bitcoind.client, &electrsd.client, vec![address_a], diff --git a/tests/integration_tests_vss.rs b/tests/integration_tests_vss.rs index c572fbcd8..161ad2108 100644 --- a/tests/integration_tests_vss.rs +++ b/tests/integration_tests_vss.rs @@ -22,13 +22,16 @@ fn channel_full_cycle_with_vss_store() { let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap(); let node_a = builder_a.build_with_vss_store(vss_base_url.clone(), "node_1_store".to_string()).unwrap(); - node_a.start().unwrap(); println!("\n== Node B =="); let config_b = common::random_config(true); let mut builder_b = Builder::from_config(config_b); builder_b.set_esplora_server(esplora_url); let node_b = builder_b.build_with_vss_store(vss_base_url, "node_2_store".to_string()).unwrap(); + + common::premine(&bitcoind.client, electrsd.client); + + node_a.start().unwrap(); node_b.start().unwrap(); common::do_channel_full_cycle(