mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-09-27 20:05:58 +00:00
Add Tor feature flag and only run test if enabled
This commit is contained in:
parent
5e19949d71
commit
295216a8ee
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -46,6 +46,9 @@ jobs:
|
|||||||
build_test:
|
build_test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Install tor
|
||||||
|
run: sudo apt-get tor
|
||||||
|
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ serde_json = "1"
|
|||||||
sha2 = "0.9"
|
sha2 = "0.9"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
tokio = { version = "0.2", default-features = false, features = ["blocking", "macros", "rt-core", "time", "rt-threaded"] }
|
tokio = { version = "0.2", default-features = false, features = ["blocking", "macros", "rt-core", "time", "rt-threaded"] }
|
||||||
torut = "0.1"
|
torut = { version = "0.1", optional = true }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
@ -35,3 +35,7 @@ spectral = "0.6"
|
|||||||
testcontainers = "0.10"
|
testcontainers = "0.10"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.2"
|
tracing-subscriber = "0.2"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
tor = ["torut"]
|
||||||
|
@ -49,5 +49,6 @@ pub mod alice;
|
|||||||
pub mod bitcoin;
|
pub mod bitcoin;
|
||||||
pub mod bob;
|
pub mod bob;
|
||||||
pub mod monero;
|
pub mod monero;
|
||||||
|
#[cfg(feature = "tor")]
|
||||||
pub mod tor;
|
pub mod tor;
|
||||||
pub mod transport;
|
pub mod transport;
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
use anyhow::Result;
|
#[cfg(feature = "tor")]
|
||||||
use hyper::service::{make_service_fn, service_fn};
|
mod tor_test {
|
||||||
use reqwest::StatusCode;
|
|
||||||
use spectral::prelude::*;
|
|
||||||
use std::convert::Infallible;
|
|
||||||
use tokio::sync::oneshot::Receiver;
|
|
||||||
use torut::onion::TorSecretKeyV3;
|
|
||||||
use xmr_btc::tor::{AuthenticatedConnection, TOR_PROXY_ADDR};
|
|
||||||
|
|
||||||
async fn hello_world(
|
use anyhow::Result;
|
||||||
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
use spectral::prelude::*;
|
||||||
|
use std::convert::Infallible;
|
||||||
|
use tokio::sync::oneshot::Receiver;
|
||||||
|
use torut::onion::TorSecretKeyV3;
|
||||||
|
use xmr_btc::tor::{AuthenticatedConnection, TOR_PROXY_ADDR};
|
||||||
|
|
||||||
|
async fn hello_world(
|
||||||
_req: hyper::Request<hyper::Body>,
|
_req: hyper::Request<hyper::Body>,
|
||||||
) -> Result<hyper::Response<hyper::Body>, Infallible> {
|
) -> Result<hyper::Response<hyper::Body>, Infallible> {
|
||||||
Ok(hyper::Response::new("Hello World".into()))
|
Ok(hyper::Response::new("Hello World".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_test_service(port: u16, rx: Receiver<()>) {
|
fn start_test_service(port: u16, rx: Receiver<()>) {
|
||||||
let make_svc = make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(hello_world)) });
|
let make_svc =
|
||||||
|
make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(hello_world)) });
|
||||||
let addr = ([127, 0, 0, 1], port).into();
|
let addr = ([127, 0, 0, 1], port).into();
|
||||||
let server = hyper::Server::bind(&addr).serve(make_svc);
|
let server = hyper::Server::bind(&addr).serve(make_svc);
|
||||||
let graceful = server.with_graceful_shutdown(async {
|
let graceful = server.with_graceful_shutdown(async {
|
||||||
@ -26,10 +30,10 @@ fn start_test_service(port: u16, rx: Receiver<()>) {
|
|||||||
eprintln!("server error: {}", e);
|
eprintln!("server error: {}", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_tor_control_port() -> Result<()> {
|
async fn test_tor_control_port() -> Result<()> {
|
||||||
// Setup test HTTP Server
|
// Setup test HTTP Server
|
||||||
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
|
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
|
||||||
let port = 8080;
|
let port = 8080;
|
||||||
@ -61,4 +65,5 @@ async fn test_tor_control_port() -> Result<()> {
|
|||||||
// gracefully shut down server
|
// gracefully shut down server
|
||||||
let _ = tx.send(());
|
let _ = tx.send(());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user