- Introduce Test abstraction instead of tow harnesses, move test specific data into Test - Change the abstraction from actors to swap, because we are creating swaps, not actors - rename actor::swap to run, because we are running a swappull/147/head
parent
e4795fa4ee
commit
8bf467b550
@ -1,58 +1,30 @@
|
||||
use rand::rngs::OsRng;
|
||||
use swap::protocol::{alice, alice::AliceState, bob};
|
||||
|
||||
pub mod testutils;
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
||||
testutils::test(|alice_harness, bob_harness| async move {
|
||||
let alice = alice_harness.new_alice().await;
|
||||
let bob = bob_harness.new_bob().await;
|
||||
|
||||
let bob_swap = bob::swap(
|
||||
bob.state,
|
||||
bob.event_loop_handle,
|
||||
bob.db,
|
||||
bob.bitcoin_wallet.clone(),
|
||||
bob.monero_wallet.clone(),
|
||||
OsRng,
|
||||
bob.swap_id,
|
||||
);
|
||||
let bob_swap_handle = tokio::spawn(bob_swap);
|
||||
|
||||
let alice_state = alice::run_until(
|
||||
alice.state,
|
||||
alice::swap::is_encsig_learned,
|
||||
alice.event_loop_handle,
|
||||
alice.bitcoin_wallet.clone(),
|
||||
alice.monero_wallet.clone(),
|
||||
alice.config,
|
||||
alice.swap_id,
|
||||
alice.db,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
testutils::init(|test| async move {
|
||||
let alice_swap = test.new_swap_as_alice().await;
|
||||
let bob_swap = test.new_swap_as_bob().await;
|
||||
|
||||
let bob = bob::run(bob_swap);
|
||||
let bob_handle = tokio::spawn(bob);
|
||||
|
||||
let alice_state = alice::run_until(alice_swap, alice::swap::is_encsig_learned)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(matches!(alice_state, AliceState::EncSigLearned {..}));
|
||||
|
||||
let alice = alice_harness.recover_alice_from_db().await;
|
||||
assert!(matches!(alice.state, AliceState::EncSigLearned {..}));
|
||||
|
||||
let alice_state = alice::swap(
|
||||
alice.state,
|
||||
alice.event_loop_handle,
|
||||
alice.bitcoin_wallet.clone(),
|
||||
alice.monero_wallet.clone(),
|
||||
alice.config,
|
||||
alice.swap_id,
|
||||
alice.db,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
alice_harness.assert_redeemed(alice_state).await;
|
||||
|
||||
let bob_state = bob_swap_handle.await.unwrap();
|
||||
bob_harness.assert_redeemed(bob_state.unwrap()).await
|
||||
let alice_swap = test.recover_alice_from_db().await;
|
||||
assert!(matches!(alice_swap.state, AliceState::EncSigLearned {..}));
|
||||
|
||||
let alice_state = alice::run(alice_swap).await.unwrap();
|
||||
|
||||
test.assert_alice_redeemed(alice_state).await;
|
||||
|
||||
let bob_state = bob_handle.await.unwrap();
|
||||
test.assert_bob_redeemed(bob_state.unwrap()).await
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -1,59 +1,31 @@
|
||||
use rand::rngs::OsRng;
|
||||
use swap::protocol::{alice, bob, bob::BobState};
|
||||
|
||||
pub mod testutils;
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
||||
testutils::test(|alice_harness, bob_harness| async move {
|
||||
let alice = alice_harness.new_alice().await;
|
||||
let bob = bob_harness.new_bob().await;
|
||||
|
||||
let alice_swap = alice::swap(
|
||||
alice.state,
|
||||
alice.event_loop_handle,
|
||||
alice.bitcoin_wallet.clone(),
|
||||
alice.monero_wallet.clone(),
|
||||
alice.config,
|
||||
alice.swap_id,
|
||||
alice.db,
|
||||
);
|
||||
let alice_swap_handle = tokio::spawn(alice_swap);
|
||||
|
||||
let bob_state = bob::run_until(
|
||||
bob.state,
|
||||
bob::swap::is_encsig_sent,
|
||||
bob.event_loop_handle,
|
||||
bob.db,
|
||||
bob.bitcoin_wallet.clone(),
|
||||
bob.monero_wallet.clone(),
|
||||
OsRng,
|
||||
bob.swap_id,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
testutils::init(|test| async move {
|
||||
let alice_swap = test.new_swap_as_alice().await;
|
||||
let bob_swap = test.new_swap_as_bob().await;
|
||||
|
||||
let alice = alice::run(alice_swap);
|
||||
let alice_handle = tokio::spawn(alice);
|
||||
|
||||
let bob_state = bob::run_until(bob_swap, bob::swap::is_encsig_sent)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(matches!(bob_state, BobState::EncSigSent {..}));
|
||||
|
||||
let bob = bob_harness.recover_bob_from_db().await;
|
||||
assert!(matches!(bob.state, BobState::EncSigSent {..}));
|
||||
|
||||
let bob_state = bob::swap(
|
||||
bob.state,
|
||||
bob.event_loop_handle,
|
||||
bob.db,
|
||||
bob.bitcoin_wallet.clone(),
|
||||
bob.monero_wallet.clone(),
|
||||
OsRng,
|
||||
bob.swap_id,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
bob_harness.assert_redeemed(bob_state).await;
|
||||
|
||||
let alice_state = alice_swap_handle.await.unwrap();
|
||||
alice_harness.assert_redeemed(alice_state.unwrap()).await;
|
||||
let bob_swap = test.recover_bob_from_db().await;
|
||||
assert!(matches!(bob_swap.state, BobState::EncSigSent {..}));
|
||||
|
||||
let bob_state = bob::run(bob_swap).await.unwrap();
|
||||
|
||||
test.assert_bob_redeemed(bob_state).await;
|
||||
|
||||
let alice_state = alice_handle.await.unwrap();
|
||||
test.assert_alice_redeemed(alice_state.unwrap()).await;
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -1,59 +1,32 @@
|
||||
use rand::rngs::OsRng;
|
||||
use swap::protocol::{alice, bob, bob::BobState};
|
||||
use swap::protocol::{
|
||||
alice, bob,
|
||||
bob::{swap::is_xmr_locked, BobState},
|
||||
};
|
||||
|
||||
pub mod testutils;
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
||||
testutils::test(|alice_harness, bob_harness| async move {
|
||||
let alice = alice_harness.new_alice().await;
|
||||
let bob = bob_harness.new_bob().await;
|
||||
|
||||
let alice_swap = alice::swap(
|
||||
alice.state,
|
||||
alice.event_loop_handle,
|
||||
alice.bitcoin_wallet.clone(),
|
||||
alice.monero_wallet.clone(),
|
||||
alice.config,
|
||||
alice.swap_id,
|
||||
alice.db,
|
||||
);
|
||||
let alice_swap_handle = tokio::spawn(alice_swap);
|
||||
|
||||
let bob_state = bob::run_until(
|
||||
bob.state,
|
||||
bob::swap::is_xmr_locked,
|
||||
bob.event_loop_handle,
|
||||
bob.db,
|
||||
bob.bitcoin_wallet.clone(),
|
||||
bob.monero_wallet.clone(),
|
||||
OsRng,
|
||||
bob.swap_id,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
testutils::init(|test| async move {
|
||||
let alice_swap = test.new_swap_as_alice().await;
|
||||
let bob_swap = test.new_swap_as_bob().await;
|
||||
|
||||
let alice_handle = alice::run(alice_swap);
|
||||
let alice_swap_handle = tokio::spawn(alice_handle);
|
||||
|
||||
let bob_state = bob::run_until(bob_swap, is_xmr_locked).await.unwrap();
|
||||
|
||||
assert!(matches!(bob_state, BobState::XmrLocked {..}));
|
||||
|
||||
let bob = bob_harness.recover_bob_from_db().await;
|
||||
assert!(matches!(bob.state, BobState::XmrLocked {..}));
|
||||
let bob_swap = test.recover_bob_from_db().await;
|
||||
assert!(matches!(bob_swap.state, BobState::XmrLocked {..}));
|
||||
|
||||
let bob_state = bob::swap(
|
||||
bob.state,
|
||||
bob.event_loop_handle,
|
||||
bob.db,
|
||||
bob.bitcoin_wallet.clone(),
|
||||
bob.monero_wallet.clone(),
|
||||
OsRng,
|
||||
bob.swap_id,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let bob_state = bob::run(bob_swap).await.unwrap();
|
||||
|
||||
bob_harness.assert_redeemed(bob_state).await;
|
||||
test.assert_bob_redeemed(bob_state).await;
|
||||
|
||||
let alice_state = alice_swap_handle.await.unwrap();
|
||||
alice_harness.assert_redeemed(alice_state.unwrap()).await;
|
||||
test.assert_alice_redeemed(alice_state.unwrap()).await;
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
Loading…
Reference in new issue