|
1 | 1 | use bitcoin::network::constants::Network;
|
2 | 2 | use chrono::Utc;
|
3 | 3 | use lightning::ln::msgs::NetAddress;
|
4 |
| -use std::{env, fs}; |
| 4 | +use std::fs; |
| 5 | +use std::path::PathBuf; |
5 | 6 | use tempfile::{Builder, TempDir};
|
6 | 7 |
|
7 | 8 | pub struct LdkUserInfo {
|
8 | 9 | pub bitcoind_rpc_username: String,
|
9 | 10 | pub bitcoind_rpc_password: String,
|
10 | 11 | pub bitcoind_rpc_port: u16,
|
11 | 12 | pub bitcoind_rpc_host: String,
|
| 13 | + pub ldk_data_dir: PathBuf, |
12 | 14 | pub ldk_peer_listening_port: u16,
|
13 | 15 | pub ldk_announced_listen_addr: Vec<NetAddress>,
|
14 | 16 | pub ldk_announced_node_name: [u8; 32],
|
15 | 17 | pub network: Network,
|
16 | 18 | }
|
17 | 19 |
|
18 |
| - |
19 | 20 | // Here we initialize three layers of directories needed for our tests. We won't persist ldk data, but we'll persist
|
20 | 21 | // the logs to help with debugging.
|
21 |
| -pub(crate) fn setup_data_and_log_dirs(test_name: &str) -> (String, TempDir, String) { |
22 |
| - // If necessary, we initialize the lndk-tests dir, which holds all of the lndk related test data. |
23 |
| - let lndk_tests_folder = "lndk-tests"; |
24 |
| - let lndk_test_dir = env::temp_dir().join(lndk_tests_folder); |
25 |
| - fs::create_dir_all(lndk_test_dir.clone()).unwrap(); |
26 |
| - |
27 |
| - let ldk_dir_binding = Builder::new() |
| 22 | +pub(crate) fn setup_data_and_log_dirs(ldk_dir: PathBuf, test_name: &str) -> (String, TempDir, String) { |
| 23 | + let ldk_data_dir_binding = Builder::new() |
28 | 24 | .prefix("ldk-data-dir")
|
29 |
| - .tempdir_in(lndk_test_dir.clone()) |
| 25 | + .tempdir_in(ldk_dir.clone()) |
30 | 26 | .unwrap();
|
31 |
| - let ldk_data_dir = String::from(ldk_dir_binding.path().to_str().unwrap()); |
| 27 | + let ldk_data_dir = String::from(ldk_data_dir_binding.path().to_str().unwrap()); |
32 | 28 |
|
33 | 29 | // Create the ldk-logs dir, which we'll persist after the tests are over for debugging.
|
34 | 30 | let now_timestamp = Utc::now();
|
35 | 31 | let timestamp = now_timestamp.format("%d-%m-%Y-%H%M");
|
36 |
| - let ldk_log_dir_binding = lndk_test_dir.join(format!("ldk-logs-{test_name}-{timestamp}")); |
| 32 | + let ldk_log_dir_binding = ldk_dir.join(format!("ldk-logs-{test_name}-{timestamp}")); |
37 | 33 | let ldk_log_dir = String::from(ldk_log_dir_binding.as_path().to_str().unwrap());
|
38 | 34 |
|
39 | 35 | // Initialize the LDK data directory if necessary.
|
40 |
| - fs::create_dir_all(ldk_data_dir.clone()).unwrap(); |
41 | 36 | fs::create_dir_all(ldk_log_dir.clone()).unwrap();
|
42 | 37 |
|
43 |
| - (ldk_data_dir, ldk_dir_binding, ldk_log_dir) |
| 38 | + (ldk_data_dir, ldk_data_dir_binding, ldk_log_dir) |
44 | 39 | }
|
0 commit comments