2020-12-14 01:24:23 -05:00
|
|
|
use rand::rngs::OsRng;
|
2021-01-15 03:29:26 -05:00
|
|
|
use swap::protocol::{alice, bob};
|
2021-01-14 19:26:32 -05:00
|
|
|
use tokio::join;
|
2020-12-14 01:24:23 -05:00
|
|
|
|
|
|
|
pub mod testutils;
|
|
|
|
|
|
|
|
/// Run the following tests with RUST_MIN_STACK=10000000
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn happy_path() {
|
2021-01-15 03:29:26 -05:00
|
|
|
testutils::test(|alice_harness, bob_harness| async move {
|
2021-01-15 02:34:46 -05:00
|
|
|
let alice = alice_harness.new_alice().await;
|
2021-01-15 03:34:51 -05:00
|
|
|
let bob = bob_harness.new_bob().await;
|
|
|
|
|
|
|
|
let alice_swap = alice::swap(
|
2021-01-14 19:26:32 -05:00
|
|
|
alice.state,
|
|
|
|
alice.event_loop_handle,
|
2021-01-15 02:34:46 -05:00
|
|
|
alice.bitcoin_wallet.clone(),
|
|
|
|
alice.monero_wallet.clone(),
|
2021-01-14 19:26:32 -05:00
|
|
|
alice.config,
|
|
|
|
alice.swap_id,
|
|
|
|
alice.db,
|
|
|
|
);
|
2021-01-15 03:29:26 -05:00
|
|
|
|
2021-01-15 03:34:51 -05:00
|
|
|
let bob_swap = bob::swap(
|
2021-01-14 19:26:32 -05:00
|
|
|
bob.state,
|
|
|
|
bob.event_loop_handle,
|
|
|
|
bob.db,
|
|
|
|
bob.bitcoin_wallet.clone(),
|
|
|
|
bob.monero_wallet.clone(),
|
|
|
|
OsRng,
|
|
|
|
bob.swap_id,
|
|
|
|
);
|
2021-01-15 03:34:51 -05:00
|
|
|
let (alice_state, bob_state) = join!(alice_swap, bob_swap);
|
2021-01-14 19:26:32 -05:00
|
|
|
|
2021-01-15 02:34:46 -05:00
|
|
|
alice_harness.assert_redeemed(alice_state.unwrap()).await;
|
2021-01-15 03:29:26 -05:00
|
|
|
bob_harness.assert_redeemed(bob_state.unwrap()).await;
|
2021-01-14 19:26:32 -05:00
|
|
|
})
|
2020-12-14 01:24:23 -05:00
|
|
|
.await;
|
|
|
|
}
|