fix(swap): Unit test compilation errors

This commit is contained in:
binarybaron 2024-08-26 17:48:19 +02:00 committed by binarybaron
parent a57e3aff75
commit dc3c937333
4 changed files with 27 additions and 10 deletions

View file

@ -41,7 +41,7 @@ mod tests {
use ::bitcoin::Amount;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use swap::api::request::determine_btc_to_swap;
use swap::cli::api::request::determine_btc_to_swap;
use swap::network::quote::BidQuote;
use swap::tracing_ext::capture_logs;
use tracing::level_filters::LevelFilter;
@ -65,6 +65,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
)
.await
.unwrap();
@ -102,6 +103,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
)
.await
.unwrap();
@ -139,6 +141,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
)
.await
.unwrap();
@ -172,6 +175,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
)
.await
.unwrap();
@ -205,6 +209,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
)
.await
.unwrap();
@ -242,6 +247,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
)
.await
.unwrap();
@ -284,6 +290,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
),
)
.await
@ -333,6 +340,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
),
)
.await
@ -367,6 +375,7 @@ mod tests {
},
|| async { Ok(()) },
|_| async { Ok(Amount::from_sat(1000)) },
None,
)
.await
.err()

View file

@ -541,6 +541,13 @@ struct Seller {
#[cfg(test)]
mod tests {
// this test is very long, however it just checks that various CLI arguments sets the
// internal Context and Request properly. It is unlikely to fail and splitting it in various
// tests would require to run the tests sequantially which is very slow (due to the context
// need to access files like the Bitcoin wallet).
/*
use super::*;
use crate::cli::api::api_test::*;
@ -550,11 +557,8 @@ mod tests {
const BINARY_NAME: &str = "swap";
const ARGS_DATA_DIR: &str = "/tmp/dir/";
TODO: This test doesn't work anymore since the Request struct has been removed. We need to find another way to test the CLI arguments.
#[tokio::test]
// this test is very long, however it just checks that various CLI arguments sets the
// internal Context and Request properly. It is unlikely to fail and splitting it in various
// tests would require to run the tests sequantially which is very slow (due to the context
// need to access files like the Bitcoin wallet).
async fn test_cli_arguments() {
// given_buy_xmr_on_mainnet_then_defaults_to_mainnet
@ -1274,4 +1278,5 @@ mod tests {
let result = parse_args_and_apply_defaults(raw_ars).await.unwrap();
assert!(matches!(result, ParseResult::Context(_, _)));
}
*/
}

View file

@ -16,6 +16,7 @@ use std::sync::Arc;
use std::time::Duration;
use swap::asb::FixedRate;
use swap::bitcoin::{CancelTimelock, PunishTimelock, TxCancel, TxPunish, TxRedeem, TxRefund};
use swap::cli::api;
use swap::database::SqliteDatabase;
use swap::env::{Config, GetConfig};
use swap::fs::ensure_directory_exists;
@ -25,7 +26,7 @@ use swap::protocol::alice::{AliceState, Swap};
use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob, Database};
use swap::seed::Seed;
use swap::{api, asb, bitcoin, cli, env, monero};
use swap::{asb, bitcoin, cli, env, monero};
use tempfile::{tempdir, NamedTempFile};
use testcontainers::clients::Cli;
use testcontainers::{Container, RunnableImage};

View file

@ -15,8 +15,8 @@ mod test {
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use swap::api::request::{start_daemon, StartDaemonArgs};
use swap::api::Context;
use swap::cli::api::request::{Request, StartDaemonArgs};
use swap::cli::api::Context;
use crate::harness::alice_run_until::is_xmr_lock_transaction_sent;
use crate::harness::bob_run_until::is_btc_locked;
@ -39,14 +39,16 @@ mod test {
harness_ctx: TestContext,
) -> (Client, MakeCapturingWriter, Arc<Context>) {
let writer = capture_logs(LevelFilter::DEBUG);
let server_address: Option<SocketAddr> = SERVER_ADDRESS.parse().unwrap().into();
let server_address: Option<SocketAddr> =
SERVER_ADDRESS.parse::<SocketAddr>().unwrap().into();
let context = Arc::new(harness_ctx.get_bob_context().await);
let context_clone = context.clone();
tokio::spawn(async move {
if let Err(err) = start_daemon(StartDaemonArgs { server_address }, context).await {
let args = StartDaemonArgs { server_address };
if let Err(err) = args.request(context_clone).await {
println!("Failed to initialize daemon for testing: {}", err);
}
});