Replace hard coded port by dynamic available one

Fixes #84.
This commit is contained in:
Franck Royer 2020-12-18 11:54:13 +11:00
parent 2212758d17
commit 638143a10d
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
7 changed files with 30 additions and 18 deletions

7
Cargo.lock generated
View File

@ -1151,6 +1151,12 @@ dependencies = [
"version_check",
]
[[package]]
name = "get-port"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac6c41a39c60ae1fc5bf0e220347ce90fa1e4bb0fcdac65b09bb5f4576bebc84"
[[package]]
name = "get_if_addrs"
version = "0.5.2"
@ -3312,6 +3318,7 @@ dependencies = [
"ecdsa_fun",
"futures",
"genawaiter",
"get-port",
"hyper",
"libp2p",
"libp2p-tokio-socks5",

View File

@ -48,6 +48,7 @@ void = "1"
xmr-btc = { path = "../xmr-btc" }
[dev-dependencies]
get-port = "3"
hyper = "0.13"
port_check = "0.1"
spectral = "0.6"

View File

@ -1,5 +1,6 @@
use crate::testutils::{init_alice, init_bob};
use futures::future::try_join;
use get_port::get_port;
use libp2p::Multiaddr;
use rand::rngs::OsRng;
use swap::{alice, bob};
@ -35,8 +36,8 @@ async fn happy_path() {
let xmr_alice = xmr_to_swap * 10;
let xmr_bob = xmr_btc::monero::Amount::ZERO;
// todo: This should not be hardcoded
let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9876"
let port = get_port().expect("Failed to find a free port");
let alice_multiaddr: Multiaddr = format!("/ip4/127.0.0.1/tcp/{}", port)
.parse()
.expect("failed to parse Alice's address");

View File

@ -1,17 +1,17 @@
use crate::testutils::{init_alice, init_bob};
use get_port::get_port;
use libp2p::Multiaddr;
use rand::rngs::OsRng;
use std::convert::TryFrom;
use swap::{alice, alice::swap::AliceState, bitcoin, bob, storage::Database};
use tempfile::tempdir;
use testcontainers::clients::Cli;
use testutils::init_tracing;
use uuid::Uuid;
use xmr_btc::config::Config;
pub mod testutils;
use crate::testutils::{init_alice, init_bob};
use std::convert::TryFrom;
use testutils::init_tracing;
#[tokio::test]
async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
let _guard = init_tracing();
@ -31,7 +31,8 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
let bob_btc_starting_balance = btc_to_swap * 10;
let alice_xmr_starting_balance = xmr_to_swap * 10;
let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9877"
let port = get_port().expect("Failed to find a free port");
let alice_multiaddr: Multiaddr = format!("/ip4/127.0.0.1/tcp/{}", port)
.parse()
.expect("failed to parse Alice's address");

View File

@ -1,18 +1,17 @@
use crate::testutils::{init_alice, init_bob};
use get_port::get_port;
use libp2p::Multiaddr;
use rand::rngs::OsRng;
use swap::{alice, bitcoin, bob, storage::Database};
use std::convert::TryFrom;
use swap::{alice, bitcoin, bob, bob::swap::BobState, storage::Database};
use tempfile::tempdir;
use testcontainers::clients::Cli;
use testutils::init_tracing;
use uuid::Uuid;
use xmr_btc::config::Config;
pub mod testutils;
use crate::testutils::{init_alice, init_bob};
use std::convert::TryFrom;
use swap::bob::swap::BobState;
use testutils::init_tracing;
#[tokio::test]
async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
let _guard = init_tracing();
@ -32,7 +31,8 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
let bob_btc_starting_balance = btc_to_swap * 10;
let alice_xmr_starting_balance = xmr_to_swap * 10;
let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9877"
let port = get_port().expect("Failed to find a free port");
let alice_multiaddr: Multiaddr = format!("/ip4/127.0.0.1/tcp/{}", port)
.parse()
.expect("failed to parse Alice's address");

View File

@ -1,5 +1,6 @@
use crate::testutils::{init_alice, init_bob};
use futures::future::try_join;
use get_port::get_port;
use libp2p::Multiaddr;
use rand::rngs::OsRng;
use swap::{alice, alice::swap::AliceState, bob, bob::swap::BobState};
@ -33,8 +34,8 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
let alice_btc_starting_balance = bitcoin::Amount::ZERO;
let alice_xmr_starting_balance = xmr_to_swap * 10;
// todo: This should not be hardcoded
let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9877"
let port = get_port().expect("Failed to find a free port");
let alice_multiaddr: Multiaddr = format!("/ip4/127.0.0.1/tcp/{}", port)
.parse()
.expect("failed to parse Alice's address");

View File

@ -1,5 +1,6 @@
use crate::testutils::{init_alice, init_bob};
use futures::future::try_join;
use get_port::get_port;
use libp2p::Multiaddr;
use rand::rngs::OsRng;
use swap::{alice, alice::swap::AliceState, bob, bob::swap::BobState, storage::Database};
@ -35,8 +36,8 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
let alice_btc_starting_balance = bitcoin::Amount::ZERO;
let alice_xmr_starting_balance = xmr_to_swap * 10;
// todo: This should not be hardcoded
let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9879"
let port = get_port().expect("Failed to find a free port");
let alice_multiaddr: Multiaddr = format!("/ip4/127.0.0.1/tcp/{}", port)
.parse()
.expect("failed to parse Alice's address");