Skip to content

Commit 2046195

Browse files
committed
Make corepc-node optional in payjoin-test-utils
Test constants (ORIGINAL_PSBT, EXAMPLE_URL, etc.) and the TestServices infrastructure don't require bitcoind. Only init_bitcoind* functions need the corepc-node crate, which downloads a ~40MB binary at build time. Gate corepc-node behind a `bitcoind` feature (default = on) so downstream consumers can import payjoin-test-utils for constants without triggering the bitcoind download. This unblocks nix environments and CI setups that provide their own bitcoind via BITCOIND_EXE.
1 parent 117ce51 commit 2046195

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

payjoin-test-utils/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ repository = "https://github.com/payjoin/rust-payjoin"
88
rust-version = "1.85"
99
license = "MIT"
1010

11+
[features]
12+
default = ["bitcoind"]
13+
bitcoind = ["dep:corepc-node"]
14+
1115
[dependencies]
1216
axum-server = { version = "0.8", features = ["tls-rustls-no-provider"] }
1317
bitcoin = { version = "0.32.7", features = ["base64"] }
14-
corepc-node = { version = "0.10.0", features = ["download", "29_0"] }
18+
corepc-node = { version = "0.10.0", features = ["download", "29_0"], optional = true }
1519
http = "1.3.1"
1620
ohttp = { package = "bitcoin-ohttp", version = "0.6.0" }
1721
once_cell = "1.21.3"

payjoin-test-utils/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use std::sync::Arc;
44
use std::time::Duration;
55

66
use axum_server::tls_rustls::RustlsConfig;
7-
use bitcoin::{Amount, Psbt};
8-
pub use corepc_node; // re-export for convenience
9-
use corepc_node::AddressType;
7+
use bitcoin::Psbt;
108
use http::StatusCode;
119
use ohttp::hpke::{Aead, Kdf, Kem};
1210
use ohttp::{KeyId, SymmetricSuite};
@@ -19,9 +17,17 @@ use rustls::pki_types::CertificateDer;
1917
use rustls::RootCertStore;
2018
use tempfile::tempdir;
2119
use tokio::task::JoinHandle;
22-
use tracing::Level;
2320
use tracing_subscriber::{EnvFilter, FmtSubscriber};
2421

22+
#[cfg(feature = "bitcoind")]
23+
use bitcoin::Amount;
24+
#[cfg(feature = "bitcoind")]
25+
pub use corepc_node;
26+
#[cfg(feature = "bitcoind")]
27+
use corepc_node::AddressType;
28+
#[cfg(feature = "bitcoind")]
29+
use tracing::Level;
30+
2531
pub type BoxError = Box<dyn std::error::Error + 'static>;
2632
pub type BoxSendSyncError = Box<dyn std::error::Error + Send + Sync>;
2733

@@ -173,6 +179,7 @@ pub fn local_cert_key() -> rcgen::CertifiedKey<rcgen::KeyPair> {
173179
.expect("Failed to generate cert")
174180
}
175181

182+
#[cfg(feature = "bitcoind")]
176183
pub fn init_bitcoind() -> Result<corepc_node::Node, BoxError> {
177184
let bitcoind_exe = corepc_node::exe_path()?;
178185
let mut conf = corepc_node::Conf::default();
@@ -182,6 +189,7 @@ pub fn init_bitcoind() -> Result<corepc_node::Node, BoxError> {
182189
Ok(bitcoind)
183190
}
184191

192+
#[cfg(feature = "bitcoind")]
185193
pub fn init_bitcoind_sender_receiver(
186194
sender_address_type: Option<AddressType>,
187195
receiver_address_type: Option<AddressType>,
@@ -197,6 +205,7 @@ pub fn init_bitcoind_sender_receiver(
197205
Ok((bitcoind, receiver, sender))
198206
}
199207

208+
#[cfg(feature = "bitcoind")]
200209
fn create_and_fund_wallets<W: AsRef<str>>(
201210
bitcoind: &corepc_node::Node,
202211
wallets: Vec<(W, Option<AddressType>)>,
@@ -231,6 +240,7 @@ pub fn http_agent(cert_der: Vec<u8>) -> Result<Client, BoxSendSyncError> {
231240
Ok(http_agent_builder(cert_der).build()?)
232241
}
233242

243+
#[cfg(feature = "bitcoind")]
234244
pub fn init_bitcoind_multi_sender_single_reciever(
235245
number_of_senders: usize,
236246
) -> Result<(corepc_node::Node, Vec<corepc_node::Client>, corepc_node::Client), BoxError> {

0 commit comments

Comments
 (0)