Skip to content

Commit 8ca908c

Browse files
committed
Randomize chain sources in tests
.. all of our tests should be robust against switching chain sources. We here opt to pick a random one each time to considerably extend our test coverage, instead of just running some cases against non-Esplora chain sources.
1 parent 10db851 commit 8ca908c

File tree

2 files changed

+54
-56
lines changed

2 files changed

+54
-56
lines changed

tests/common/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,31 @@ pub(crate) fn setup_bitcoind_and_electrsd() -> (BitcoinD, ElectrsD) {
206206
(bitcoind, electrsd)
207207
}
208208

209+
pub(crate) fn random_chain_source<'a>(
210+
bitcoind: &'a BitcoinD, electrsd: &'a ElectrsD,
211+
) -> TestChainSource<'a> {
212+
let r = rand::random_range(0..3);
213+
match r {
214+
0 => {
215+
println!("Randomly setting up Esplora chain syncing...");
216+
TestChainSource::Esplora(electrsd)
217+
},
218+
1 => {
219+
println!("Randomly setting up Electrum chain syncing...");
220+
TestChainSource::Electrum(electrsd)
221+
},
222+
2 => {
223+
println!("Randomly setting up Bitcoind RPC chain syncing...");
224+
TestChainSource::BitcoindRpcSync(bitcoind)
225+
},
226+
3 => {
227+
println!("Randomly setting up Bitcoind REST chain syncing...");
228+
TestChainSource::BitcoindRestSync(bitcoind)
229+
},
230+
_ => unreachable!(),
231+
}
232+
}
233+
209234
pub(crate) fn random_storage_path() -> PathBuf {
210235
let mut temp_path = std::env::temp_dir();
211236
let mut rng = rng();

tests/integration_tests_rust.rs

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use common::{
2121
expect_channel_pending_event, expect_channel_ready_event, expect_event,
2222
expect_payment_claimable_event, expect_payment_received_event, expect_payment_successful_event,
2323
expect_splice_pending_event, generate_blocks_and_wait, open_channel, open_channel_push_amt,
24-
premine_and_distribute_funds, premine_blocks, prepare_rbf, random_config,
24+
premine_and_distribute_funds, premine_blocks, prepare_rbf, random_chain_source, random_config,
2525
random_listening_addresses, setup_bitcoind_and_electrsd, setup_builder, setup_node,
2626
setup_two_nodes, wait_for_tx, TestChainSource, TestStoreType, TestSyncStore,
2727
};
@@ -43,34 +43,7 @@ use log::LevelFilter;
4343
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
4444
async fn channel_full_cycle() {
4545
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
46-
let chain_source = TestChainSource::Esplora(&electrsd);
47-
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
48-
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, false)
49-
.await;
50-
}
51-
52-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
53-
async fn channel_full_cycle_electrum() {
54-
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
55-
let chain_source = TestChainSource::Electrum(&electrsd);
56-
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
57-
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, false)
58-
.await;
59-
}
60-
61-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
62-
async fn channel_full_cycle_bitcoind_rpc_sync() {
63-
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
64-
let chain_source = TestChainSource::BitcoindRpcSync(&bitcoind);
65-
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
66-
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, false)
67-
.await;
68-
}
69-
70-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
71-
async fn channel_full_cycle_bitcoind_rest_sync() {
72-
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
73-
let chain_source = TestChainSource::BitcoindRestSync(&bitcoind);
46+
let chain_source = random_chain_source(&bitcoind, &electrsd);
7447
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
7548
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, false)
7649
.await;
@@ -79,7 +52,7 @@ async fn channel_full_cycle_bitcoind_rest_sync() {
7952
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
8053
async fn channel_full_cycle_force_close() {
8154
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
82-
let chain_source = TestChainSource::Esplora(&electrsd);
55+
let chain_source = random_chain_source(&bitcoind, &electrsd);
8356
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
8457
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, true)
8558
.await;
@@ -88,7 +61,7 @@ async fn channel_full_cycle_force_close() {
8861
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
8962
async fn channel_full_cycle_force_close_trusted_no_reserve() {
9063
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
91-
let chain_source = TestChainSource::Esplora(&electrsd);
64+
let chain_source = random_chain_source(&bitcoind, &electrsd);
9265
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, true);
9366
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, true)
9467
.await;
@@ -97,7 +70,7 @@ async fn channel_full_cycle_force_close_trusted_no_reserve() {
9770
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
9871
async fn channel_full_cycle_0conf() {
9972
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
100-
let chain_source = TestChainSource::Esplora(&electrsd);
73+
let chain_source = random_chain_source(&bitcoind, &electrsd);
10174
let (node_a, node_b) = setup_two_nodes(&chain_source, true, true, false);
10275
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, true, true, false)
10376
.await;
@@ -106,7 +79,7 @@ async fn channel_full_cycle_0conf() {
10679
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
10780
async fn channel_full_cycle_legacy_staticremotekey() {
10881
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
109-
let chain_source = TestChainSource::Esplora(&electrsd);
82+
let chain_source = random_chain_source(&bitcoind, &electrsd);
11083
let (node_a, node_b) = setup_two_nodes(&chain_source, false, false, false);
11184
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, false, false)
11285
.await;
@@ -115,7 +88,7 @@ async fn channel_full_cycle_legacy_staticremotekey() {
11588
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
11689
async fn channel_open_fails_when_funds_insufficient() {
11790
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
118-
let chain_source = TestChainSource::Esplora(&electrsd);
91+
let chain_source = random_chain_source(&bitcoind, &electrsd);
11992
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
12093

12194
let addr_a = node_a.onchain_payment().new_address().unwrap();
@@ -320,7 +293,7 @@ async fn start_stop_reinit() {
320293
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
321294
async fn onchain_send_receive() {
322295
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
323-
let chain_source = TestChainSource::Esplora(&electrsd);
296+
let chain_source = random_chain_source(&bitcoind, &electrsd);
324297
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
325298

326299
let addr_a = node_a.onchain_payment().new_address().unwrap();
@@ -521,7 +494,7 @@ async fn onchain_send_receive() {
521494
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
522495
async fn onchain_send_all_retains_reserve() {
523496
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
524-
let chain_source = TestChainSource::Esplora(&electrsd);
497+
let chain_source = random_chain_source(&bitcoind, &electrsd);
525498
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
526499

527500
// Setup nodes
@@ -606,7 +579,7 @@ async fn onchain_send_all_retains_reserve() {
606579
async fn onchain_wallet_recovery() {
607580
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
608581

609-
let chain_source = TestChainSource::Esplora(&electrsd);
582+
let chain_source = random_chain_source(&bitcoind, &electrsd);
610583

611584
let original_config = random_config(true);
612585
let original_node_entropy = original_config.node_entropy;
@@ -821,9 +794,9 @@ async fn run_rbf_test(is_insert_block: bool) {
821794

822795
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
823796
async fn sign_verify_msg() {
824-
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
797+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
825798
let config = random_config(true);
826-
let chain_source = TestChainSource::Esplora(&electrsd);
799+
let chain_source = random_chain_source(&bitcoind, &electrsd);
827800
let node = setup_node(&chain_source, config);
828801

829802
// Tests arbitrary message signing and later verification
@@ -835,8 +808,8 @@ async fn sign_verify_msg() {
835808

836809
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
837810
async fn connection_multi_listen() {
838-
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
839-
let chain_source = TestChainSource::Esplora(&electrsd);
811+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
812+
let chain_source = random_chain_source(&bitcoind, &electrsd);
840813
let (node_a, node_b) = setup_two_nodes(&chain_source, false, false, false);
841814

842815
let node_id_b = node_b.node_id();
@@ -855,8 +828,8 @@ async fn connection_restart_behavior() {
855828
}
856829

857830
async fn do_connection_restart_behavior(persist: bool) {
858-
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
859-
let chain_source = TestChainSource::Esplora(&electrsd);
831+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
832+
let chain_source = random_chain_source(&bitcoind, &electrsd);
860833
let (node_a, node_b) = setup_two_nodes(&chain_source, false, false, false);
861834

862835
let node_id_a = node_a.node_id();
@@ -902,8 +875,8 @@ async fn do_connection_restart_behavior(persist: bool) {
902875

903876
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
904877
async fn concurrent_connections_succeed() {
905-
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
906-
let chain_source = TestChainSource::Esplora(&electrsd);
878+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
879+
let chain_source = random_chain_source(&bitcoind, &electrsd);
907880
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
908881

909882
let node_a = Arc::new(node_a);
@@ -1078,7 +1051,7 @@ async fn splice_channel() {
10781051
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
10791052
async fn simple_bolt12_send_receive() {
10801053
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1081-
let chain_source = TestChainSource::Esplora(&electrsd);
1054+
let chain_source = random_chain_source(&bitcoind, &electrsd);
10821055
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
10831056

10841057
let address_a = node_a.onchain_payment().new_address().unwrap();
@@ -1307,7 +1280,7 @@ async fn simple_bolt12_send_receive() {
13071280
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
13081281
async fn async_payment() {
13091282
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1310-
let chain_source = TestChainSource::Esplora(&electrsd);
1283+
let chain_source = random_chain_source(&bitcoind, &electrsd);
13111284

13121285
let mut config_sender = random_config(true);
13131286
config_sender.node_config.listening_addresses = None;
@@ -1433,7 +1406,7 @@ async fn async_payment() {
14331406
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
14341407
async fn test_node_announcement_propagation() {
14351408
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1436-
let chain_source = TestChainSource::Esplora(&electrsd);
1409+
let chain_source = random_chain_source(&bitcoind, &electrsd);
14371410

14381411
// Node A will use both listening and announcement addresses
14391412
let mut config_a = random_config(true);
@@ -1525,7 +1498,7 @@ async fn test_node_announcement_propagation() {
15251498
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
15261499
async fn generate_bip21_uri() {
15271500
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1528-
let chain_source = TestChainSource::Esplora(&electrsd);
1501+
let chain_source = random_chain_source(&bitcoind, &electrsd);
15291502

15301503
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
15311504

@@ -1580,7 +1553,7 @@ async fn generate_bip21_uri() {
15801553
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
15811554
async fn unified_send_receive_bip21_uri() {
15821555
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1583-
let chain_source = TestChainSource::Esplora(&electrsd);
1556+
let chain_source = random_chain_source(&bitcoind, &electrsd);
15841557

15851558
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
15861559

@@ -1918,8 +1891,8 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) {
19181891

19191892
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
19201893
async fn facade_logging() {
1921-
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1922-
let chain_source = TestChainSource::Esplora(&electrsd);
1894+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1895+
let chain_source = random_chain_source(&bitcoind, &electrsd);
19231896

19241897
let logger = init_log_logger(LevelFilter::Trace);
19251898
let mut config = random_config(false);
@@ -1937,7 +1910,7 @@ async fn facade_logging() {
19371910
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
19381911
async fn spontaneous_send_with_custom_preimage() {
19391912
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1940-
let chain_source = TestChainSource::Esplora(&electrsd);
1913+
let chain_source = random_chain_source(&bitcoind, &electrsd);
19411914
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
19421915

19431916
let address_a = node_a.onchain_payment().new_address().unwrap();
@@ -2003,8 +1976,8 @@ async fn spontaneous_send_with_custom_preimage() {
20031976

20041977
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
20051978
async fn drop_in_async_context() {
2006-
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
2007-
let chain_source = TestChainSource::Esplora(&electrsd);
1979+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1980+
let chain_source = random_chain_source(&bitcoind, &electrsd);
20081981
let config = random_config(true);
20091982
let node = setup_node(&chain_source, config);
20101983
node.stop().unwrap();
@@ -2313,7 +2286,7 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() {
23132286
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
23142287
async fn payment_persistence_after_restart() {
23152288
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
2316-
let chain_source = TestChainSource::Esplora(&electrsd);
2289+
let chain_source = random_chain_source(&bitcoind, &electrsd);
23172290

23182291
// Setup nodes manually so we can restart node_a with the same config
23192292
println!("== Node A ==");

0 commit comments

Comments
 (0)