From 773eebc723ae0bf8ee88f1e7bd75afaa8b9ad277 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Fri, 18 Dec 2020 10:50:32 +1100 Subject: [PATCH] Cleanup resume_from_database functions only used in tests --- swap/src/alice/swap.rs | 23 ----------------------- swap/src/bob/swap.rs | 26 -------------------------- swap/tests/happy_path_restart_alice.rs | 7 ++++++- swap/tests/happy_path_restart_bob.rs | 11 ++++++++--- 4 files changed, 14 insertions(+), 53 deletions(-) diff --git a/swap/src/alice/swap.rs b/swap/src/alice/swap.rs index 4ea3b8cb..0ba39d16 100644 --- a/swap/src/alice/swap.rs +++ b/swap/src/alice/swap.rs @@ -233,29 +233,6 @@ pub async fn swap( .await } -pub async fn resume_from_database( - event_loop_handle: EventLoopHandle, - bitcoin_wallet: Arc, - monero_wallet: Arc, - config: Config, - swap_id: Uuid, - db: Database, -) -> Result { - let db_swap = db.get_state(swap_id)?; - let start_state = AliceState::try_from(db_swap)?; - let state = swap( - start_state, - event_loop_handle, - bitcoin_wallet, - monero_wallet, - config, - swap_id, - db, - ) - .await?; - Ok(state) -} - pub fn is_complete(state: &AliceState) -> bool { matches!( state, diff --git a/swap/src/bob/swap.rs b/swap/src/bob/swap.rs index e9a9df77..dd0571de 100644 --- a/swap/src/bob/swap.rs +++ b/swap/src/bob/swap.rs @@ -122,32 +122,6 @@ where .await } -pub async fn resume_from_database( - event_loop_handle: EventLoopHandle, - db: Database, - bitcoin_wallet: Arc, - monero_wallet: Arc, - rng: R, - swap_id: Uuid, -) -> Result -where - R: RngCore + CryptoRng + Send, -{ - let db_swap = db.get_state(swap_id)?; - let start_state = BobState::try_from(db_swap)?; - let state = swap( - start_state, - event_loop_handle, - db, - bitcoin_wallet, - monero_wallet, - rng, - swap_id, - ) - .await?; - Ok(state) -} - pub fn is_complete(state: &BobState) -> bool { matches!( state, diff --git a/swap/tests/happy_path_restart_alice.rs b/swap/tests/happy_path_restart_alice.rs index 9e2e2f01..e2c4d0d2 100644 --- a/swap/tests/happy_path_restart_alice.rs +++ b/swap/tests/happy_path_restart_alice.rs @@ -9,6 +9,7 @@ use xmr_btc::config::Config; pub mod testutils; use crate::testutils::{init_alice, init_bob}; +use std::convert::TryFrom; use testutils::init_tracing; #[tokio::test] @@ -114,7 +115,11 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() { testutils::init_alice_event_loop(alice_multiaddr); let _alice_swarm_fut = tokio::spawn(async move { event_loop_after_restart.run().await }); - let alice_state = alice::swap::resume_from_database( + let db_swap = alice_db.get_state(alice_swap_id).unwrap(); + let resume_state = AliceState::try_from(db_swap).unwrap(); + + let alice_state = alice::swap::swap( + resume_state, event_loop_handle_after_restart, alice_btc_wallet, alice_xmr_wallet, diff --git a/swap/tests/happy_path_restart_bob.rs b/swap/tests/happy_path_restart_bob.rs index 79c4bcec..b6af415d 100644 --- a/swap/tests/happy_path_restart_bob.rs +++ b/swap/tests/happy_path_restart_bob.rs @@ -9,6 +9,7 @@ use xmr_btc::config::Config; pub mod testutils; use crate::testutils::{init_alice, init_bob}; +use std::convert::TryFrom; use swap::bob::swap::BobState; use testutils::init_tracing; @@ -112,9 +113,13 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() { let (event_loop_after_restart, event_loop_handle_after_restart) = testutils::init_bob_event_loop(); - let _alice_swarm_fut = tokio::spawn(async move { event_loop_after_restart.run().await }); + let _bob_swarm_fut = tokio::spawn(async move { event_loop_after_restart.run().await }); - let alice_state = bob::swap::resume_from_database( + let db_swap = bob_db.get_state(bob_swap_id).unwrap(); + let resume_state = BobState::try_from(db_swap).unwrap(); + + let bob_state = bob::swap::swap( + resume_state, event_loop_handle_after_restart, bob_db, bob_btc_wallet, @@ -125,7 +130,7 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() { .await .unwrap(); - assert!(matches!(alice_state, BobState::XmrRedeemed {..})); + assert!(matches!(bob_state, BobState::XmrRedeemed {..})); // TODO: Additionally assert balances }