mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-30 20:46:33 -05:00
fix compile issues for tests and use serial_test crate
This commit is contained in:
parent
9b08f71bb8
commit
ccf9b0c31f
5 changed files with 24 additions and 34 deletions
|
|
@ -90,8 +90,8 @@ impl SwapLock {
|
|||
/// # Notes
|
||||
/// The 50ms polling interval is considered negligible overhead compared to the typical time required to suspend ongoing swap processes.
|
||||
pub async fn send_suspend_signal(&self) -> Result<(), Error> {
|
||||
const TIMEOUT: i32 = 10_000;
|
||||
const INTERVAL: i32 = 50;
|
||||
const TIMEOUT: u64 = 10_000;
|
||||
const INTERVAL: u64 = 50;
|
||||
|
||||
let _ = self.suspension_trigger.send(())?;
|
||||
|
||||
|
|
|
|||
|
|
@ -371,6 +371,7 @@ mod tests {
|
|||
use crate::protocol::{alice, bob};
|
||||
use rand::rngs::OsRng;
|
||||
use uuid::Uuid;
|
||||
use std::matches;
|
||||
|
||||
#[test]
|
||||
fn lock_confirmations_le_to_cancel_timelock_no_timelock_expired() {
|
||||
|
|
@ -384,7 +385,7 @@ mod tests {
|
|||
tx_cancel_status,
|
||||
);
|
||||
|
||||
assert_eq!(expired_timelock, ExpiredTimelocks::None)
|
||||
assert!(matches!(expired_timelock, ExpiredTimelocks::None { .. }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -399,7 +400,7 @@ mod tests {
|
|||
tx_cancel_status,
|
||||
);
|
||||
|
||||
assert_eq!(expired_timelock, ExpiredTimelocks::Cancel)
|
||||
assert!(matches!(expired_timelock, ExpiredTimelocks::Cancel {..}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -1004,9 +1004,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn given_depth_0_should_meet_confirmation_target_one() {
|
||||
|
||||
let script = ScriptStatus::Confirmed(Confirmed { depth: 0 });
|
||||
|
||||
let confirmed = script.is_confirmed_with(1);
|
||||
let confirmed = script.is_confirmed_with(1 as u32);
|
||||
|
||||
assert!(confirmed)
|
||||
}
|
||||
|
|
@ -1015,7 +1016,7 @@ mod tests {
|
|||
fn given_confirmations_1_should_meet_confirmation_target_one() {
|
||||
let script = ScriptStatus::from_confirmations(1);
|
||||
|
||||
let confirmed = script.is_confirmed_with(1);
|
||||
let confirmed = script.is_confirmed_with(1 as u32);
|
||||
|
||||
assert!(confirmed)
|
||||
}
|
||||
|
|
@ -1034,7 +1035,7 @@ mod tests {
|
|||
fn given_depth_0_should_return_0_blocks_left_until_1() {
|
||||
let script = ScriptStatus::Confirmed(Confirmed { depth: 0 });
|
||||
|
||||
let blocks_left = script.blocks_left_until(1);
|
||||
let blocks_left = script.blocks_left_until(1 as u32);
|
||||
|
||||
assert_eq!(blocks_left, 0)
|
||||
}
|
||||
|
|
@ -1043,7 +1044,7 @@ mod tests {
|
|||
fn given_depth_1_should_return_0_blocks_left_until_1() {
|
||||
let script = ScriptStatus::Confirmed(Confirmed { depth: 1 });
|
||||
|
||||
let blocks_left = script.blocks_left_until(1);
|
||||
let blocks_left = script.blocks_left_until(1 as u32);
|
||||
|
||||
assert_eq!(blocks_left, 0)
|
||||
}
|
||||
|
|
@ -1052,7 +1053,7 @@ mod tests {
|
|||
fn given_depth_0_should_return_1_blocks_left_until_2() {
|
||||
let script = ScriptStatus::Confirmed(Confirmed { depth: 0 });
|
||||
|
||||
let blocks_left = script.blocks_left_until(2);
|
||||
let blocks_left = script.blocks_left_until(2 as u32);
|
||||
|
||||
assert_eq!(blocks_left, 1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1054,6 +1054,7 @@ mod tests {
|
|||
Config::default(is_testnet, None, debug, json),
|
||||
Request::buy_xmr(is_testnet),
|
||||
);
|
||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
||||
|
||||
let (actual_config, actual_request) = match args {
|
||||
ParseResult::Context(context, request) => (context.config.clone(), request),
|
||||
|
|
|
|||
|
|
@ -5,17 +5,15 @@ use jsonrpsee::ws_client::WsClientBuilder;
|
|||
use jsonrpsee_core::client::ClientT;
|
||||
use jsonrpsee_core::params::ObjectParams;
|
||||
|
||||
use sequential_test::sequential;
|
||||
use serial_test::serial;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use swap::api::request::{Method, Params, Request, Shutdown};
|
||||
use swap::api::request::{Method, Request };
|
||||
use swap::api::Context;
|
||||
use swap::cli::command::{Bitcoin, Monero};
|
||||
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -34,7 +32,6 @@ pub async fn initialize_context() -> (Arc<Context>, Request) {
|
|||
let (is_testnet, debug, json) = (true, false, false);
|
||||
// let data_dir = data::data_dir_from(None, is_testnet).unwrap();
|
||||
let server_address = None;
|
||||
let (tx, _) = broadcast::channel(1);
|
||||
|
||||
let bitcoin = Bitcoin {
|
||||
bitcoin_electrum_rpc_url: None,
|
||||
|
|
@ -45,7 +42,7 @@ pub async fn initialize_context() -> (Arc<Context>, Request) {
|
|||
monero_daemon_address: None,
|
||||
};
|
||||
|
||||
let request = Request::new(tx.subscribe(), Method::StartDaemon, Params::default());
|
||||
let request = Request::new(Method::StartDaemon { server_address: None });
|
||||
|
||||
let context = Context::build(
|
||||
Some(bitcoin),
|
||||
|
|
@ -56,7 +53,6 @@ pub async fn initialize_context() -> (Arc<Context>, Request) {
|
|||
debug,
|
||||
json,
|
||||
server_address,
|
||||
tx,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
@ -65,7 +61,7 @@ pub async fn initialize_context() -> (Arc<Context>, Request) {
|
|||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn can_start_server() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -73,12 +69,11 @@ pub async fn can_start_server() {
|
|||
request.call(Arc::clone(&move_ctx)).await;
|
||||
});
|
||||
tokio::time::sleep(Duration::from_secs(3)).await;
|
||||
ctx.shutdown.send(());
|
||||
assert!(true);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn get_bitcoin_balance() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -96,11 +91,10 @@ pub async fn get_bitcoin_balance() {
|
|||
.unwrap();
|
||||
|
||||
assert_eq!(response, HashMap::from([("balance".to_string(), 0)]));
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn get_history() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -119,11 +113,10 @@ pub async fn get_history() {
|
|||
let swaps: Vec<(Uuid, String)> = Vec::new();
|
||||
|
||||
assert_eq!(response, HashMap::from([("swaps".to_string(), swaps)]));
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn get_raw_history() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -145,11 +138,10 @@ pub async fn get_raw_history() {
|
|||
response,
|
||||
HashMap::from([("raw_history".to_string(), raw_history)])
|
||||
);
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn get_seller() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -197,11 +189,10 @@ pub async fn get_seller() {
|
|||
e
|
||||
),
|
||||
}
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn get_swap_start_date() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -244,11 +235,10 @@ pub async fn get_swap_start_date() {
|
|||
Ok(hash) => (),
|
||||
Err(e) => panic!("Expected a HashMap, got an error: {}", e),
|
||||
}
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn resume_swap() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -291,11 +281,10 @@ pub async fn resume_swap() {
|
|||
Ok(hash) => (),
|
||||
Err(e) => panic!("Expected a HashMap, got an error: {}", e),
|
||||
}
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn withdraw_btc() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -348,11 +337,10 @@ pub async fn withdraw_btc() {
|
|||
Err(e) => panic!("Expected a HashMap, got an error: {}", e),
|
||||
}
|
||||
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[sequential]
|
||||
#[serial]
|
||||
pub async fn buy_xmr() {
|
||||
let (ctx, mut request) = initialize_context().await;
|
||||
let move_ctx = Arc::clone(&ctx);
|
||||
|
|
@ -454,5 +442,4 @@ pub async fn buy_xmr() {
|
|||
Err(e) => panic!("Expected a HashMap, got an error: {}", e),
|
||||
}
|
||||
|
||||
ctx.shutdown.send(());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue