Skip to content

Commit fd945b0

Browse files
committed
ci: add new features to matrix and include ignored tests
1 parent 7d07d50 commit fd945b0

File tree

4 files changed

+63
-42
lines changed

4 files changed

+63
-42
lines changed

.github/workflows/cont_integration.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- async-https-native
2828
- async-https-rustls
2929
- async-https-rustls-manual-roots
30+
- async-arti-hyper
31+
- async-arti-hyper-native
32+
- async-arti-hyper-rustls
3033
steps:
3134
- uses: actions/checkout@v3
3235
- name: Generate cache key
@@ -52,10 +55,11 @@ jobs:
5255
if: matrix.rust.version == '1.63.0'
5356
run: |
5457
cargo update -p home --precise 0.5.5
58+
cargo update -p serde_with --precise 3.1.0
5559
- name: Build
5660
run: cargo build --features ${{ matrix.features }} --no-default-features
5761
- name: Clippy
5862
if: ${{ matrix.rust.clippy }}
5963
run: cargo clippy --all-targets --features ${{ matrix.features }} --no-default-features -- -D warnings
6064
- name: Test
61-
run: cargo test --features ${{ matrix.features }} --no-default-features
65+
run: cargo test --features ${{ matrix.features }} --no-default-features -- --include-ignored

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ async-https-rustls-manual-roots = ["async", "reqwest/rustls-tls-manual-roots"]
5353
# TODO: (@leonardo) Should I rename it to async-anonymized ?
5454
async-arti-hyper = ["hyper", "arti-client", "tor-rtcompat", "tls-api", "tls-api-native-tls", "tls-api-openssl", "arti-hyper"]
5555
async-arti-hyper-native = ["async-arti-hyper", "arti-hyper/native-tls"]
56-
async-arti-hyper-rustls = ["async-arti-hyper", "arti-hyper/rustls"]
56+
async-arti-hyper-rustls = ["async-arti-hyper", "arti-hyper/rustls"]

src/async.rs

+53-39
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
use std::collections::HashMap;
1515
use std::str::FromStr;
1616

17-
use arti_client::{TorClient, TorClientConfig};
18-
19-
use arti_hyper::ArtiHttpConnector;
20-
2117
use bitcoin::consensus::{deserialize, serialize};
2218
use bitcoin::hashes::hex::FromHex;
2319
use bitcoin::hashes::{sha256, Hash};
@@ -26,26 +22,39 @@ use bitcoin::{
2622
};
2723
use bitcoin_internals::hex::display::DisplayHex;
2824

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

33-
use reqwest::{Client, StatusCode};
34-
use tls_api::{TlsConnector as TlsConnectorTrait, TlsConnectorBuilder};
28+
#[cfg(feature = "async")]
29+
use reqwest::Client;
30+
31+
#[cfg(feature = "async-arti-hyper")]
32+
use {
33+
arti_client::{TorClient, TorClientConfig},
34+
arti_hyper::ArtiHttpConnector,
35+
hyper::service::Service,
36+
hyper::{Body, Request, Response, Uri},
37+
tls_api::{TlsConnector as TlsConnectorTrait, TlsConnectorBuilder},
38+
tor_rtcompat::PreferredRuntime,
39+
};
40+
41+
#[cfg(feature = "async-arti-hyper")]
3542
#[cfg(not(target_vendor = "apple"))]
3643
use tls_api_native_tls::TlsConnector;
44+
#[cfg(feature = "async-arti-hyper")]
3745
#[cfg(target_vendor = "apple")]
3846
use tls_api_openssl::TlsConnector;
39-
use tor_rtcompat::PreferredRuntime;
4047

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

50+
#[cfg(feature = "async")]
4351
#[derive(Debug, Clone)]
4452
pub struct AsyncClient {
4553
url: String,
4654
client: Client,
4755
}
4856

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

80-
if let StatusCode::NOT_FOUND = resp.status() {
89+
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
8190
return Ok(None);
8291
}
8392

