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 } ;
3
3
4
4
use bitcoin:: { Address , Amount , OutPoint , Txid } ;
5
5
use bitcoind:: bitcoincore_rpc:: RpcApi ;
@@ -8,8 +8,6 @@ use electrsd::{bitcoind, bitcoind::BitcoinD, ElectrsD};
8
8
use electrum_client:: ElectrumApi ;
9
9
10
10
use once_cell:: sync:: OnceCell ;
11
- use rand:: distributions:: Alphanumeric ;
12
- use rand:: { thread_rng, Rng } ;
13
11
14
12
use std:: env;
15
13
use std:: sync:: Mutex ;
@@ -137,38 +135,17 @@ fn premine_and_distribute_funds(addrs: Vec<Address>, amount: Amount) {
137
135
generate_blocks_and_wait ( 1 ) ;
138
136
}
139
137
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
-
162
138
#[ test]
163
139
fn channel_full_cycle ( ) {
164
140
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) ;
166
143
let node_a = Builder :: from_config ( config_a) . build ( ) ;
167
144
node_a. start ( ) . unwrap ( ) ;
168
145
let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
169
146
170
147
println ! ( "\n == Node B ==" ) ;
171
- let config_b = rand_config ( ) ;
148
+ let config_b = random_config ( esplora_url ) ;
172
149
let node_b = Builder :: from_config ( config_b) . build ( ) ;
173
150
node_b. start ( ) . unwrap ( ) ;
174
151
let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
@@ -317,13 +294,14 @@ fn channel_full_cycle() {
317
294
#[ test]
318
295
fn channel_open_fails_when_funds_insufficient ( ) {
319
296
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) ;
321
299
let node_a = Builder :: from_config ( config_a) . build ( ) ;
322
300
node_a. start ( ) . unwrap ( ) ;
323
301
let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
324
302
325
303
println ! ( "\n == Node B ==" ) ;
326
- let config_b = rand_config ( ) ;
304
+ let config_b = random_config ( & esplora_url ) ;
327
305
let node_b = Builder :: from_config ( config_b) . build ( ) ;
328
306
node_b. start ( ) . unwrap ( ) ;
329
307
let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
@@ -344,7 +322,8 @@ fn channel_open_fails_when_funds_insufficient() {
344
322
345
323
#[ test]
346
324
fn 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) ;
348
327
config. esplora_server_url = "https://blockstream.info/testnet/api" . to_string ( ) ;
349
328
config. network = bitcoin:: Network :: Testnet ;
350
329
let node = Builder :: from_config ( config) . build ( ) ;
@@ -355,7 +334,8 @@ fn connect_to_public_testnet_esplora() {
355
334
356
335
#[ test]
357
336
fn 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) ;
359
339
let node = Builder :: from_config ( config. clone ( ) ) . build ( ) ;
360
340
let expected_node_id = node. node_id ( ) ;
361
341
0 commit comments