Skip to content

Commit

Permalink
wip(ci): add new features to matrix and include ignored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oleonardolima committed Jan 15, 2024
1 parent 7f96586 commit 53c089b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 41 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- async-https-native
- async-https-rustls
- async-https-rustls-manual-roots
- async-arti-hyper
- async-arti-hyper-native
- async-arti-hyper-rustls
steps:
- uses: actions/checkout@v3
- name: Generate cache key
Expand Down Expand Up @@ -58,4 +61,4 @@ jobs:
if: ${{ matrix.rust.clippy }}
run: cargo clippy --all-targets --features ${{ matrix.features }} --no-default-features -- -D warnings
- name: Test
run: cargo test --features ${{ matrix.features }} --no-default-features
run: cargo test --features ${{ matrix.features }} --no-default-features -- --include-ignored
92 changes: 53 additions & 39 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
use std::collections::HashMap;
use std::str::FromStr;

use arti_client::{TorClient, TorClientConfig};

use arti_hyper::ArtiHttpConnector;

use bitcoin::consensus::{deserialize, serialize};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::{sha256, Hash};
Expand All @@ -26,26 +22,39 @@ use bitcoin::{
};
use bitcoin_internals::hex::display::DisplayHex;

use hyper::{Body, Response, Uri};
#[allow(unused_imports)]
use log::{debug, error, info, trace};

use reqwest::{Client, StatusCode};
use tls_api::{TlsConnector as TlsConnectorTrait, TlsConnectorBuilder};
#[cfg(feature = "async")]
use reqwest::Client;

#[cfg(feature = "async-arti-hyper")]
use {
arti_client::{TorClient, TorClientConfig},
arti_hyper::ArtiHttpConnector,
hyper::service::Service,
hyper::{Body, Request, Response, Uri},
tls_api::{TlsConnector as TlsConnectorTrait, TlsConnectorBuilder},
tor_rtcompat::PreferredRuntime,
};

#[cfg(feature = "async-arti-hyper")]
#[cfg(not(target_vendor = "apple"))]
use tls_api_native_tls::TlsConnector;
#[cfg(feature = "async-arti-hyper")]
#[cfg(target_vendor = "apple")]
use tls_api_openssl::TlsConnector;
use tor_rtcompat::PreferredRuntime;

use crate::{BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus};

#[cfg(feature = "async")]
#[derive(Debug, Clone)]
pub struct AsyncClient {
url: String,
client: Client,
}

#[cfg(feature = "async")]
impl AsyncClient {
/// build an async client from a builder
pub fn from_builder(builder: Builder) -> Result<Self, Error> {
Expand Down Expand Up @@ -77,7 +86,7 @@ impl AsyncClient {
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand Down Expand Up @@ -112,7 +121,7 @@ impl AsyncClient {
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand Down Expand Up @@ -198,7 +207,7 @@ impl AsyncClient {
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand All @@ -220,7 +229,7 @@ impl AsyncClient {
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand All @@ -242,7 +251,7 @@ impl AsyncClient {
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand All @@ -269,7 +278,7 @@ impl AsyncClient {
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand Down Expand Up @@ -346,7 +355,7 @@ impl AsyncClient {
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
return Err(Error::HeaderHeightNotFound(block_height));
}

Expand Down Expand Up @@ -441,12 +450,14 @@ impl AsyncClient {
}
}

#[cfg(feature = "async-arti-hyper")]
#[derive(Debug, Clone)]
pub struct AsyncAnonymizedClient {
url: String,
client: hyper::Client<ArtiHttpConnector<PreferredRuntime, TlsConnector>>,
}

#[cfg(feature = "async-arti-hyper")]
impl AsyncAnonymizedClient {
/// build an async [`TorClient`] with default Tor configuration
async fn create_tor_client() -> Result<TorClient<PreferredRuntime>, arti_client::Error> {
Expand Down Expand Up @@ -485,7 +496,7 @@ impl AsyncAnonymizedClient {

let resp = self.client.get(uri).await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let hyper::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand Down Expand Up @@ -521,7 +532,7 @@ impl AsyncAnonymizedClient {

let resp = self.client.get(uri).await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let hyper::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand Down Expand Up @@ -604,7 +615,7 @@ impl AsyncAnonymizedClient {
let uri = Uri::from_str(&path).map_err(|_| Error::InvalidUri)?;
let resp = self.client.get(uri).await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let hyper::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand All @@ -627,7 +638,7 @@ impl AsyncAnonymizedClient {

let resp = self.client.get(uri).await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let hyper::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand All @@ -652,7 +663,7 @@ impl AsyncAnonymizedClient {

let resp = self.client.get(uri).await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let hyper::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand All @@ -678,7 +689,7 @@ impl AsyncAnonymizedClient {
let uri = Uri::from_str(path).map_err(|_| Error::InvalidUri)?;
let resp = self.client.get(uri).await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let hyper::StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Expand All @@ -698,23 +709,26 @@ impl AsyncAnonymizedClient {
}

// /// Broadcast a [`Transaction`] to Esplora
// pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> {
// let resp = self
// .client
// .post(&format!("{}/tx", self.url))
// .body(serialize(transaction).to_lower_hex_string())
// .send()
// .await?;

// if resp.status().is_server_error() || resp.status().is_client_error() {
// Err(Error::HttpResponse {
// status: resp.status().as_u16(),
// message: resp.text().await?,
// })
// } else {
// Ok(())
// }
// }
pub async fn broadcast(&mut self, transaction: &Transaction) -> Result<(), Error> {
let path = &format!("{}/tx", self.url);
let uri = Uri::from_str(path).map_err(|_| Error::InvalidUri)?;

let body = Body::from(serialize(transaction).to_lower_hex_string());
let req = Request::post(uri)
.body(body)
.map_err(|_| Error::InvalidBody)?;

let resp = self.client.call(req).await?;

if resp.status().is_server_error() || resp.status().is_client_error() {
Err(Error::HttpResponse {
status: resp.status().as_u16(),
message: Self::text(resp).await?,
})
} else {
Ok(())
}
}

/// Get the current height of the blockchain tip
pub async fn get_height(&self) -> Result<u32, Error> {
Expand Down Expand Up @@ -761,7 +775,7 @@ impl AsyncAnonymizedClient {
let uri = Uri::from_str(path).map_err(|_| Error::InvalidUri)?;
let resp = self.client.get(uri).await?;

if let StatusCode::NOT_FOUND = resp.status() {
if let hyper::StatusCode::NOT_FOUND = resp.status() {
return Err(Error::HeaderHeightNotFound(block_height));
}

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use bitcoin::consensus;

pub mod api;

#[cfg(feature = "async")]
#[cfg(any(feature = "async", feature = "async-arti-hyper"))]
pub mod r#async;
#[cfg(feature = "blocking")]
pub mod blocking;
Expand Down Expand Up @@ -196,6 +196,9 @@ pub enum Error {
/// Error during hyper HTTP request
#[cfg(feature = "async-arti-hyper")]
InvalidUri,
/// Error during hyper HTTP request body creation
#[cfg(feature = "async-arti-hyper")]
InvalidBody,
/// Error during Tor client creation
#[cfg(feature = "async-arti-hyper")]
ArtiClient(::arti_client::Error),
Expand Down

0 comments on commit 53c089b

Please sign in to comment.