mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-20 16:06:00 -04:00
Move tests under src
This commit is contained in:
parent
91fe18a796
commit
f24f77fcd1
@ -23,6 +23,8 @@ pub mod monero;
|
||||
pub mod network;
|
||||
pub mod protocol;
|
||||
pub mod seed;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub mod trace;
|
||||
|
||||
mod fs;
|
||||
|
@ -33,6 +33,8 @@ pub mod monero;
|
||||
pub mod network;
|
||||
pub mod protocol;
|
||||
pub mod seed;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub mod trace;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -1,13 +1,14 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, bob};
|
||||
use crate::{
|
||||
protocol::{alice, bob},
|
||||
tests::setup_test,
|
||||
};
|
||||
use tokio::join;
|
||||
|
||||
/// Run the following tests with RUST_MIN_STACK=10000000
|
||||
|
||||
#[tokio::test]
|
||||
async fn happy_path() {
|
||||
testutils::setup_test(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
@ -1,11 +1,11 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, alice::AliceState, bob};
|
||||
use testutils::alice_run_until::is_encsig_learned;
|
||||
use crate::{
|
||||
protocol::{alice, alice::AliceState, bob},
|
||||
tests::{alice_run_until::is_encsig_learned, setup_test},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
||||
testutils::setup_test(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
@ -1,11 +1,11 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, bob, bob::BobState};
|
||||
use testutils::bob_run_until::is_encsig_sent;
|
||||
use crate::{
|
||||
protocol::{alice, bob, bob::BobState},
|
||||
tests::{bob_run_until::is_encsig_sent, setup_test},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
||||
testutils::setup_test(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
@ -1,11 +1,11 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, bob, bob::BobState};
|
||||
use testutils::bob_run_until::is_lock_proof_received;
|
||||
use crate::{
|
||||
protocol::{alice, bob, bob::BobState},
|
||||
tests::{bob_run_until::is_lock_proof_received, setup_test},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_bob_restarts_after_lock_proof_received_resume_swap() {
|
||||
testutils::setup_test(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
@ -1,11 +1,11 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, bob, bob::BobState};
|
||||
use testutils::bob_run_until::is_xmr_locked;
|
||||
use crate::{
|
||||
protocol::{alice, bob, bob::BobState},
|
||||
tests::{bob_run_until::is_xmr_locked, setup_test},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
||||
testutils::setup_test(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
@ -1,23 +1,31 @@
|
||||
use crate::testutils;
|
||||
use bitcoin_harness::Bitcoind;
|
||||
use futures::Future;
|
||||
use get_port::get_port;
|
||||
use libp2p::{core::Multiaddr, PeerId};
|
||||
use monero_harness::{image, Monero};
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use swap::{
|
||||
use crate::{
|
||||
bitcoin,
|
||||
config::Config,
|
||||
monero,
|
||||
protocol::{alice, alice::AliceState, bob, bob::BobState, SwapAmounts},
|
||||
seed::Seed,
|
||||
};
|
||||
use bitcoin_harness::Bitcoind;
|
||||
use futures::Future;
|
||||
use get_port::get_port;
|
||||
use libp2p::{core::Multiaddr, PeerId};
|
||||
use monero_harness::{image, Monero};
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use tempfile::tempdir;
|
||||
use testcontainers::{clients::Cli, Container};
|
||||
use tracing_core::dispatcher::DefaultGuard;
|
||||
use tracing_log::LogTracer;
|
||||
use uuid::Uuid;
|
||||
|
||||
mod happy_path;
|
||||
mod happy_path_restart_alice;
|
||||
mod happy_path_restart_bob_after_comm;
|
||||
mod happy_path_restart_bob_after_lock_proof_received;
|
||||
mod happy_path_restart_bob_before_comm;
|
||||
mod punish;
|
||||
mod refund_restart_alice;
|
||||
mod refund_restart_alice_cancelled;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StartingBalances {
|
||||
pub xmr: monero::Amount,
|
||||
@ -297,7 +305,7 @@ where
|
||||
|
||||
let _guard = init_tracing();
|
||||
|
||||
let (monero, containers) = testutils::init_containers(&cli).await;
|
||||
let (monero, containers) = init_containers(&cli).await;
|
||||
|
||||
let swap_amounts = SwapAmounts {
|
||||
btc: bitcoin::Amount::from_sat(1_000_000),
|
||||
@ -398,13 +406,13 @@ async fn init_wallets(
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let xmr_wallet = Arc::new(swap::monero::Wallet {
|
||||
let xmr_wallet = Arc::new(monero::Wallet {
|
||||
inner: monero.wallet(name).unwrap().client(),
|
||||
network: config.monero_network,
|
||||
});
|
||||
|
||||
let btc_wallet = Arc::new(
|
||||
swap::bitcoin::Wallet::new(name, bitcoind.node_url.clone(), config.bitcoin_network)
|
||||
bitcoin::Wallet::new(name, bitcoind.node_url.clone(), config.bitcoin_network)
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
@ -461,7 +469,7 @@ fn init_tracing() -> DefaultGuard {
|
||||
}
|
||||
|
||||
pub mod alice_run_until {
|
||||
use swap::protocol::alice::AliceState;
|
||||
use crate::protocol::alice::AliceState;
|
||||
|
||||
pub fn is_xmr_locked(state: &AliceState) -> bool {
|
||||
matches!(
|
||||
@ -479,7 +487,7 @@ pub mod alice_run_until {
|
||||
}
|
||||
|
||||
pub mod bob_run_until {
|
||||
use swap::protocol::bob::BobState;
|
||||
use crate::protocol::bob::BobState;
|
||||
|
||||
pub fn is_btc_locked(state: &BobState) -> bool {
|
||||
matches!(state, BobState::BtcLocked(..))
|
@ -1,13 +1,13 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, bob, bob::BobState};
|
||||
use testutils::bob_run_until::is_btc_locked;
|
||||
use crate::{
|
||||
protocol::{alice, bob, bob::BobState},
|
||||
tests::{bob_run_until::is_btc_locked, setup_test},
|
||||
};
|
||||
|
||||
/// 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(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
@ -1,13 +1,13 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, alice::AliceState, bob};
|
||||
use testutils::alice_run_until::is_xmr_locked;
|
||||
use crate::{
|
||||
protocol::{alice, alice::AliceState, bob},
|
||||
tests::{alice_run_until::is_xmr_locked, setup_test},
|
||||
};
|
||||
|
||||
/// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice
|
||||
/// then also refunds.
|
||||
#[tokio::test]
|
||||
async fn given_alice_restarts_after_xmr_is_locked_refund_swap() {
|
||||
testutils::setup_test(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
@ -1,14 +1,14 @@
|
||||
pub mod testutils;
|
||||
|
||||
use swap::protocol::{alice, alice::AliceState, bob};
|
||||
use testutils::alice_run_until::is_encsig_learned;
|
||||
use crate::{
|
||||
protocol::{alice, alice::AliceState, bob},
|
||||
tests::{alice_run_until::is_encsig_learned, setup_test},
|
||||
};
|
||||
|
||||
/// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice
|
||||
/// is forced to refund even though she learned the secret and would be able to
|
||||
/// redeem had the timelock not expired.
|
||||
#[tokio::test]
|
||||
async fn given_alice_restarts_after_enc_sig_learned_and_bob_already_cancelled_refund_swap() {
|
||||
testutils::setup_test(|mut ctx| async move {
|
||||
setup_test(|mut ctx| async move {
|
||||
let alice_swap = ctx.new_swap_as_alice().await;
|
||||
let bob_swap = ctx.new_swap_as_bob().await;
|
||||
|
Loading…
x
Reference in New Issue
Block a user