1- use crate :: tests :: test_utils :: expect_event;
2- use crate :: { Builder , Config , Error , Event , PaymentDirection , PaymentStatus } ;
1+ use crate :: test :: utils :: { expect_event, random_config } ;
2+ use crate :: { Builder , Error , Event , PaymentDirection , PaymentStatus } ;
33
44use bitcoin:: { Address , Amount , OutPoint , Txid } ;
55use bitcoind:: bitcoincore_rpc:: RpcApi ;
@@ -8,8 +8,6 @@ use electrsd::{bitcoind, bitcoind::BitcoinD, ElectrsD};
88use electrum_client:: ElectrumApi ;
99
1010use once_cell:: sync:: OnceCell ;
11- use rand:: distributions:: Alphanumeric ;
12- use rand:: { thread_rng, Rng } ;
1311
1412use std:: env;
1513use std:: sync:: Mutex ;
@@ -137,38 +135,17 @@ fn premine_and_distribute_funds(addrs: Vec<Address>, amount: Amount) {
137135 generate_blocks_and_wait ( 1 ) ;
138136}
139137
140- fn rand_config ( ) -> Config {
141- let mut config = Config :: default ( ) ;
142-
143- let esplora_url = get_electrsd ( ) . esplora_url . as_ref ( ) . unwrap ( ) ;
144-
145- println ! ( "Setting esplora server URL: {}" , esplora_url) ;
146- config. esplora_server_url = format ! ( "http://{}" , esplora_url) ;
147-
148- let mut rng = thread_rng ( ) ;
149- let rand_dir: String = ( 0 ..7 ) . map ( |_| rng. sample ( Alphanumeric ) as char ) . collect ( ) ;
150- let rand_path = format ! ( "/tmp/{}" , rand_dir) ;
151- println ! ( "Setting random LDK storage dir: {}" , rand_dir) ;
152- config. storage_dir_path = rand_path;
153-
154- let rand_port: u16 = rng. gen_range ( 5000 ..8000 ) ;
155- println ! ( "Setting random LDK listening port: {}" , rand_port) ;
156- let listening_address = format ! ( "127.0.0.1:{}" , rand_port) ;
157- config. listening_address = Some ( listening_address) ;
158-
159- config
160- }
161-
162138#[ test]
163139fn channel_full_cycle ( ) {
164140 println ! ( "== Node A ==" ) ;
165- let config_a = rand_config ( ) ;
141+ let esplora_url = get_electrsd ( ) . esplora_url . as_ref ( ) . unwrap ( ) ;
142+ let config_a = random_config ( esplora_url) ;
166143 let node_a = Builder :: from_config ( config_a) . build ( ) ;
167144 node_a. start ( ) . unwrap ( ) ;
168145 let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
169146
170147 println ! ( "\n == Node B ==" ) ;
171- let config_b = rand_config ( ) ;
148+ let config_b = random_config ( esplora_url ) ;
172149 let node_b = Builder :: from_config ( config_b) . build ( ) ;
173150 node_b. start ( ) . unwrap ( ) ;
174151 let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
@@ -317,13 +294,14 @@ fn channel_full_cycle() {
317294#[ test]
318295fn channel_open_fails_when_funds_insufficient ( ) {
319296 println ! ( "== Node A ==" ) ;
320- let config_a = rand_config ( ) ;
297+ let esplora_url = get_electrsd ( ) . esplora_url . as_ref ( ) . unwrap ( ) ;
298+ let config_a = random_config ( & esplora_url) ;
321299 let node_a = Builder :: from_config ( config_a) . build ( ) ;
322300 node_a. start ( ) . unwrap ( ) ;
323301 let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
324302
325303 println ! ( "\n == Node B ==" ) ;
326- let config_b = rand_config ( ) ;
304+ let config_b = random_config ( & esplora_url ) ;
327305 let node_b = Builder :: from_config ( config_b) . build ( ) ;
328306 node_b. start ( ) . unwrap ( ) ;
329307 let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
@@ -344,7 +322,8 @@ fn channel_open_fails_when_funds_insufficient() {
344322
345323#[ test]
346324fn connect_to_public_testnet_esplora ( ) {
347- let mut config = rand_config ( ) ;
325+ let esplora_url = get_electrsd ( ) . esplora_url . as_ref ( ) . unwrap ( ) ;
326+ let mut config = random_config ( & esplora_url) ;
348327 config. esplora_server_url = "https://blockstream.info/testnet/api" . to_string ( ) ;
349328 config. network = bitcoin:: Network :: Testnet ;
350329 let node = Builder :: from_config ( config) . build ( ) ;
@@ -355,7 +334,8 @@ fn connect_to_public_testnet_esplora() {
355334
356335#[ test]
357336fn start_stop_reinit ( ) {
358- let config = rand_config ( ) ;
337+ let esplora_url = get_electrsd ( ) . esplora_url . as_ref ( ) . unwrap ( ) ;
338+ let config = random_config ( & esplora_url) ;
359339 let node = Builder :: from_config ( config. clone ( ) ) . build ( ) ;
360340 let expected_node_id = node. node_id ( ) ;
361341
0 commit comments