Skip to content

Commit

Permalink
fix test not building on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Nov 13, 2024
1 parent 8ca6593 commit eef87ac
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
37 changes: 22 additions & 15 deletions liana/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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#"
Expand Down
5 changes: 4 additions & 1 deletion liana/src/jsonrpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions liana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
)
}
Expand All @@ -583,7 +583,7 @@ impl DaemonHandle {
Self::Controller {
ref poller_handle, ..
} => !poller_handle.is_finished(),
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
Self::Server {
ref poller_handle,
ref rpcserver_handle,
Expand All @@ -606,7 +606,7 @@ impl DaemonHandle {
poller_handle.join().expect("Poller thread must not panic");
Ok(())
}
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
Self::Server {
poller_sender,
poller_handle,
Expand Down Expand Up @@ -869,7 +869,7 @@ mod tests {
move || {
let handle = DaemonHandle::start_default(
config,
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
false,
)
.unwrap();
Expand All @@ -894,7 +894,7 @@ mod tests {
move || {
let handle = DaemonHandle::start_default(
config,
#[cfg(feature = "daemon")]
#[cfg(all(unix, feature = "daemon"))]
false,
)
.unwrap();
Expand Down

0 comments on commit eef87ac

Please sign in to comment.