@@ -112,7 +121,7 @@ impl AsyncClient {
112121
.send()
113122
.await?;
114123

115-
if let StatusCode::NOT_FOUND = resp.status() {
124+
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
116125
return Ok(None);
117126
}
118127

@@ -198,7 +207,7 @@ impl AsyncClient {
198207
.send()
199208
.await?;
200209

201-
if let StatusCode::NOT_FOUND = resp.status() {
210+
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
202211
return Ok(None);
203212
}
204213

@@ -220,7 +229,7 @@ impl AsyncClient {
220229
.send()
221230
.await?;
222231

223-
if let StatusCode::NOT_FOUND = resp.status() {
232+
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
224233
return Ok(None);
225234
}
226235

@@ -242,7 +251,7 @@ impl AsyncClient {
242251
.send()
243252
.await?;
244253

245-
if let StatusCode::NOT_FOUND = resp.status() {
254+
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
246255
return Ok(None);
247256
}
248257

@@ -269,7 +278,7 @@ impl AsyncClient {
269278
.send()
270279
.await?;
271280

272-
if let StatusCode::NOT_FOUND = resp.status() {
281+
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
273282
return Ok(None);
274283
}
275284

@@ -346,7 +355,7 @@ impl AsyncClient {
346355
.send()
347356
.await?;
348357

349-
if let StatusCode::NOT_FOUND = resp.status() {
358+
if let reqwest::StatusCode::NOT_FOUND = resp.status() {
350359
return Err(Error::HeaderHeightNotFound(block_height));
351360
}
352361

@@ -441,12 +450,14 @@ impl AsyncClient {
441450
}
442451
}
443452

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

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

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

488-
if let StatusCode::NOT_FOUND = resp.status() {
499+
if let hyper::StatusCode::NOT_FOUND = resp.status() {
489500
return Ok(None);
490501
}
491502

@@ -521,7 +532,7 @@ impl AsyncAnonymizedClient {
521532

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

524-
if let StatusCode::NOT_FOUND = resp.status() {
535+
if let hyper::StatusCode::NOT_FOUND = resp.status() {
525536
return Ok(None);
526537
}
527538

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

607-
if let StatusCode::NOT_FOUND = resp.status() {
618+
if let hyper::StatusCode::NOT_FOUND = resp.status() {
608619
return Ok(None);
609620
}
610621

@@ -627,7 +638,7 @@ impl AsyncAnonymizedClient {
627638

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

630-
if let StatusCode::NOT_FOUND = resp.status() {
641+
if let hyper::StatusCode::NOT_FOUND = resp.status() {
631642
return Ok(None);
632643
}
633644

@@ -652,7 +663,7 @@ impl AsyncAnonymizedClient {
652663

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

655-
if let StatusCode::NOT_FOUND = resp.status() {
666+
if let hyper::StatusCode::NOT_FOUND = resp.status() {
656667
return Ok(None);
657668
}
658669

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

681-
if let StatusCode::NOT_FOUND = resp.status() {
692+
if let hyper::StatusCode::NOT_FOUND = resp.status() {
682693
return Ok(None);
683694
}
684695

@@ -698,23 +709,26 @@ impl AsyncAnonymizedClient {
698709
}
699710

700711
// /// Broadcast a [`Transaction`] to Esplora
701-
// pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> {
702-
// let resp = self
703-
// .client
704-
// .post(&format!("{}/tx", self.url))
705-
// .body(serialize(transaction).to_lower_hex_string())
706-
// .send()
707-
// .await?;
708-
709-
// if resp.status().is_server_error() || resp.status().is_client_error() {
710-
// Err(Error::HttpResponse {
711-
// status: resp.status().as_u16(),
712-
// message: resp.text().await?,
713-
// })
714-
// } else {
715-
// Ok(())
716-
// }
717-
// }
712+
pub async fn broadcast(&mut self, transaction: &Transaction) -> Result<(), Error> {
713+
let path = &format!("{}/tx", self.url);
714+
let uri = Uri::from_str(path).map_err(|_| Error::InvalidUri)?;
715+
716+
let body = Body::from(serialize(transaction).to_lower_hex_string());
717+
let req = Request::post(uri)
718+
.body(body)
719+
.map_err(|_| Error::InvalidBody)?;
720+
721+
let resp = self.client.call(req).await?;
722+
723+
if resp.status().is_server_error() || resp.status().is_client_error() {
724+
Err(Error::HttpResponse {
725+
status: resp.status().as_u16(),
726+
message: Self::text(resp).await?,
727+
})
728+
} else {
729+
Ok(())
730+
}
731+
}
718732

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

764-
if let StatusCode::NOT_FOUND = resp.status() {
778+
if let hyper::StatusCode::NOT_FOUND = resp.status() {
765779
return Err(Error::HeaderHeightNotFound(block_height));
766780
}
767781

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use bitcoin::consensus;
8888

8989
pub mod api;
9090

91-
#[cfg(feature = "async")]
91+
#[cfg(any(feature = "async", feature = "async-arti-hyper"))]
9292
pub mod r#async;
9393
#[cfg(feature = "blocking")]
9494
pub mod blocking;
@@ -196,6 +196,9 @@ pub enum Error {
196196
/// Error during hyper HTTP request
197197
#[cfg(feature = "async-arti-hyper")]
198198
InvalidUri,
199+
/// Error during hyper HTTP request body creation
200+
#[cfg(feature = "async-arti-hyper")]
201+
InvalidBody,
199202
/// Error during Tor client creation
200203
#[cfg(feature = "async-arti-hyper")]
201204
ArtiClient(::arti_client::Error),

0 commit comments

Comments
 (0)