From a22efaa7bc6ad0b1a84457ec5f3782d0a7be8bbd Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 4 Dec 2020 16:04:24 +1100 Subject: [PATCH] Remove unneeded peer id argument --- swap/tests/alice_safe_restart.rs | 87 ++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/swap/tests/alice_safe_restart.rs b/swap/tests/alice_safe_restart.rs index 7957cfa3..37762823 100644 --- a/swap/tests/alice_safe_restart.rs +++ b/swap/tests/alice_safe_restart.rs @@ -116,44 +116,61 @@ async fn alice_safe_restart_after_btc_is_locked() { xmr: xmr_to_swap, }; - let (alice_swap, alice_peer_id) = { + let alice_swap = { let rng = &mut OsRng; - let alice_behaviour = alice::Behaviour::default(); - let alice_peer_id = alice_behaviour.peer_id(); - let alice_transport = build(alice_behaviour.identity()).unwrap(); - let alice_state = { + let (alice_state, alice_behaviour) = { let a = bitcoin::SecretKey::new_random(rng); let s_a = cross_curve_dleq::Scalar::random(rng); let v_a = xmr_btc::monero::PrivateViewKey::new_random(rng); - AliceState::Started { - amounts, + let redeem_address = alice_btc_wallet.as_ref().new_address().await.unwrap(); + let punish_address = redeem_address.clone(); + let state0 = xmr_btc::alice::State0::new( a, s_a, v_a, - } + amounts.btc, + amounts.xmr, + REFUND_TIMELOCK, + PUNISH_TIMELOCK, + redeem_address, + punish_address, + ); + + ( + AliceState::Started { + amounts, + state0: state0.clone(), + }, + alice::Behaviour::new(state0), + ) }; - let alice_swarm = - alice::new_swarm(alice_multiaddr.clone(), alice_transport, alice_behaviour).unwrap(); + let alice_transport = build(alice_behaviour.identity()).unwrap(); + let (mut alice_event_loop, alice_event_loop_handle) = alice::event_loop::EventLoop::new( + alice_transport, + alice_behaviour, + alice_multiaddr.clone(), + ) + .unwrap(); + + let _alice_swarm_fut = tokio::spawn(async move { alice_event_loop.run().await }); + let config = xmr_btc::config::Config::regtest(); let swap_id = Uuid::new_v4(); let tmp_dir = TempDir::new().unwrap(); let db = Database::open(tmp_dir.path()).unwrap(); - ( - alice::swap::swap( - alice_state, - alice_swarm, - alice_btc_wallet.clone(), - alice_xmr_wallet.clone(), - config, - swap_id, - db, - ), - alice_peer_id, + alice::swap::swap( + alice_state, + alice_event_loop_handle, + alice_btc_wallet.clone(), + alice_xmr_wallet.clone(), + config, + swap_id, + db, ) }; - let bob_swap = { + let (bob_swap, bob_event_loop) = { let rng = &mut OsRng; let bob_db_dir = tempdir().unwrap(); let bob_db = Database::open(bob_db_dir.path()).unwrap(); @@ -172,21 +189,27 @@ async fn alice_safe_restart_after_btc_is_locked() { let bob_state = BobState::Started { state0, amounts, - peer_id: alice_peer_id, addr: alice_multiaddr, }; - let bob_swarm = bob::new_swarm(bob_transport, bob_behaviour).unwrap(); - bob::swap::swap( - bob_state, - bob_swarm, - bob_db, - bob_btc_wallet.clone(), - bob_xmr_wallet.clone(), - OsRng, - Uuid::new_v4(), + let (bob_event_loop, bob_event_loop_handle) = + bob::event_loop::EventLoop::new(bob_transport, bob_behaviour).unwrap(); + + ( + bob::swap::swap( + bob_state, + bob_event_loop_handle, + bob_db, + bob_btc_wallet.clone(), + bob_xmr_wallet.clone(), + OsRng, + Uuid::new_v4(), + ), + bob_event_loop, ) }; + let _bob_event_loop = tokio::spawn(async move { bob_event_loop.run().await }); + try_join(alice_swap, bob_swap).await.unwrap(); let btc_alice_final = alice_btc_wallet.balance().await.unwrap();