fix test not building on windows

This commit is contained in:
edouardparis 2024-11-13 16:23:58 +01:00
parent f28b40fe8d
commit 8973ee0c7c
6 changed files with 51 additions and 29 deletions

View File

@ -1,3 +1,5 @@
#![cfg(not(target_os = "windows"))]
use liana::config::{config_folder_path, Config};
use std::{

View File

@ -80,7 +80,12 @@ fn main() {
process::exit(1);
});
let handle = DaemonHandle::start_default(config, true).unwrap_or_else(|e| {
let handle = DaemonHandle::start_default(
config,
#[cfg(all(unix, feature = "daemon"))]
true,
)
.unwrap_or_else(|e| {
log::error!("Error starting Liana daemon: {}", e);
process::exit(1);
});

View File

@ -318,7 +318,9 @@ mod tests {
toml::from_str::<Config>(&toml_str).expect("Deserializing toml_str");
// A valid, round-tripping, config
let toml_str = r#"
#[cfg(unix)] // On non-UNIX there is no 'daemon' member.
{
let toml_str = r#"
data_dir = '/home/wizardsardine/custom/folder/'
daemon = false
log_level = 'TRACE'
@ -332,13 +334,16 @@ mod tests {
cookie_path = '/home/user/.bitcoin/.cookie'
addr = '127.0.0.1:8332'
"#.trim_start().replace(" ", "");
let parsed = toml::from_str::<Config>(&toml_str).expect("Deserializing toml_str");
let serialized = toml::to_string_pretty(&parsed).expect("Serializing to toml");
#[cfg(unix)] // On non-UNIX there is no 'daemon' member.
assert_eq!(toml_str, serialized);
let parsed = toml::from_str::<Config>(&toml_str).expect("Deserializing toml_str");
let serialized = toml::to_string_pretty(&parsed).expect("Serializing to toml");
assert_eq!(toml_str, serialized);
}
// A valid, round-tripping, config for a Taproot descriptor.
let toml_str = r#"
#[cfg(unix)] // On non-UNIX there is no 'daemon' member.
{
let toml_str = r#"
data_dir = '/home/wizardsardine/custom/folder/'
daemon = false
log_level = 'TRACE'
@ -352,13 +357,15 @@ mod tests {
cookie_path = '/home/user/.bitcoin/.cookie'
addr = '127.0.0.1:8332'
"#.trim_start().replace(" ", "");
let parsed = toml::from_str::<Config>(&toml_str).expect("Deserializing toml_str");
let serialized = toml::to_string_pretty(&parsed).expect("Serializing to toml");
#[cfg(unix)] // On non-UNIX there is no 'daemon' member.
assert_eq!(toml_str, serialized);
let parsed = toml::from_str::<Config>(&toml_str).expect("Deserializing toml_str");
let serialized = toml::to_string_pretty(&parsed).expect("Serializing to toml");
assert_eq!(toml_str, serialized);
}
// A valid, round-tripping, config with `auth` instead of `cookie_path`
let toml_str = r#"
#[cfg(unix)] // On non-UNIX there is no 'daemon' member.
{
let toml_str = r#"
data_dir = '/home/wizardsardine/custom/folder/'
daemon = false
log_level = 'TRACE'
@ -372,10 +379,10 @@ mod tests {
auth = 'my_user:my_password'
addr = '127.0.0.1:8332'
"#.trim_start().replace(" ", "");
let parsed = toml::from_str::<Config>(&toml_str).expect("Deserializing toml_str");
let serialized = toml::to_string_pretty(&parsed).expect("Serializing to toml");
#[cfg(unix)] // On non-UNIX there is no 'daemon' member.
assert_eq!(toml_str, serialized);
let parsed = toml::from_str::<Config>(&toml_str).expect("Deserializing toml_str");
let serialized = toml::to_string_pretty(&parsed).expect("Serializing to toml");
assert_eq!(toml_str, serialized);
}
// Invalid desc checksum
let toml_str = r#"

View File

@ -215,7 +215,10 @@ mod tests {
testutils::*,
};
use std::{env, fs, io::Write, process};
use std::{env, fs, process};
#[cfg(not(windows))]
use std::io::Write;
fn read_one_command(socket_path: &path::Path) -> thread::JoinHandle<Option<Request>> {
let listener = rpcserver_setup(socket_path).unwrap();

View File

@ -5,7 +5,7 @@ pub mod config;
mod daemonize;
mod database;
pub mod descriptors;
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
mod jsonrpc;
pub mod random;
pub mod signer;
@ -22,7 +22,7 @@ pub use crate::bitcoin::{
d::{BitcoinD, BitcoindError, WalletError},
electrum::{Electrum, ElectrumError},
};
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
use crate::jsonrpc::server::{rpcserver_loop, rpcserver_setup};
use crate::{
bitcoin::{poller, BitcoinInterface},
@ -435,7 +435,7 @@ impl DaemonHandle {
config: Config,
bitcoin: Option<impl BitcoinInterface + 'static>,
db: Option<impl DatabaseInterface + 'static>,
#[cfg(feature = "daemon")] with_rpc_server: bool,
#[cfg(all(unix, feature = "daemon"))] with_rpc_server: bool,
) -> Result<Self, StartupError> {
#[cfg(not(test))]
setup_panic_hook();
@ -525,7 +525,7 @@ impl DaemonHandle {
// structure or through the JSONRPC server we may setup below.
let control = DaemonControl::new(config, bit, poller_sender.clone(), db, secp);
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
if with_rpc_server {
let rpcserver_shutdown = sync::Arc::from(sync::atomic::AtomicBool::from(false));
let rpcserver_handle = thread::Builder::new()
@ -564,13 +564,13 @@ impl DaemonHandle {
/// and SQLite).
pub fn start_default(
config: Config,
#[cfg(feature = "daemon")] with_rpc_server: bool,
#[cfg(all(unix, feature = "daemon"))] with_rpc_server: bool,
) -> Result<DaemonHandle, StartupError> {
Self::start(
config,
Option::<BitcoinD>::None,
Option::<SqliteDb>::None,
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
with_rpc_server,
)
}
@ -869,7 +869,7 @@ mod tests {
move || {
let handle = DaemonHandle::start_default(
config,
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
false,
)
.unwrap();
@ -894,7 +894,7 @@ mod tests {
move || {
let handle = DaemonHandle::start_default(
config,
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
false,
)
.unwrap();

View File

@ -544,7 +544,7 @@ impl DummyLiana {
pub fn _new(
bitcoin_interface: impl BitcoinInterface + 'static,
database: impl DatabaseInterface + 'static,
rpc_server: bool,
#[cfg(all(unix, feature = "daemon"))] rpc_server: bool,
) -> DummyLiana {
let tmp_dir = tmp_dir();
fs::create_dir_all(&tmp_dir).unwrap();
@ -579,7 +579,7 @@ impl DummyLiana {
config,
Some(bitcoin_interface),
Some(database),
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
rpc_server,
)
.unwrap();
@ -591,11 +591,16 @@ impl DummyLiana {
bitcoin_interface: impl BitcoinInterface + 'static,
database: impl DatabaseInterface + 'static,
) -> DummyLiana {
Self::_new(bitcoin_interface, database, false)
Self::_new(
bitcoin_interface,
database,
#[cfg(all(unix, feature = "daemon"))]
false,
)
}
/// Creates a new DummyLiana interface which also spins up an RPC server.
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
pub fn new_server(
bitcoin_interface: impl BitcoinInterface + 'static,
database: impl DatabaseInterface + 'static,