mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-06 21:44:49 -04:00
Move tests under src/
This commit is contained in:
parent
9eae0db9ac
commit
99e34bfc6b
14 changed files with 63 additions and 40 deletions
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
@ -107,8 +107,8 @@ jobs:
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
run: cargo test --package monero-harness --all-features
|
run: cargo test --package monero-harness --all-features
|
||||||
|
|
||||||
- name: Run library tests for swap
|
- name: Run library tests for swap (without test containers)
|
||||||
run: cargo test --package swap --lib --all-features
|
run: cargo test --package swap --lib
|
||||||
|
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
run: |
|
run: |
|
||||||
|
@ -160,7 +160,7 @@ jobs:
|
||||||
key: rust-${{ env.TARGET }}-cargo-registry-directory-${{ hashFiles('Cargo.lock') }}-v1
|
key: rust-${{ env.TARGET }}-cargo-registry-directory-${{ hashFiles('Cargo.lock') }}-v1
|
||||||
|
|
||||||
- name: Run test ${{ matrix.test_name }}
|
- name: Run test ${{ matrix.test_name }}
|
||||||
run: cargo test --package swap --all-features --test ${{ matrix.test_name }} ""
|
run: cargo test --package swap --all-features --lib tests::${{ matrix.test_name }} ""
|
||||||
env:
|
env:
|
||||||
MONERO_ADDITIONAL_SLEEP_PERIOD: 60000
|
MONERO_ADDITIONAL_SLEEP_PERIOD: 60000
|
||||||
RUST_MIN_STACK: 16777216 # 16 MB. Default is 8MB. This is fine as in tests we start 2 programs: Alice and Bob.
|
RUST_MIN_STACK: 16777216 # 16 MB. Default is 8MB. This is fine as in tests we start 2 programs: Alice and Bob.
|
||||||
|
|
|
@ -40,6 +40,7 @@ sled = "0.34"
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
strum = { version = "0.20", features = ["derive"] }
|
strum = { version = "0.20", features = ["derive"] }
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
testcontainers = { version = "0.11", optional = true }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
time = "0.2"
|
time = "0.2"
|
||||||
tokio = { version = "1.0", features = ["rt-multi-thread", "time", "macros", "sync"] }
|
tokio = { version = "1.0", features = ["rt-multi-thread", "time", "macros", "sync"] }
|
||||||
|
@ -59,4 +60,6 @@ port_check = "0.1"
|
||||||
serde_cbor = "0.11"
|
serde_cbor = "0.11"
|
||||||
spectral = "0.6"
|
spectral = "0.6"
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
testcontainers = "0.11"
|
|
||||||
|
[features]
|
||||||
|
default = [ ]
|
||||||
|
|
|
@ -27,3 +27,6 @@ pub mod trace;
|
||||||
|
|
||||||
mod fs;
|
mod fs;
|
||||||
mod serde_peer_id;
|
mod serde_peer_id;
|
||||||
|
|
||||||
|
#[cfg(all(test, feature = "testcontainers"))]
|
||||||
|
mod tests;
|
||||||
|
|
|
@ -37,6 +37,8 @@ pub mod trace;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod fs;
|
mod fs;
|
||||||
mod serde_peer_id;
|
mod serde_peer_id;
|
||||||
|
#[cfg(all(test, feature = "testcontainers"))]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate prettytable;
|
extern crate prettytable;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
protocol::{alice, bob},
|
||||||
use swap::protocol::{alice, bob};
|
tests::testutils,
|
||||||
|
};
|
||||||
use testutils::SlowCancelConfig;
|
use testutils::SlowCancelConfig;
|
||||||
use tokio::join;
|
use tokio::join;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
protocol::{alice, alice::AliceState, bob},
|
||||||
use swap::protocol::{alice, alice::AliceState, bob};
|
tests::testutils,
|
||||||
|
};
|
||||||
use testutils::{alice_run_until::is_encsig_learned, SlowCancelConfig};
|
use testutils::{alice_run_until::is_encsig_learned, SlowCancelConfig};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
protocol::{alice, bob, bob::BobState},
|
||||||
use swap::protocol::{alice, bob, bob::BobState};
|
tests::testutils,
|
||||||
|
};
|
||||||
use testutils::{bob_run_until::is_encsig_sent, SlowCancelConfig};
|
use testutils::{bob_run_until::is_encsig_sent, SlowCancelConfig};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
protocol::{alice, bob, bob::BobState},
|
||||||
use swap::protocol::{alice, bob, bob::BobState};
|
tests::testutils,
|
||||||
|
};
|
||||||
use testutils::{bob_run_until::is_lock_proof_received, SlowCancelConfig};
|
use testutils::{bob_run_until::is_lock_proof_received, SlowCancelConfig};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
protocol::{alice, bob, bob::BobState},
|
||||||
use swap::protocol::{alice, bob, bob::BobState};
|
tests::testutils,
|
||||||
|
};
|
||||||
use testutils::{bob_run_until::is_xmr_locked, SlowCancelConfig};
|
use testutils::{bob_run_until::is_xmr_locked, SlowCancelConfig};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
9
swap/src/tests/mod.rs
Normal file
9
swap/src/tests/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
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;
|
||||||
|
pub mod testutils;
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
protocol::{alice, bob, bob::BobState},
|
||||||
use swap::protocol::{alice, bob, bob::BobState};
|
tests::testutils,
|
||||||
|
};
|
||||||
use testutils::{bob_run_until::is_btc_locked, FastPunishConfig};
|
use testutils::{bob_run_until::is_btc_locked, 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
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
protocol::{alice, alice::AliceState, bob},
|
||||||
use swap::protocol::{alice, alice::AliceState, bob};
|
tests::testutils,
|
||||||
|
};
|
||||||
use testutils::{alice_run_until::is_xmr_locked, FastCancelConfig};
|
use testutils::{alice_run_until::is_xmr_locked, FastCancelConfig};
|
||||||
|
|
||||||
/// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice
|
/// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice
|
|
@ -1,8 +1,7 @@
|
||||||
pub mod testutils;
|
use crate::{
|
||||||
|
|
||||||
use swap::{
|
|
||||||
config,
|
config,
|
||||||
protocol::{alice, alice::AliceState, bob},
|
protocol::{alice, alice::AliceState, bob},
|
||||||
|
tests::testutils,
|
||||||
};
|
};
|
||||||
use testutils::alice_run_until::is_encsig_learned;
|
use testutils::alice_run_until::is_encsig_learned;
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
use crate::testutils;
|
use crate::{
|
||||||
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::{
|
|
||||||
bitcoin,
|
bitcoin,
|
||||||
bitcoin::Timelock,
|
bitcoin::Timelock,
|
||||||
config,
|
config,
|
||||||
|
@ -13,7 +6,14 @@ use swap::{
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, alice::AliceState, bob, bob::BobState, SwapAmounts},
|
protocol::{alice, alice::AliceState, bob, bob::BobState, SwapAmounts},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
|
tests::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 tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use testcontainers::{clients::Cli, Container};
|
use testcontainers::{clients::Cli, Container};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
@ -415,13 +415,13 @@ async fn init_wallets(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let xmr_wallet = Arc::new(swap::monero::Wallet {
|
let xmr_wallet = Arc::new(crate::monero::Wallet {
|
||||||
inner: monero.wallet(name).unwrap().client(),
|
inner: monero.wallet(name).unwrap().client(),
|
||||||
network: config.monero_network,
|
network: config.monero_network,
|
||||||
});
|
});
|
||||||
|
|
||||||
let btc_wallet = Arc::new(
|
let btc_wallet = Arc::new(
|
||||||
swap::bitcoin::Wallet::new(name, bitcoind.node_url.clone(), config.bitcoin_network)
|
crate::bitcoin::Wallet::new(name, bitcoind.node_url.clone(), config.bitcoin_network)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
|
@ -478,7 +478,7 @@ fn init_tracing() -> DefaultGuard {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod alice_run_until {
|
pub mod alice_run_until {
|
||||||
use swap::protocol::alice::AliceState;
|
use crate::protocol::alice::AliceState;
|
||||||
|
|
||||||
pub fn is_xmr_locked(state: &AliceState) -> bool {
|
pub fn is_xmr_locked(state: &AliceState) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
|
@ -496,7 +496,7 @@ pub mod alice_run_until {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod bob_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 {
|
pub fn is_btc_locked(state: &BobState) -> bool {
|
||||||
matches!(state, BobState::BtcLocked(..))
|
matches!(state, BobState::BtcLocked(..))
|
Loading…
Add table
Add a link
Reference in a new issue