mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Merge #99
99: Cleanup resume_from_database functions only used in tests r=da-kami a=da-kami Follow up of https://github.com/comit-network/xmr-btc-swap/pull/88 Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
commit
3db71997d3
@ -233,29 +233,6 @@ pub async fn swap(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn resume_from_database(
|
|
||||||
event_loop_handle: EventLoopHandle,
|
|
||||||
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
|
||||||
monero_wallet: Arc<crate::monero::Wallet>,
|
|
||||||
config: Config,
|
|
||||||
swap_id: Uuid,
|
|
||||||
db: Database,
|
|
||||||
) -> Result<AliceState> {
|
|
||||||
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 {
|
pub fn is_complete(state: &AliceState) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
state,
|
state,
|
||||||
|
@ -127,32 +127,6 @@ where
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn resume_from_database<R>(
|
|
||||||
event_loop_handle: EventLoopHandle,
|
|
||||||
db: Database,
|
|
||||||
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
|
||||||
monero_wallet: Arc<crate::monero::Wallet>,
|
|
||||||
rng: R,
|
|
||||||
swap_id: Uuid,
|
|
||||||
) -> Result<BobState>
|
|
||||||
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 {
|
pub fn is_complete(state: &BobState) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
state,
|
state,
|
||||||
|
@ -9,6 +9,7 @@ use xmr_btc::config::Config;
|
|||||||
pub mod testutils;
|
pub mod testutils;
|
||||||
|
|
||||||
use crate::testutils::{init_alice, init_bob};
|
use crate::testutils::{init_alice, init_bob};
|
||||||
|
use std::convert::TryFrom;
|
||||||
use testutils::init_tracing;
|
use testutils::init_tracing;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -119,7 +120,11 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
|||||||
testutils::init_alice_event_loop(alice_multiaddr);
|
testutils::init_alice_event_loop(alice_multiaddr);
|
||||||
let _alice_swarm_fut = tokio::spawn(async move { event_loop_after_restart.run().await });
|
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,
|
event_loop_handle_after_restart,
|
||||||
alice_btc_wallet.clone(),
|
alice_btc_wallet.clone(),
|
||||||
alice_xmr_wallet.clone(),
|
alice_xmr_wallet.clone(),
|
||||||
|
@ -9,6 +9,7 @@ use xmr_btc::config::Config;
|
|||||||
pub mod testutils;
|
pub mod testutils;
|
||||||
|
|
||||||
use crate::testutils::{init_alice, init_bob};
|
use crate::testutils::{init_alice, init_bob};
|
||||||
|
use std::convert::TryFrom;
|
||||||
use swap::bob::swap::BobState;
|
use swap::bob::swap::BobState;
|
||||||
use testutils::init_tracing;
|
use testutils::init_tracing;
|
||||||
|
|
||||||
@ -122,9 +123,13 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
|||||||
|
|
||||||
let (event_loop_after_restart, event_loop_handle_after_restart) =
|
let (event_loop_after_restart, event_loop_handle_after_restart) =
|
||||||
testutils::init_bob_event_loop();
|
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,
|
event_loop_handle_after_restart,
|
||||||
bob_db,
|
bob_db,
|
||||||
bob_btc_wallet,
|
bob_btc_wallet,
|
||||||
@ -135,7 +140,7 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(matches!(alice_state, BobState::XmrRedeemed {..}));
|
assert!(matches!(bob_state, BobState::XmrRedeemed {..}));
|
||||||
|
|
||||||
let btc_alice_final = alice_btc_wallet_clone.as_ref().balance().await.unwrap();
|
let btc_alice_final = alice_btc_wallet_clone.as_ref().balance().await.unwrap();
|
||||||
let btc_bob_final = bob_btc_wallet_clone.as_ref().balance().await.unwrap();
|
let btc_bob_final = bob_btc_wallet_clone.as_ref().balance().await.unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user