diff --git a/xmr-btc/src/alice.rs b/xmr-btc/src/alice.rs index 169c3f81..8072f777 100644 --- a/xmr-btc/src/alice.rs +++ b/xmr-btc/src/alice.rs @@ -88,19 +88,6 @@ pub enum State { 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 { ($type:ident) => { impl TryFrom for $type { diff --git a/xmr-btc/src/bob.rs b/xmr-btc/src/bob.rs index 1a97f202..8b73bf70 100644 --- a/xmr-btc/src/bob.rs +++ b/xmr-btc/src/bob.rs @@ -124,16 +124,6 @@ impl_from_child_state!(State3); impl_from_child_state!(State4); 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)] pub struct State0 { b: bitcoin::SecretKey, diff --git a/xmr-btc/tests/e2e.rs b/xmr-btc/tests/e2e.rs index 5b91ac1f..f17f4d13 100644 --- a/xmr-btc/tests/e2e.rs +++ b/xmr-btc/tests/e2e.rs @@ -144,16 +144,15 @@ pub async fn init_test<'a>( #[cfg(test)] mod tests { use crate::{ + harness, harness::node::{run_alice_until, run_bob_until}, init_bitcoind, init_test, }; - + use futures::future; use monero_harness::Monero; use rand::rngs::OsRng; - use testcontainers::clients::Cli; - - use futures::future; use std::convert::TryInto; + use testcontainers::clients::Cli; use tracing_subscriber::util::SubscriberInitExt; use xmr_btc::{ alice, bitcoin, @@ -184,10 +183,15 @@ mod tests { run_alice_until( &mut alice_node, 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, ), - run_bob_until(&mut bob_node, bob_state0.into(), bob::is_state5, &mut OsRng), ) .await .unwrap(); @@ -265,10 +269,15 @@ mod tests { run_alice_until( &mut alice_node, 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, ), - run_bob_until(&mut bob_node, bob_state0.into(), bob::is_state3, &mut OsRng), ) .await .unwrap(); @@ -346,10 +355,15 @@ mod tests { run_alice_until( &mut alice_node, 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, ), - run_bob_until(&mut bob_node, bob_state0.into(), bob::is_state3, &mut OsRng), ) .await .unwrap(); diff --git a/xmr-btc/tests/harness/mod.rs b/xmr-btc/tests/harness/mod.rs index 38d3808a..4f2cba46 100644 --- a/xmr-btc/tests/harness/mod.rs +++ b/xmr-btc/tests/harness/mod.rs @@ -1,3 +1,36 @@ pub mod node; pub mod transport; 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 { .. }) + } +}