Rename testutils to harness

This allows us to bring in a dependency named `testutils`.
This commit is contained in:
Thomas Eizinger 2021-03-24 17:49:19 +11:00
parent 11b45cd8c0
commit b9d8cbeaa2
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
10 changed files with 33 additions and 33 deletions

View File

@ -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::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};
use testutils::bob_run_until::is_btc_locked;
use testutils::FastCancelConfig;
#[tokio::test] #[tokio::test]
async fn given_bob_manually_refunds_after_btc_locked_bob_refunds() { 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, bob_join_handle) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked)); let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked));

View File

@ -1,14 +1,14 @@
pub mod testutils; pub mod harness;
use bob::cancel::Error; use bob::cancel::Error;
use harness::bob_run_until::is_btc_locked;
use harness::SlowCancelConfig;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};
use testutils::bob_run_until::is_btc_locked;
use testutils::SlowCancelConfig;
#[tokio::test] #[tokio::test]
async fn given_bob_manually_cancels_when_timelock_not_expired_errors() { 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, bob_join_handle) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked)); let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked));

View File

@ -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::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};
use testutils::bob_run_until::is_btc_locked;
use testutils::SlowCancelConfig;
#[tokio::test] #[tokio::test]
async fn given_bob_manually_forces_cancel_when_timelock_not_expired_errors() { 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, bob_join_handle) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked)); let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked));

View File

@ -1,14 +1,14 @@
pub mod testutils; pub mod harness;
use harness::SlowCancelConfig;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};
use testutils::SlowCancelConfig;
use tokio::join; use tokio::join;
/// Run the following tests with RUST_MIN_STACK=10000000 /// Run the following tests with RUST_MIN_STACK=10000000
#[tokio::test] #[tokio::test]
async fn happy_path() { 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, _) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run(bob_swap)); let bob_swap = tokio::spawn(bob::run(bob_swap));

View File

@ -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::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};
use testutils::bob_run_until::is_xmr_locked;
use testutils::SlowCancelConfig;
#[tokio::test] #[tokio::test]
async fn given_bob_restarts_after_xmr_is_locked_resume_swap() { 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, bob_join_handle) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_xmr_locked)); let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_xmr_locked));

View File

@ -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::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};
use testutils::bob_run_until::is_xmr_locked;
use testutils::SlowCancelConfig;
#[tokio::test] #[tokio::test]
async fn given_bob_restarts_after_xmr_is_locked_resume_swap() { 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, bob_join_handle) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_xmr_locked)); let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_xmr_locked));

View File

@ -1,4 +1,4 @@
use crate::testutils::bitcoind; use crate::harness::bitcoind;
use bitcoin::Network; use bitcoin::Network;
use std::collections::HashMap; use std::collections::HashMap;
use testcontainers::core::{Container, Docker, WaitForMessage}; use testcontainers::core::{Container, Docker, WaitForMessage};

View File

@ -1,7 +1,7 @@
mod bitcoind; mod bitcoind;
mod electrs; mod electrs;
use crate::testutils; use crate::harness;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use async_trait::async_trait; use async_trait::async_trait;
use bitcoin_harness::{BitcoindRpcApi, Client}; use bitcoin_harness::{BitcoindRpcApi, Client};
@ -452,7 +452,7 @@ where
let env_config = C::get_config(); 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 btc_amount = bitcoin::Amount::from_sat(1_000_000);
let xmr_amount = monero::Amount::from_monero(btc_amount.as_btc() / FixedRate::RATE).unwrap(); let xmr_amount = monero::Amount::from_monero(btc_amount.as_btc() / FixedRate::RATE).unwrap();
@ -470,7 +470,7 @@ where
let electrs_rpc_port = containers let electrs_rpc_port = containers
.electrs .electrs
.get_host_port(testutils::electrs::RPC_PORT) .get_host_port(harness::electrs::RPC_PORT)
.expect("Could not map electrs rpc port"); .expect("Could not map electrs rpc port");
let alice_seed = Seed::random().unwrap(); 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 docker = cli.run_with_args(image, run_args);
let a = docker let a = docker
.get_host_port(testutils::bitcoind::RPC_PORT) .get_host_port(harness::bitcoind::RPC_PORT)
.context("Could not map bitcoind rpc port")?; .context("Could not map bitcoind rpc port")?;
let bitcoind_url = { let bitcoind_url = {
@ -627,7 +627,7 @@ pub async fn init_electrs_container(
let bitcoind_rpc_addr = format!( let bitcoind_rpc_addr = format!(
"{}:{}", "{}:{}",
bitcoind_container_name, bitcoind_container_name,
testutils::bitcoind::RPC_PORT harness::bitcoind::RPC_PORT
); );
let image = electrs::Electrs::default() let image = electrs::Electrs::default()
.with_volume(volume) .with_volume(volume)

View File

@ -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::bob::BobState;
use swap::protocol::{alice, bob}; 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 /// 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. /// the encsig and fail to refund or redeem. Alice punishes.
#[tokio::test] #[tokio::test]
async fn alice_punishes_if_bob_never_acts_after_fund() { 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, bob_join_handle) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked)); let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked));