mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-23 13:51:08 -05:00
Add test for cancel/refund before timelock expired
This commit is contained in:
parent
2d5d70d856
commit
02f8eb7f18
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -135,6 +135,7 @@ jobs:
|
||||
refund_restart_alice_cancelled,
|
||||
refund_restart_alice,
|
||||
bob_refunds_using_cancel_and_refund_command,
|
||||
bob_refunds_using_cancel_and_refund_command_timelock_not_exired,
|
||||
]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
@ -0,0 +1,56 @@
|
||||
pub mod testutils;
|
||||
|
||||
use bob::cancel::CancelError;
|
||||
use swap::protocol::{alice, bob, bob::BobState};
|
||||
use testutils::{bob_run_until::is_btc_locked, SlowCancelConfig};
|
||||
|
||||
#[tokio::test]
|
||||
async fn given_bob_manually_cancels_when_timelock_not_expired_errors() {
|
||||
testutils::setup_test(SlowCancelConfig, |mut ctx| async move {
|
||||
let (alice_swap, _) = ctx.new_swap_as_alice().await;
|
||||
let (bob_swap, bob_join_handle) = ctx.new_swap_as_bob().await;
|
||||
|
||||
let alice_handle = alice::run(alice_swap);
|
||||
tokio::spawn(alice_handle);
|
||||
|
||||
let bob_state = bob::run_until(bob_swap, is_btc_locked).await.unwrap();
|
||||
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 manually cancels
|
||||
let result = bob::cancel(
|
||||
bob_swap.swap_id,
|
||||
bob_swap.state,
|
||||
bob_swap.bitcoin_wallet,
|
||||
bob_swap.db,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.err()
|
||||
.unwrap();
|
||||
|
||||
assert!(matches!(result, CancelError::CancelTimelockNotExpiredYet));
|
||||
|
||||
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 manually refunds
|
||||
bob::refund(
|
||||
bob_swap.swap_id,
|
||||
bob_swap.state,
|
||||
bob_swap.execution_params,
|
||||
bob_swap.bitcoin_wallet,
|
||||
bob_swap.db,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.err()
|
||||
.unwrap();
|
||||
|
||||
let (bob_swap, _) = ctx.stop_and_resume_bob_from_db(bob_join_handle).await;
|
||||
assert!(matches!(bob_swap.state, BobState::BtcLocked {..}));
|
||||
})
|
||||
.await;
|
||||
}
|
Loading…
Reference in New Issue
Block a user