From b9d8cbeaa264bcc7fb61c7f077921a45fc5b6bc4 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 24 Mar 2021 17:49:19 +1100 Subject: [PATCH] Rename testutils to harness This allows us to bring in a dependency named `testutils`. --- .../bob_refunds_using_cancel_and_refund_command.rs | 8 ++++---- ...g_cancel_and_refund_command_timelock_not_expired.rs | 8 ++++---- ...el_and_refund_command_timelock_not_expired_force.rs | 8 ++++---- swap/tests/happy_path.rs | 6 +++--- swap/tests/happy_path_restart_bob_after_xmr_locked.rs | 8 ++++---- swap/tests/happy_path_restart_bob_before_xmr_locked.rs | 8 ++++---- swap/tests/{testutils => harness}/bitcoind.rs | 0 swap/tests/{testutils => harness}/electrs.rs | 2 +- swap/tests/{testutils => harness}/mod.rs | 10 +++++----- swap/tests/punish.rs | 8 ++++---- 10 files changed, 33 insertions(+), 33 deletions(-) rename swap/tests/{testutils => harness}/bitcoind.rs (100%) rename swap/tests/{testutils => harness}/electrs.rs (99%) rename swap/tests/{testutils => harness}/mod.rs (99%) diff --git a/swap/tests/bob_refunds_using_cancel_and_refund_command.rs b/swap/tests/bob_refunds_using_cancel_and_refund_command.rs index e04eab58..f9a7a41e 100644 --- a/swap/tests/bob_refunds_using_cancel_and_refund_command.rs +++ b/swap/tests/bob_refunds_using_cancel_and_refund_command.rs @@ -1,13 +1,13 @@ -pub mod testutils; +pub mod harness; +use harness::bob_run_until::is_btc_locked; +use harness::FastCancelConfig; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; -use testutils::bob_run_until::is_btc_locked; -use testutils::FastCancelConfig; #[tokio::test] async fn given_bob_manually_refunds_after_btc_locked_bob_refunds() { - testutils::setup_test(FastCancelConfig, |mut ctx| async move { + harness::setup_test(FastCancelConfig, |mut ctx| async move { let (bob_swap, bob_join_handle) = ctx.bob_swap().await; let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked)); diff --git a/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired.rs b/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired.rs index 8edf705d..13793009 100644 --- a/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired.rs +++ b/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired.rs @@ -1,14 +1,14 @@ -pub mod testutils; +pub mod harness; use bob::cancel::Error; +use harness::bob_run_until::is_btc_locked; +use harness::SlowCancelConfig; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; -use testutils::bob_run_until::is_btc_locked; -use testutils::SlowCancelConfig; #[tokio::test] async fn given_bob_manually_cancels_when_timelock_not_expired_errors() { - testutils::setup_test(SlowCancelConfig, |mut ctx| async move { + harness::setup_test(SlowCancelConfig, |mut ctx| async move { let (bob_swap, bob_join_handle) = ctx.bob_swap().await; let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked)); diff --git a/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired_force.rs b/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired_force.rs index ff46d683..8a9d7f66 100644 --- a/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired_force.rs +++ b/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired_force.rs @@ -1,13 +1,13 @@ -pub mod testutils; +pub mod harness; +use harness::bob_run_until::is_btc_locked; +use harness::SlowCancelConfig; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; -use testutils::bob_run_until::is_btc_locked; -use testutils::SlowCancelConfig; #[tokio::test] async fn given_bob_manually_forces_cancel_when_timelock_not_expired_errors() { - testutils::setup_test(SlowCancelConfig, |mut ctx| async move { + harness::setup_test(SlowCancelConfig, |mut ctx| async move { let (bob_swap, bob_join_handle) = ctx.bob_swap().await; let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked)); diff --git a/swap/tests/happy_path.rs b/swap/tests/happy_path.rs index fb665e73..5f1ac5b3 100644 --- a/swap/tests/happy_path.rs +++ b/swap/tests/happy_path.rs @@ -1,14 +1,14 @@ -pub mod testutils; +pub mod harness; +use harness::SlowCancelConfig; use swap::protocol::{alice, bob}; -use testutils::SlowCancelConfig; use tokio::join; /// Run the following tests with RUST_MIN_STACK=10000000 #[tokio::test] async fn happy_path() { - testutils::setup_test(SlowCancelConfig, |mut ctx| async move { + harness::setup_test(SlowCancelConfig, |mut ctx| async move { let (bob_swap, _) = ctx.bob_swap().await; let bob_swap = tokio::spawn(bob::run(bob_swap)); diff --git a/swap/tests/happy_path_restart_bob_after_xmr_locked.rs b/swap/tests/happy_path_restart_bob_after_xmr_locked.rs index 6abba569..9967c117 100644 --- a/swap/tests/happy_path_restart_bob_after_xmr_locked.rs +++ b/swap/tests/happy_path_restart_bob_after_xmr_locked.rs @@ -1,13 +1,13 @@ -pub mod testutils; +pub mod harness; +use harness::bob_run_until::is_xmr_locked; +use harness::SlowCancelConfig; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; -use testutils::bob_run_until::is_xmr_locked; -use testutils::SlowCancelConfig; #[tokio::test] async fn given_bob_restarts_after_xmr_is_locked_resume_swap() { - testutils::setup_test(SlowCancelConfig, |mut ctx| async move { + harness::setup_test(SlowCancelConfig, |mut ctx| async move { let (bob_swap, bob_join_handle) = ctx.bob_swap().await; let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_xmr_locked)); diff --git a/swap/tests/happy_path_restart_bob_before_xmr_locked.rs b/swap/tests/happy_path_restart_bob_before_xmr_locked.rs index 6abba569..9967c117 100644 --- a/swap/tests/happy_path_restart_bob_before_xmr_locked.rs +++ b/swap/tests/happy_path_restart_bob_before_xmr_locked.rs @@ -1,13 +1,13 @@ -pub mod testutils; +pub mod harness; +use harness::bob_run_until::is_xmr_locked; +use harness::SlowCancelConfig; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; -use testutils::bob_run_until::is_xmr_locked; -use testutils::SlowCancelConfig; #[tokio::test] async fn given_bob_restarts_after_xmr_is_locked_resume_swap() { - testutils::setup_test(SlowCancelConfig, |mut ctx| async move { + harness::setup_test(SlowCancelConfig, |mut ctx| async move { let (bob_swap, bob_join_handle) = ctx.bob_swap().await; let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_xmr_locked)); diff --git a/swap/tests/testutils/bitcoind.rs b/swap/tests/harness/bitcoind.rs similarity index 100% rename from swap/tests/testutils/bitcoind.rs rename to swap/tests/harness/bitcoind.rs diff --git a/swap/tests/testutils/electrs.rs b/swap/tests/harness/electrs.rs similarity index 99% rename from swap/tests/testutils/electrs.rs rename to swap/tests/harness/electrs.rs index c4c09720..46eff15a 100644 --- a/swap/tests/testutils/electrs.rs +++ b/swap/tests/harness/electrs.rs @@ -1,4 +1,4 @@ -use crate::testutils::bitcoind; +use crate::harness::bitcoind; use bitcoin::Network; use std::collections::HashMap; use testcontainers::core::{Container, Docker, WaitForMessage}; diff --git a/swap/tests/testutils/mod.rs b/swap/tests/harness/mod.rs similarity index 99% rename from swap/tests/testutils/mod.rs rename to swap/tests/harness/mod.rs index 7df968ed..8fafe985 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/harness/mod.rs @@ -1,7 +1,7 @@ mod bitcoind; mod electrs; -use crate::testutils; +use crate::harness; use anyhow::{bail, Context, Result}; use async_trait::async_trait; use bitcoin_harness::{BitcoindRpcApi, Client}; @@ -452,7 +452,7 @@ where let env_config = C::get_config(); - let (monero, containers) = testutils::init_containers(&cli).await; + let (monero, containers) = harness::init_containers(&cli).await; let btc_amount = bitcoin::Amount::from_sat(1_000_000); let xmr_amount = monero::Amount::from_monero(btc_amount.as_btc() / FixedRate::RATE).unwrap(); @@ -470,7 +470,7 @@ where let electrs_rpc_port = containers .electrs - .get_host_port(testutils::electrs::RPC_PORT) + .get_host_port(harness::electrs::RPC_PORT) .expect("Could not map electrs rpc port"); let alice_seed = Seed::random().unwrap(); @@ -600,7 +600,7 @@ async fn init_bitcoind_container( let docker = cli.run_with_args(image, run_args); let a = docker - .get_host_port(testutils::bitcoind::RPC_PORT) + .get_host_port(harness::bitcoind::RPC_PORT) .context("Could not map bitcoind rpc port")?; let bitcoind_url = { @@ -627,7 +627,7 @@ pub async fn init_electrs_container( let bitcoind_rpc_addr = format!( "{}:{}", bitcoind_container_name, - testutils::bitcoind::RPC_PORT + harness::bitcoind::RPC_PORT ); let image = electrs::Electrs::default() .with_volume(volume) diff --git a/swap/tests/punish.rs b/swap/tests/punish.rs index 758f8e98..f058dc79 100644 --- a/swap/tests/punish.rs +++ b/swap/tests/punish.rs @@ -1,15 +1,15 @@ -pub mod testutils; +pub mod harness; +use harness::bob_run_until::is_btc_locked; +use harness::FastPunishConfig; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob}; -use testutils::bob_run_until::is_btc_locked; -use testutils::FastPunishConfig; /// Bob locks Btc and Alice locks Xmr. Bob does not act; he fails to send Alice /// the encsig and fail to refund or redeem. Alice punishes. #[tokio::test] async fn alice_punishes_if_bob_never_acts_after_fund() { - testutils::setup_test(FastPunishConfig, |mut ctx| async move { + harness::setup_test(FastPunishConfig, |mut ctx| async move { let (bob_swap, bob_join_handle) = ctx.bob_swap().await; let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked));