uncommenting and fixing more tests

This commit is contained in:
Lorenzo Tucci 2022-12-04 22:12:33 +01:00
parent f5b62f967c
commit 500684a43e
No known key found for this signature in database
GPG Key ID: D98C4FA2CDF590A0
2 changed files with 322 additions and 334 deletions

View File

@ -737,8 +737,8 @@ pub mod api_test {
pub fn default( pub fn default(
is_testnet: bool, is_testnet: bool,
data_dir: Option<PathBuf>, data_dir: Option<PathBuf>,
json: bool,
debug: bool, debug: bool,
json: bool,
) -> Self { ) -> Self {
let data_dir = data::data_dir_from(data_dir, is_testnet).unwrap(); let data_dir = data::data_dir_from(data_dir, is_testnet).unwrap();

View File

@ -977,339 +977,327 @@ mod tests {
assert_eq!(actual_config, expected_config); assert_eq!(actual_config, expected_config);
assert_eq!(actual_request, Box::new(expected_request)); assert_eq!(actual_request, Box::new(expected_request));
} }
//
// #[tokio::test] #[tokio::test]
// async fn given_with_debug_then_debug_set() { #[sequential]
// let raw_ars = vec![ async fn given_buy_xmr_on_mainnet_with_debug_then_debug_set() {
// BINARY_NAME, let raw_ars = vec![
// "--debug", BINARY_NAME,
// "buy-xmr", "--debug",
// "--change-address", "buy-xmr",
// BITCOIN_MAINNET_ADDRESS, "--change-address",
// "--receive-address", BITCOIN_MAINNET_ADDRESS,
// MONERO_MAINNET_ADDRESS, "--receive-address",
// "--seller", MONERO_MAINNET_ADDRESS,
// MULTI_ADDRESS, "--seller",
// ]; MULTI_ADDRESS,
// ];
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// let (is_testnet, debug, json) = (false, true, false); let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// let data_dir = data_dir_path_cli(is_testnet); let (is_testnet, debug, json) = (false, true, false);
//
// let (expected_context, expected_request) = ( let (expected_config, expected_request) = (
// Context::default(is_testnet, data_dir, debug, json) Config::default(is_testnet, None, debug, json),
// .await Request::buy_xmr(is_testnet),
// .unwrap(), );
// Request::buy_xmr(is_testnet),
// ); let (actual_config, actual_request) = match args {
// ParseResult::Context(context, request) => (context.config.clone(), request),
// let (actual_context, actual_request) = match args { _ => panic!("Couldn't parse result"),
// ParseResult::Context(context, request) => (context, request), };
// _ => panic!("Couldn't parse result"),
// }; assert_eq!(actual_config, expected_config);
// assert_eq!(actual_request, Box::new(expected_request));
// assert_eq!(actual_context, Arc::new(expected_context)); }
// assert_eq!(actual_request, Box::new(expected_request));
// #[tokio::test]
// let raw_ars = vec![ #[sequential]
// BINARY_NAME, async fn given_buy_xmr_on_testnet_with_debug_then_debug_set() {
// "--testnet", let raw_ars = vec![
// "--debug", BINARY_NAME,
// "buy-xmr", "--testnet",
// "--change-address", "--debug",
// BITCOIN_TESTNET_ADDRESS, "buy-xmr",
// "--receive-address", "--change-address",
// MONERO_STAGENET_ADDRESS, BITCOIN_TESTNET_ADDRESS,
// "--seller", "--receive-address",
// MULTI_ADDRESS, MONERO_STAGENET_ADDRESS,
// ]; "--seller",
// MULTI_ADDRESS,
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); ];
// let (is_testnet, debug, json) = (true, true, false);
// let data_dir = data_dir_path_cli(is_testnet); let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// let (is_testnet, debug, json) = (true, true, false);
// let (expected_context, expected_request) = (
// Context::default(is_testnet, data_dir, debug, json) let (expected_config, expected_request) = (
// .await Config::default(is_testnet, None, debug, json),
// .unwrap(), Request::buy_xmr(is_testnet),
// Request::buy_xmr(is_testnet), );
// );
// let (actual_config, actual_request) = match args {
// let (actual_context, actual_request) = match args { ParseResult::Context(context, request) => (context.config.clone(), request),
// ParseResult::Context(context, request) => (context, request), _ => panic!("Couldn't parse result"),
// _ => panic!("Couldn't parse result"), };
// };
// assert_eq!(actual_config, expected_config);
// assert_eq!(actual_context, Arc::new(expected_context)); assert_eq!(actual_request, Box::new(expected_request));
// assert_eq!(actual_request, Box::new(expected_request)); }
//
// let raw_ars = vec![BINARY_NAME, "--debug", "resume", "--swap-id", SWAP_ID]; #[tokio::test]
// #[sequential]
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); async fn given_resume_on_mainnet_with_debug_then_debug_set() {
// let (is_testnet, debug, json) = (false, true, false);
// let data_dir = data_dir_path_cli(is_testnet); let raw_ars = vec![BINARY_NAME, "--debug", "resume", "--swap-id", SWAP_ID];
//
// let (expected_context, expected_request) = ( let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// Context::default(is_testnet, data_dir, debug, json) let (is_testnet, debug, json) = (false, true, false);
// .await
// .unwrap(), let (expected_config, expected_request) = (
// Request::resume(), Config::default(is_testnet, None, debug, json),
// ); Request::resume(),
// );
// let (actual_context, actual_request) = match args {
// ParseResult::Context(context, request) => (context, request), let (actual_config, actual_request) = match args {
// _ => panic!("Couldn't parse result"), ParseResult::Context(context, request) => (context.config.clone(), request),
// }; _ => panic!("Couldn't parse result"),
// };
// assert_eq!(actual_context, Arc::new(expected_context));
// assert_eq!(actual_request, Box::new(expected_request)); assert_eq!(actual_config, expected_config);
// assert_eq!(actual_request, Box::new(expected_request));
// let raw_ars = vec![ }
// BINARY_NAME,
// "--testnet",
// "--debug", #[tokio::test]
// "resume", #[sequential]
// "--swap-id", async fn given_resume_on_testnet_with_debug_then_debug_set() {
// SWAP_ID, let raw_ars = vec![
// ]; BINARY_NAME,
// "--testnet",
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); "--debug",
// let (is_testnet, debug, json) = (true, true, false); "resume",
// let data_dir = data_dir_path_cli(is_testnet); "--swap-id",
// SWAP_ID,
// let (expected_context, expected_request) = ( ];
// Context::default(is_testnet, data_dir, debug, json)
// .await let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// .unwrap(), let (is_testnet, debug, json) = (true, true, false);
// Request::resume(),
// ); let (expected_config, expected_request) = (
// Config::default(is_testnet, None, debug, json),
// let (actual_context, actual_request) = match args { Request::resume(),
// ParseResult::Context(context, request) => (context, request), );
// _ => panic!("Couldn't parse result"),
// }; let (actual_config, actual_request) = match args {
// ParseResult::Context(context, request) => (context.config.clone(), request),
// assert_eq!(actual_context, Arc::new(expected_context)); _ => panic!("Couldn't parse result"),
// assert_eq!(actual_request, Box::new(expected_request)); };
// }
// assert_eq!(actual_config, expected_config);
// #[tokio::test] assert_eq!(actual_request, Box::new(expected_request));
// async fn given_with_json_then_json_set() { }
// let raw_ars = vec![
// BINARY_NAME, #[tokio::test]
// "--json", #[sequential]
// "buy-xmr", async fn given_buy_xmr_on_mainnet_with_json_then_json_set() {
// "--change-address", let raw_ars = vec![
// BITCOIN_MAINNET_ADDRESS, BINARY_NAME,
// "--receive-address", "--json",
// MONERO_MAINNET_ADDRESS, "buy-xmr",
// "--seller", "--change-address",
// MULTI_ADDRESS, BITCOIN_MAINNET_ADDRESS,
// ]; "--receive-address",
// MONERO_MAINNET_ADDRESS,
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); "--seller",
// let (is_testnet, debug, json) = (false, false, true); MULTI_ADDRESS,
// let data_dir = data_dir_path_cli(is_testnet); ];
//
// let (expected_context, expected_request) = ( let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// Context::default(is_testnet, data_dir, debug, json) let (is_testnet, debug, json) = (false, false, true);
// .await let data_dir = data_dir_path_cli(is_testnet);
// .unwrap(),
// Request::buy_xmr(is_testnet), let (expected_config, expected_request) = (
// ); Config::default(is_testnet, None, debug, json),
// Request::buy_xmr(is_testnet),
// let (actual_context, actual_request) = match args { );
// ParseResult::Context(context, request) => (context, request),
// _ => panic!("Couldn't parse result"), let (actual_config, actual_request) = match args {
// }; ParseResult::Context(context, request) => (context.config.clone(), request),
// _ => panic!("Couldn't parse result"),
// assert_eq!(actual_context, Arc::new(expected_context)); };
// assert_eq!(actual_request, Box::new(expected_request));
// assert_eq!(actual_config, expected_config);
// let raw_ars = vec![ assert_eq!(actual_request, Box::new(expected_request));
// BINARY_NAME, }
// "--testnet",
// "--json", #[tokio::test]
// "buy-xmr", #[sequential]
// "--change-address", async fn given_buy_xmr_on_testnet_with_json_then_json_set() {
// BITCOIN_TESTNET_ADDRESS, let raw_ars = vec![
// "--receive-address", BINARY_NAME,
// MONERO_STAGENET_ADDRESS, "--testnet",
// "--seller", "--json",
// MULTI_ADDRESS, "buy-xmr",
// ]; "--change-address",
// BITCOIN_TESTNET_ADDRESS,
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); "--receive-address",
// let (is_testnet, debug, json) = (true, false, true); MONERO_STAGENET_ADDRESS,
// let data_dir = data_dir_path_cli(is_testnet); "--seller",
// MULTI_ADDRESS,
// let (expected_context, expected_request) = ( ];
// Context::default(is_testnet, data_dir, debug, json)
// .await let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// .unwrap(), let (is_testnet, debug, json) = (true, false, true);
// Request::buy_xmr(is_testnet),
// ); let (expected_config, expected_request) = (
// Config::default(is_testnet, None, debug, json),
// let (actual_context, actual_request) = match args { Request::buy_xmr(is_testnet),
// ParseResult::Context(context, request) => (context, request), );
// _ => panic!("Couldn't parse result"),
// }; let (actual_config, actual_request) = match args {
// ParseResult::Context(context, request) => (context.config.clone(), request),
// assert_eq!(actual_context, Arc::new(expected_context)); _ => panic!("Couldn't parse result"),
// assert_eq!(actual_request, Box::new(expected_request)); };
//
// let raw_ars = vec![BINARY_NAME, "--json", "resume", "--swap-id", SWAP_ID]; assert_eq!(actual_config, expected_config);
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap(); assert_eq!(actual_request, Box::new(expected_request));
// let (is_testnet, debug, json) = (false, false, true); }
// let data_dir = data_dir_path_cli(is_testnet);
// #[tokio::test]
// let (expected_context, expected_request) = ( #[sequential]
// Context::default(is_testnet, data_dir, debug, json) async fn given_resume_on_mainnet_with_json_then_json_set() {
// .await
// .unwrap(), let raw_ars = vec![BINARY_NAME, "--json", "resume", "--swap-id", SWAP_ID];
// Request::resume(), let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// ); let (is_testnet, debug, json) = (false, false, true);
//
// let (actual_context, actual_request) = match args { let (expected_config, expected_request) = (
// ParseResult::Context(context, request) => (context, request), Config::default(is_testnet, None, debug, json),
// _ => panic!("Couldn't parse result"), Request::resume(),
// }; );
//
// assert_eq!(actual_context, Arc::new(expected_context)); let (actual_config, actual_request) = match args {
// assert_eq!(actual_request, Box::new(expected_request)); ParseResult::Context(context, request) => (context.config.clone(), request),
// _ => panic!("Couldn't parse result"),
// let raw_ars = vec![ };
// BINARY_NAME,
// "--testnet", assert_eq!(actual_config, expected_config);
// "--json", assert_eq!(actual_request, Box::new(expected_request));
// "resume", }
// "--swap-id",
// SWAP_ID, #[tokio::test]
// ]; #[sequential]
// async fn given_resume_on_testnet_with_json_then_json_set() {
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// let (is_testnet, debug, json) = (true, false, true); let raw_ars = vec![
// let data_dir = data_dir_path_cli(is_testnet); BINARY_NAME,
// "--testnet",
// let (expected_context, expected_request) = ( "--json",
// Context::default(is_testnet, data_dir, debug, json) "resume",
// .await "--swap-id",
// .unwrap(), SWAP_ID,
// Request::resume(), ];
// );
// let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// let (actual_context, actual_request) = match args { let (is_testnet, debug, json) = (true, false, true);
// ParseResult::Context(context, request) => (context, request),
// _ => panic!("Couldn't parse result"), let (expected_config, expected_request) = (
// }; Config::default(is_testnet, None, debug, json),
// Request::resume(),
// assert_eq!(actual_context, Arc::new(expected_context)); );
// assert_eq!(actual_request, Box::new(expected_request));
// } let (actual_config, actual_request) = match args {
// ParseResult::Context(context, request) => (context.config.clone(), request),
// #[tokio::test] _ => panic!("Couldn't parse result"),
// async fn only_bech32_addresses_mainnet_are_allowed() { };
// let raw_ars = vec![
// BINARY_NAME, assert_eq!(actual_config, expected_config);
// "buy-xmr", assert_eq!(actual_request, Box::new(expected_request));
// "--change-address", }
// "1A5btpLKZjgYm8R22rJAhdbTFVXgSRA2Mp",
// "--receive-address", #[tokio::test]
// MONERO_MAINNET_ADDRESS, #[sequential]
// "--seller", async fn only_bech32_addresses_mainnet_are_allowed() {
// MULTI_ADDRESS, let raw_ars = vec![
// ]; BINARY_NAME,
// let args = parse_args_and_apply_defaults(raw_ars).await; "buy-xmr",
// let (is_testnet, debug, json) = (false, false, false); "--change-address",
// let data_dir = data_dir_path_cli(is_testnet); "1A5btpLKZjgYm8R22rJAhdbTFVXgSRA2Mp",
// "--receive-address",
// assert_eq!( MONERO_MAINNET_ADDRESS,
// args.unwrap_err().to_string(), "--seller",
// "Invalid Bitcoin address provided, only bech32 format is supported!" MULTI_ADDRESS,
// ); ];
// let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
// let raw_ars = vec![
// BINARY_NAME, let raw_ars = vec![
// "buy-xmr", BINARY_NAME,
// "--change-address", "buy-xmr",
// "36vn4mFhmTXn7YcNwELFPxTXhjorw2ppu2", "--change-address",
// "--receive-address", "36vn4mFhmTXn7YcNwELFPxTXhjorw2ppu2",
// MONERO_MAINNET_ADDRESS, "--receive-address",
// "--seller", MONERO_MAINNET_ADDRESS,
// MULTI_ADDRESS, "--seller",
// ]; MULTI_ADDRESS,
// let result = parse_args_and_apply_defaults(raw_ars); ];
// assert_eq!( let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
// result.await.unwrap_err().to_string(),
// "Invalid Bitcoin address provided, only bech32 format is supported!" let raw_ars = vec![
// ); BINARY_NAME,
// "buy-xmr",
// let raw_ars = vec![ "--change-address",
// BINARY_NAME, "bc1qh4zjxrqe3trzg7s6m7y67q2jzrw3ru5mx3z7j3",
// "buy-xmr", "--receive-address",
// "--change-address", MONERO_MAINNET_ADDRESS,
// "bc1qh4zjxrqe3trzg7s6m7y67q2jzrw3ru5mx3z7j3", "--seller",
// "--receive-address", MULTI_ADDRESS,
// MONERO_MAINNET_ADDRESS, ];
// "--seller", let result = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// MULTI_ADDRESS, assert!(matches!(result, ParseResult::Context(_, _)));
// ]; }
// let result = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// // assert!(matches!(result, ParseResult::Arguments(_))); #[tokio::test]
// assert!(true); #[sequential]
// } async fn only_bech32_addresses_testnet_are_allowed() {
// let raw_ars = vec![
// #[tokio::test] BINARY_NAME,
// async fn only_bech32_addresses_testnet_are_allowed() { "--testnet",
// let raw_ars = vec![ "buy-xmr",
// BINARY_NAME, "--change-address",
// "--testnet", "n2czxyeFCQp9e8WRyGpy4oL4YfQAeKkkUH",
// "buy-xmr", "--receive-address",
// "--change-address", MONERO_STAGENET_ADDRESS,
// "n2czxyeFCQp9e8WRyGpy4oL4YfQAeKkkUH", "--seller",
// "--receive-address", MULTI_ADDRESS,
// MONERO_STAGENET_ADDRESS, ];
// "--seller", let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
// MULTI_ADDRESS,
// ]; let raw_ars = vec![
// let result = parse_args_and_apply_defaults(raw_ars); BINARY_NAME,
// assert_eq!( "--testnet",
// result.await.unwrap_err().to_string(), "buy-xmr",
// "Invalid Bitcoin address provided, only bech32 format is supported!" "--change-address",
// ); "2ND9a4xmQG89qEWG3ETRuytjKpLmGrW7Jvf",
// "--receive-address",
// let raw_ars = vec![ MONERO_STAGENET_ADDRESS,
// BINARY_NAME, "--seller",
// "--testnet", MULTI_ADDRESS,
// "buy-xmr", ];
// "--change-address", let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
// "2ND9a4xmQG89qEWG3ETRuytjKpLmGrW7Jvf",
// "--receive-address", let raw_ars = vec![
// MONERO_STAGENET_ADDRESS, BINARY_NAME,
// "--seller", "--testnet",
// MULTI_ADDRESS, "buy-xmr",
// ]; "--change-address",
// let result = parse_args_and_apply_defaults(raw_ars); "tb1q958vfh3wkdp232pktq8zzvmttyxeqnj80zkz3v",
// assert_eq!( "--receive-address",
// result.await.unwrap_err().to_string(), MONERO_STAGENET_ADDRESS,
// "Invalid Bitcoin address provided, only bech32 format is supported!" "--seller",
// ); MULTI_ADDRESS,
// ];
// let raw_ars = vec![ let result = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// BINARY_NAME, assert!(matches!(result, ParseResult::Context(_, _)));
// "--testnet", }
// "buy-xmr",
// "--change-address",
// "tb1q958vfh3wkdp232pktq8zzvmttyxeqnj80zkz3v",
// "--receive-address",
// MONERO_STAGENET_ADDRESS,
// "--seller",
// MULTI_ADDRESS,
// ];
// let result = parse_args_and_apply_defaults(raw_ars).await.unwrap();
// // assert!(matches!(result, ParseResult::Arguments(_)));
// assert!(true);
// }
fn data_dir_path_cli(is_testnet: bool) -> PathBuf { fn data_dir_path_cli(is_testnet: bool) -> PathBuf {
if is_testnet { if is_testnet {