xmr-btc-swap/swap/tests/bob_refunds_using_cancel_and_refund_command_timelock_not_expired_force.rs
Thomas Eizinger b9d8cbeaa2
Rename testutils to harness
This allows us to bring in a dependency named `testutils`.
2021-03-30 12:59:34 +11:00

58 lines
1.8 KiB
Rust

pub mod harness;
use harness::bob_run_until::is_btc_locked;
use harness::SlowCancelConfig;
use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob};
#[tokio::test]
async fn given_bob_manually_forces_cancel_when_timelock_not_expired_errors() {
harness::setup_test(SlowCancelConfig, |mut ctx| async move {
let (bob_swap, bob_join_handle) = ctx.bob_swap().await;
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_btc_locked));
let alice_swap = ctx.alice_next_swap().await;
let _ = tokio::spawn(alice::run(alice_swap));
let bob_state = bob_swap.await??;
assert!(matches!(bob_state, BobState::BtcLocked { .. }));
let (bob_swap, bob_join_handle) = ctx.stop_and_resume_bob_from_db(bob_join_handle).await;
assert!(matches!(bob_swap.state, BobState::BtcLocked { .. }));
// Bob forces a cancel that will fail
let is_error = bob::cancel(
bob_swap.swap_id,
bob_swap.state,
bob_swap.bitcoin_wallet,
bob_swap.db,
true,
)
.await
.is_err();
assert!(is_error);
let (bob_swap, bob_join_handle) = ctx.stop_and_resume_bob_from_db(bob_join_handle).await;
assert!(matches!(bob_swap.state, BobState::BtcLocked { .. }));
// Bob forces a refund that will fail
let is_error = bob::refund(
bob_swap.swap_id,
bob_swap.state,
bob_swap.bitcoin_wallet,
bob_swap.db,
true,
)
.await
.is_err();
assert!(is_error);
let (bob_swap, _) = ctx.stop_and_resume_bob_from_db(bob_join_handle).await;
assert!(matches!(bob_swap.state, BobState::BtcLocked { .. }));
Ok(())
})
.await;
}