mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-03-01 11:11:14 -05:00
Move test functions out of lib
This commit is contained in:
parent
61a8a3e428
commit
bf576bf251
@ -88,19 +88,6 @@ pub enum State {
|
|||||||
State6(State6),
|
State6(State6),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use macro or generics
|
|
||||||
pub fn is_state4(state: &State) -> bool {
|
|
||||||
matches!(state, State::State4 { .. })
|
|
||||||
}
|
|
||||||
// TODO: use macro or generics
|
|
||||||
pub fn is_state5(state: &State) -> bool {
|
|
||||||
matches!(state, State::State5 { .. })
|
|
||||||
}
|
|
||||||
// TODO: use macro or generics
|
|
||||||
pub fn is_state6(state: &State) -> bool {
|
|
||||||
matches!(state, State::State6 { .. })
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! impl_try_from_parent_state {
|
macro_rules! impl_try_from_parent_state {
|
||||||
($type:ident) => {
|
($type:ident) => {
|
||||||
impl TryFrom<State> for $type {
|
impl TryFrom<State> for $type {
|
||||||
|
@ -124,16 +124,6 @@ impl_from_child_state!(State3);
|
|||||||
impl_from_child_state!(State4);
|
impl_from_child_state!(State4);
|
||||||
impl_from_child_state!(State5);
|
impl_from_child_state!(State5);
|
||||||
|
|
||||||
// TODO: use macro or generics
|
|
||||||
pub fn is_state5(state: &State) -> bool {
|
|
||||||
matches!(state, State::State5 { .. })
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: use macro or generics
|
|
||||||
pub fn is_state3(state: &State) -> bool {
|
|
||||||
matches!(state, State::State3 { .. })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct State0 {
|
pub struct State0 {
|
||||||
b: bitcoin::SecretKey,
|
b: bitcoin::SecretKey,
|
||||||
|
@ -144,16 +144,15 @@ pub async fn init_test<'a>(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
|
harness,
|
||||||
harness::node::{run_alice_until, run_bob_until},
|
harness::node::{run_alice_until, run_bob_until},
|
||||||
init_bitcoind, init_test,
|
init_bitcoind, init_test,
|
||||||
};
|
};
|
||||||
|
use futures::future;
|
||||||
use monero_harness::Monero;
|
use monero_harness::Monero;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
|
|
||||||
use futures::future;
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
use testcontainers::clients::Cli;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
use xmr_btc::{
|
use xmr_btc::{
|
||||||
alice, bitcoin,
|
alice, bitcoin,
|
||||||
@ -184,10 +183,15 @@ mod tests {
|
|||||||
run_alice_until(
|
run_alice_until(
|
||||||
&mut alice_node,
|
&mut alice_node,
|
||||||
alice_state0.into(),
|
alice_state0.into(),
|
||||||
alice::is_state6,
|
harness::alice::is_state6,
|
||||||
|
&mut OsRng,
|
||||||
|
),
|
||||||
|
run_bob_until(
|
||||||
|
&mut bob_node,
|
||||||
|
bob_state0.into(),
|
||||||
|
harness::bob::is_state5,
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
),
|
),
|
||||||
run_bob_until(&mut bob_node, bob_state0.into(), bob::is_state5, &mut OsRng),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -265,10 +269,15 @@ mod tests {
|
|||||||
run_alice_until(
|
run_alice_until(
|
||||||
&mut alice_node,
|
&mut alice_node,
|
||||||
alice_state0.into(),
|
alice_state0.into(),
|
||||||
alice::is_state5,
|
harness::alice::is_state5,
|
||||||
|
&mut OsRng,
|
||||||
|
),
|
||||||
|
run_bob_until(
|
||||||
|
&mut bob_node,
|
||||||
|
bob_state0.into(),
|
||||||
|
harness::bob::is_state3,
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
),
|
),
|
||||||
run_bob_until(&mut bob_node, bob_state0.into(), bob::is_state3, &mut OsRng),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -346,10 +355,15 @@ mod tests {
|
|||||||
run_alice_until(
|
run_alice_until(
|
||||||
&mut alice_node,
|
&mut alice_node,
|
||||||
alice_state0.into(),
|
alice_state0.into(),
|
||||||
alice::is_state4,
|
harness::alice::is_state4,
|
||||||
|
&mut OsRng,
|
||||||
|
),
|
||||||
|
run_bob_until(
|
||||||
|
&mut bob_node,
|
||||||
|
bob_state0.into(),
|
||||||
|
harness::bob::is_state3,
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
),
|
),
|
||||||
run_bob_until(&mut bob_node, bob_state0.into(), bob::is_state3, &mut OsRng),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1,3 +1,36 @@
|
|||||||
pub mod node;
|
pub mod node;
|
||||||
pub mod transport;
|
pub mod transport;
|
||||||
pub mod wallet;
|
pub mod wallet;
|
||||||
|
|
||||||
|
pub mod bob {
|
||||||
|
use xmr_btc::bob::State;
|
||||||
|
|
||||||
|
// TODO: use macro or generics
|
||||||
|
pub fn is_state5(state: &State) -> bool {
|
||||||
|
matches!(state, State::State5 { .. })
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use macro or generics
|
||||||
|
pub fn is_state3(state: &State) -> bool {
|
||||||
|
matches!(state, State::State3 { .. })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod alice {
|
||||||
|
use xmr_btc::alice::State;
|
||||||
|
|
||||||
|
// TODO: use macro or generics
|
||||||
|
pub fn is_state4(state: &State) -> bool {
|
||||||
|
matches!(state, State::State4 { .. })
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use macro or generics
|
||||||
|
pub fn is_state5(state: &State) -> bool {
|
||||||
|
matches!(state, State::State5 { .. })
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use macro or generics
|
||||||
|
pub fn is_state6(state: &State) -> bool {
|
||||||
|
matches!(state, State::State6 { .. })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user