Skip to content

Commit f626bbb

Browse files
committed
add happy_path_alice_does_not_send_transfer_proof integration test
1 parent 67557d0 commit f626bbb

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ jobs:
180180
test_name: alice_empty_balance_after_started_btc_early_refund
181181
- package: swap
182182
test_name: alice_broken_wallet_rpc_after_started_btc_early_refund
183+
- package: swap
184+
test_name: happy_path_alice_does_not_send_transfer_proof
183185
- package: monero-tests
184186
test_name: reserve_proof
185187
- package: monero-tests
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
pub mod harness;
2+
3+
use harness::alice_run_until::is_xmr_lock_transaction_sent;
4+
use harness::bob_run_until::is_xmr_locked;
5+
use harness::SlowCancelConfig;
6+
use swap::asb::FixedRate;
7+
use swap::protocol::alice::AliceState;
8+
use swap::protocol::bob::BobState;
9+
use swap::protocol::{alice, bob};
10+
11+
/// Test that Bob can detect the Monero lock transaction using the view key
12+
/// even when Alice goes offline and doesn't send the transfer proof.
13+
#[tokio::test]
14+
async fn given_alice_goes_offline_after_xmr_locked_bob_detects_xmr_via_view_key() {
15+
harness::setup_test(SlowCancelConfig, None, |mut ctx| async move {
16+
// Bob runs until he detects the Monero as having been locked
17+
let (bob_swap, bob_join_handle) = ctx.bob_swap().await;
18+
let bob_swap_id = bob_swap.id;
19+
let bob_swap = tokio::spawn(bob::run_until(bob_swap, is_xmr_locked));
20+
21+
// Alice runs until the locks the Monero but before she sends the transfer proof
22+
let alice_swap = ctx.alice_next_swap().await;
23+
let alice_swap = tokio::spawn(alice::run_until(
24+
alice_swap,
25+
is_xmr_lock_transaction_sent,
26+
FixedRate::default(),
27+
));
28+
29+
// Assert that Alice is in correct state
30+
let alice_state = alice_swap.await??;
31+
assert!(matches!(
32+
alice_state,
33+
AliceState::XmrLockTransactionSent { .. }
34+
));
35+
36+
// Assert that Bob is in correct state
37+
let bob_state = bob_swap.await??;
38+
assert!(
39+
matches!(bob_state, BobState::XmrLocked(..)),
40+
"Bob should have detected XMR lock via view key, but state is: {:?}",
41+
bob_state
42+
);
43+
44+
// Resume the swap
45+
ctx.restart_alice().await;
46+
let alice_swap = ctx.alice_next_swap().await;
47+
let alice_swap = tokio::spawn(alice::run(alice_swap, FixedRate::default()));
48+
49+
let (bob_swap, _) = ctx
50+
.stop_and_resume_bob_from_db(bob_join_handle, bob_swap_id)
51+
.await;
52+
53+
// Run the swap to completion
54+
let bob_state = bob::run(bob_swap).await?;
55+
ctx.assert_bob_redeemed(bob_state).await;
56+
57+
let alice_state = alice_swap.await??;
58+
ctx.assert_alice_redeemed(alice_state).await;
59+
60+
Ok(())
61+
})
62+
.await;
63+
}

0 commit comments

Comments
 (0)