From ec0bc8cd394978ecf719332e0902573cb2eab35c Mon Sep 17 00:00:00 2001 From: Lorenzo Tucci Date: Fri, 22 Sep 2023 23:28:49 +0300 Subject: [PATCH] fixing test_cli_arguments and other tests --- swap/Cargo.toml | 2 +- swap/src/bin/swap.rs | 58 +++++----- swap/src/cli/command.rs | 239 ++++++++++++++++++++-------------------- 3 files changed, 149 insertions(+), 150 deletions(-) diff --git a/swap/Cargo.toml b/swap/Cargo.toml index f2075aff..12886cdd 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -55,7 +55,7 @@ structopt = "0.3" strum = { version = "0.24", features = [ "derive" ] } thiserror = "1" time = "0.3" -tokio = { version = "1", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } +tokio = { version = "1", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net", "parking_lot" ] } tokio-socks = "0.5" tokio-tungstenite = { version = "0.15", features = [ "rustls-tls" ] } tokio-util = { version = "0.7", features = [ "io", "codec" ] } diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 8cea4033..9e8ebbc5 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -75,10 +75,10 @@ mod tests { assert_eq!((amount, fees), (expected_amount, expected_fees)); assert_eq!( writer.captured(), - r" INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.00000000 BTC maximum_amount=0.01000000 BTC - INFO swap: Deposit at least 0.00001000 BTC to cover the min quantity with fee! - INFO swap: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.00001000 BTC max_giveable=0.00000000 BTC minimum_amount=0.00000000 BTC maximum_amount=0.01000000 BTC - INFO swap: Received Bitcoin new_balance=0.00100000 BTC max_giveable=0.00090000 BTC + r" INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0 BTC maximum_amount=0.01 BTC + INFO swap::api::request: Deposit at least 0.00001 BTC to cover the min quantity with fee! + INFO swap::api::request: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.00001 BTC max_giveable=0 BTC minimum_amount=0 BTC maximum_amount=0.01 BTC + INFO swap::api::request: Received Bitcoin new_balance=0.001 BTC max_giveable=0.0009 BTC " ); } @@ -112,10 +112,10 @@ mod tests { assert_eq!((amount, fees), (expected_amount, expected_fees)); assert_eq!( writer.captured(), - r" INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.00000000 BTC maximum_amount=0.01000000 BTC - INFO swap: Deposit at least 0.00001000 BTC to cover the min quantity with fee! - INFO swap: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.00001000 BTC max_giveable=0.00000000 BTC minimum_amount=0.00000000 BTC maximum_amount=0.01000000 BTC - INFO swap: Received Bitcoin new_balance=0.10010000 BTC max_giveable=0.10000000 BTC + r" INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0 BTC maximum_amount=0.01 BTC + INFO swap::api::request: Deposit at least 0.00001 BTC to cover the min quantity with fee! + INFO swap::api::request: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.00001 BTC max_giveable=0 BTC minimum_amount=0 BTC maximum_amount=0.01 BTC + INFO swap::api::request: Received Bitcoin new_balance=0.1001 BTC max_giveable=0.1 BTC " ); } @@ -149,7 +149,7 @@ mod tests { assert_eq!((amount, fees), (expected_amount, expected_fees)); assert_eq!( writer.captured(), - " INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.00000000 BTC maximum_amount=0.01000000 BTC\n" + " INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0 BTC maximum_amount=0.01 BTC\n" ); } @@ -182,7 +182,7 @@ mod tests { assert_eq!((amount, fees), (expected_amount, expected_fees)); assert_eq!( writer.captured(), - " INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.00000000 BTC maximum_amount=0.01000000 BTC\n" + " INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0 BTC maximum_amount=0.01 BTC\n" ); } @@ -215,10 +215,10 @@ mod tests { assert_eq!((amount, fees), (expected_amount, expected_fees)); assert_eq!( writer.captured(), - r" INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.01000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Deposit at least 0.01001000 BTC to cover the min quantity with fee! - INFO swap: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.01001000 BTC max_giveable=0.00000000 BTC minimum_amount=0.01000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Received Bitcoin new_balance=0.01010000 BTC max_giveable=0.01000000 BTC + r" INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0.01 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Deposit at least 0.01001 BTC to cover the min quantity with fee! + INFO swap::api::request: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.01001 BTC max_giveable=0 BTC minimum_amount=0.01 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Received Bitcoin new_balance=0.0101 BTC max_giveable=0.01 BTC " ); } @@ -252,10 +252,10 @@ mod tests { assert_eq!((amount, fees), (expected_amount, expected_fees)); assert_eq!( writer.captured(), - r" INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.01000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Deposit at least 0.00991000 BTC to cover the min quantity with fee! - INFO swap: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.00991000 BTC max_giveable=0.00010000 BTC minimum_amount=0.01000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Received Bitcoin new_balance=0.01010000 BTC max_giveable=0.01000000 BTC + r" INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0.01 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Deposit at least 0.00991 BTC to cover the min quantity with fee! + INFO swap::api::request: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.00991 BTC max_giveable=0.0001 BTC minimum_amount=0.01 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Received Bitcoin new_balance=0.0101 BTC max_giveable=0.01 BTC " ); } @@ -292,13 +292,13 @@ mod tests { assert!(matches!(error, tokio::time::error::Elapsed { .. })); assert_eq!( writer.captured(), - r" INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.10000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Deposit at least 0.10001000 BTC to cover the min quantity with fee! - INFO swap: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.10001000 BTC max_giveable=0.00000000 BTC minimum_amount=0.10000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Received Bitcoin new_balance=0.01010000 BTC max_giveable=0.01000000 BTC - INFO swap: Deposited amount is less than `min_quantity` - INFO swap: Deposit at least 0.09001000 BTC to cover the min quantity with fee! - INFO swap: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.09001000 BTC max_giveable=0.01000000 BTC minimum_amount=0.10000000 BTC maximum_amount=184467440737.09551615 BTC + r" INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0.1 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Deposit at least 0.10001 BTC to cover the min quantity with fee! + INFO swap::api::request: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.10001 BTC max_giveable=0 BTC minimum_amount=0.1 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Received Bitcoin new_balance=0.0101 BTC max_giveable=0.01 BTC + INFO swap::api::request: Deposited amount is less than `min_quantity` + INFO swap::api::request: Deposit at least 0.09001 BTC to cover the min quantity with fee! + INFO swap::api::request: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.09001 BTC max_giveable=0.01 BTC minimum_amount=0.1 BTC maximum_amount=184467440737.09551615 BTC " ); } @@ -341,10 +341,10 @@ mod tests { assert_eq!( writer.captured(), - r" INFO swap: Received quote price=0.00100000 BTC minimum_amount=0.10000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Deposit at least 0.10001000 BTC to cover the min quantity with fee! - INFO swap: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.10001000 BTC max_giveable=0.00000000 BTC minimum_amount=0.10000000 BTC maximum_amount=184467440737.09551615 BTC - INFO swap: Received Bitcoin new_balance=0.21000000 BTC max_giveable=0.20000000 BTC + r" INFO swap::api::request: Received quote price=0.001 BTC minimum_amount=0.1 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Deposit at least 0.10001 BTC to cover the min quantity with fee! + INFO swap::api::request: Waiting for Bitcoin deposit deposit_address=1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6 min_deposit=0.10001 BTC max_giveable=0 BTC minimum_amount=0.1 BTC maximum_amount=184467440737.09551615 BTC + INFO swap::api::request: Received Bitcoin new_balance=0.21 BTC max_giveable=0.2 BTC " ); } diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 70596bbe..242b48ce 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -499,15 +499,20 @@ mod tests { use crate::api::api_test::*; use crate::api::Config; - use crate::fs::system_data_dir; use crate::monero::monero_address::MoneroAddressNetworkMismatch; - use serial_test::serial; const BINARY_NAME: &str = "swap"; const ARGS_DATA_DIR: &str = "/tmp/dir/"; #[tokio::test] - async fn given_buy_xmr_on_mainnet_then_defaults_to_mainnet() { + + // 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 + let raw_ars = vec![ BINARY_NAME, "buy-xmr", @@ -522,22 +527,28 @@ mod tests { let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (false, false, false); - let (expected_config, expected_request) = ( - Config::default(is_testnet, None, debug, json), - Request::buy_xmr(is_testnet), - ); - let (actual_config, actual_request) = match args { ParseResult::Context(context, request) => (context.config.clone(), request), _ => panic!("Couldn't parse result"), }; + let (expected_config, mut expected_request) = ( + Config::default(is_testnet, None, debug, json), + Request::buy_xmr(is_testnet), + ); + + // since Uuid is random, copy before comparing requests + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - async fn given_buy_xmr_on_testnet_then_defaults_to_testnet() { + // given_buy_xmr_on_testnet_then_defaults_to_testnet let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -553,7 +564,7 @@ mod tests { let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (true, false, false); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, None, debug, json), Request::buy_xmr(is_testnet), ); @@ -563,13 +574,17 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_mainnet_with_testnet_address_then_fails() { + // given_buy_xmr_on_mainnet_with_testnet_address_then_fails let raw_ars = vec![ BINARY_NAME, "buy-xmr", @@ -590,11 +605,8 @@ mod tests { actual: monero::Network::Stagenet } ); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_testnet_with_mainnet_address_then_fails() { + // given_buy_xmr_on_testnet_with_mainnet_address_then_fails let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -616,11 +628,8 @@ mod tests { actual: monero::Network::Mainnet } ); - } - #[tokio::test] - #[serial] - async fn given_resume_on_mainnet_then_defaults_to_mainnet() { + // given_resume_on_mainnet_then_defaults_to_mainnet let raw_ars = vec![BINARY_NAME, "resume", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); @@ -638,11 +647,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_resume_on_testnet_then_defaults_to_testnet() { + // given_resume_on_testnet_then_defaults_to_testnet let raw_ars = vec![BINARY_NAME, "--testnet", "resume", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); @@ -660,11 +666,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_cancel_on_mainnet_then_defaults_to_mainnet() { + // given_cancel_on_mainnet_then_defaults_to_mainnet let raw_ars = vec![BINARY_NAME, "cancel", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); @@ -683,11 +686,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_cancel_on_testnet_then_defaults_to_testnet() { + // given_cancel_on_testnet_then_defaults_to_testnet let raw_ars = vec![BINARY_NAME, "--testnet", "cancel", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); @@ -705,11 +705,7 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_refund_on_mainnet_then_defaults_to_mainnet() { let raw_ars = vec![BINARY_NAME, "refund", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); @@ -727,11 +723,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_refund_on_testnet_then_defaults_to_testnet() { + // given_refund_on_testnet_then_defaults_to_testnet let raw_ars = vec![BINARY_NAME, "--testnet", "refund", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); @@ -749,11 +742,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_mainnet_with_data_dir_then_data_dir_set() { + // given_buy_xmr_on_mainnet_with_data_dir_then_data_dir_set let raw_ars = vec![ BINARY_NAME, "--data-base-dir", @@ -771,7 +761,7 @@ mod tests { let (is_testnet, debug, json) = (false, false, false); let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap(); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, Some(data_dir.clone()), debug, json), Request::buy_xmr(is_testnet), ); @@ -781,13 +771,17 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_testnet_with_data_dir_then_data_dir_set() { + // given_buy_xmr_on_testnet_with_data_dir_then_data_dir_set let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -806,7 +800,7 @@ mod tests { let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (true, false, false); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, Some(data_dir.clone()), debug, json), Request::buy_xmr(is_testnet), ); @@ -816,13 +810,17 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_resume_on_mainnet_with_data_dir_then_data_dir_set() { + // given_resume_on_mainnet_with_data_dir_then_data_dir_set let raw_ars = vec![ BINARY_NAME, "--data-base-dir", @@ -836,11 +834,18 @@ mod tests { let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (false, false, false); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, Some(data_dir.clone()), debug, json), Request::resume(), ); + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + let (actual_config, actual_request) = match args { ParseResult::Context(context, request) => (context.config.clone(), request), _ => panic!("Couldn't parse result"), @@ -848,11 +853,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_resume_on_testnet_with_data_dir_then_data_dir_set() { + // given_resume_on_testnet_with_data_dir_then_data_dir_set let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -879,11 +881,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_mainnet_with_debug_then_debug_set() { + // given_buy_xmr_on_mainnet_with_debug_then_debug_set let raw_ars = vec![ BINARY_NAME, "--debug", @@ -899,7 +898,7 @@ mod tests { let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (false, true, false); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, None, debug, json), Request::buy_xmr(is_testnet), ); @@ -909,13 +908,17 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_testnet_with_debug_then_debug_set() { + // given_buy_xmr_on_testnet_with_debug_then_debug_set let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -932,7 +935,7 @@ mod tests { let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (true, true, false); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, None, debug, json), Request::buy_xmr(is_testnet), ); @@ -942,19 +945,23 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_resume_on_mainnet_with_debug_then_debug_set() { + // given_resume_on_mainnet_with_debug_then_debug_set let raw_ars = vec![BINARY_NAME, "--debug", "resume", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (false, true, false); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, None, debug, json), Request::resume(), ); @@ -964,13 +971,17 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_resume_on_testnet_with_debug_then_debug_set() { + // given_resume_on_testnet_with_debug_then_debug_set let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -995,11 +1006,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_mainnet_with_json_then_json_set() { + // given_buy_xmr_on_mainnet_with_json_then_json_set let raw_ars = vec![ BINARY_NAME, "--json", @@ -1015,7 +1023,7 @@ mod tests { let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (false, false, true); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, None, debug, json), Request::buy_xmr(is_testnet), ); @@ -1025,13 +1033,17 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_buy_xmr_on_testnet_with_json_then_json_set() { + // given_buy_xmr_on_testnet_with_json_then_json_set let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -1047,7 +1059,7 @@ mod tests { let (is_testnet, debug, json) = (true, false, true); - let (expected_config, expected_request) = ( + let (expected_config, mut expected_request) = ( Config::default(is_testnet, None, debug, json), Request::buy_xmr(is_testnet), ); @@ -1058,13 +1070,17 @@ mod tests { _ => panic!("Couldn't parse result"), }; + if let Method::BuyXmr { ref mut swap_id, .. } = expected_request.cmd { + *swap_id = match actual_request.cmd { + Method::BuyXmr { swap_id, .. } => { swap_id }, + _ => panic!("Not the Method we expected") + } + }; + assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_resume_on_mainnet_with_json_then_json_set() { + // given_resume_on_mainnet_with_json_then_json_set let raw_ars = vec![BINARY_NAME, "--json", "resume", "--swap-id", SWAP_ID]; let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); let (is_testnet, debug, json) = (false, false, true); @@ -1081,11 +1097,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn given_resume_on_testnet_with_json_then_json_set() { + // given_resume_on_testnet_with_json_then_json_set let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -1110,11 +1123,8 @@ mod tests { assert_eq!(actual_config, expected_config); assert_eq!(actual_request, Box::new(expected_request)); - } - #[tokio::test] - #[serial] - async fn only_bech32_addresses_mainnet_are_allowed() { + // only_bech32_addresses_mainnet_are_allowed let raw_ars = vec![ BINARY_NAME, "buy-xmr", @@ -1125,7 +1135,7 @@ mod tests { "--seller", MULTI_ADDRESS, ]; - let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); + parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); let raw_ars = vec![ BINARY_NAME, @@ -1137,7 +1147,7 @@ mod tests { "--seller", MULTI_ADDRESS, ]; - let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); + parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); let raw_ars = vec![ BINARY_NAME, @@ -1151,11 +1161,8 @@ mod tests { ]; let result = parse_args_and_apply_defaults(raw_ars).await.unwrap(); assert!(matches!(result, ParseResult::Context(_, _))); - } - #[tokio::test] - #[serial] - async fn only_bech32_addresses_testnet_are_allowed() { + // only_bech32_addresses_testnet_are_allowed let raw_ars = vec![ BINARY_NAME, "--testnet", @@ -1167,7 +1174,7 @@ mod tests { "--seller", MULTI_ADDRESS, ]; - let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); + parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); let raw_ars = vec![ BINARY_NAME, @@ -1180,7 +1187,7 @@ mod tests { "--seller", MULTI_ADDRESS, ]; - let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); + parse_args_and_apply_defaults(raw_ars).await.unwrap_err(); let raw_ars = vec![ BINARY_NAME, @@ -1196,12 +1203,4 @@ mod tests { let result = parse_args_and_apply_defaults(raw_ars).await.unwrap(); assert!(matches!(result, ParseResult::Context(_, _))); } - - fn data_dir_path_cli(is_testnet: bool) -> PathBuf { - if is_testnet { - system_data_dir().unwrap().join("cli").join("testnet") - } else { - system_data_dir().unwrap().join("cli").join("mainnet") - } - } }