Skip to content

Commit 4099199

Browse files
committed
Gate payjoin-ffi bitcoind types behind feature
Split _test-utils into _test-utils (constants + TestServices only) and _test-utils-bitcoind (adds BitcoindEnv, RpcClient, etc.). This lets FFI consumers like Dart unit tests import test constants without triggering the corepc-node/bitcoind download. Update all binding-generation and test scripts to use _test-utils-bitcoind where integration-test types are needed.
1 parent 5c59429 commit 4099199

10 files changed

Lines changed: 32 additions & 20 deletions

File tree

payjoin-ffi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ exclude = ["tests"]
99
default = []
1010
csharp = ["dep:uniffi-bindgen-cs"]
1111
dart = ["dep:uniffi-dart"]
12-
_test-utils = ["payjoin-test-utils", "payjoin-test-utils/bitcoind", "tokio"]
12+
_test-utils = ["payjoin-test-utils", "tokio"]
13+
_test-utils-bitcoind = ["_test-utils", "payjoin-test-utils/bitcoind"]
1314
_manual-tls = ["payjoin/_manual-tls"]
1415
wasm_js = ["getrandom/js"]
1516

payjoin-ffi/contrib/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
# Individual features with no defaults.
5-
features=("_manual-tls" "_test-utils")
5+
features=("_manual-tls" "_test-utils" "_test-utils-bitcoind")
66

77
for feature in "${features[@]}"; do
88
# Don't duplicate --all-targets clippy. Clippy end-user code, not tests.

payjoin-ffi/contrib/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
RUST_VERSION=$(rustc --version | awk '{print $2}')
55

66
if [[ ! $RUST_VERSION =~ ^1\.85\. ]]; then
7-
cargo test --package payjoin-ffi --verbose --features=_manual-tls,_test-utils
7+
cargo test --package payjoin-ffi --verbose --features=_manual-tls,_test-utils-bitcoind
88
else
99
echo "Skipping payjoin-ffi tests for Rust version $RUST_VERSION (MSRV)"
1010
fi

payjoin-ffi/csharp/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ dotnet test
5656

5757
Generation uses the Cargo-managed C# generator from `payjoin-ffi/Cargo.toml`.
5858

59-
By default, generation builds `payjoin-ffi` with `_test-utils` enabled to keep parity with other language test scripts. Override via `PAYJOIN_FFI_FEATURES`.
59+
By default, generation builds `payjoin-ffi` with `_test-utils-bitcoind` enabled to keep parity with other language test scripts. Override via `PAYJOIN_FFI_FEATURES`.
6060

6161
### Unix shells
6262

6363
```shell
64-
export PAYJOIN_FFI_FEATURES=_test-utils # default behavior
64+
export PAYJOIN_FFI_FEATURES=_test-utils-bitcoind # default behavior
6565
# export PAYJOIN_FFI_FEATURES="" # build without extra features
6666
bash ./scripts/generate_bindings.sh
6767
```
6868

6969
### PowerShell
7070

7171
```powershell
72-
$env:PAYJOIN_FFI_FEATURES = "_test-utils" # default behavior
72+
$env:PAYJOIN_FFI_FEATURES = "_test-utils-bitcoind" # default behavior
7373
# $env:PAYJOIN_FFI_FEATURES = "" # build without extra features
7474
powershell -ExecutionPolicy Bypass -File .\scripts\generate_bindings.ps1
7575
dotnet build

payjoin-ffi/csharp/scripts/generate_bindings.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Write-Host "Generating payjoin C#..."
4040
if ($null -ne $env:PAYJOIN_FFI_FEATURES) {
4141
$payjoinFfiFeatures = $env:PAYJOIN_FFI_FEATURES
4242
} else {
43-
# Keep parity with other language test scripts: include _test-utils by default.
44-
$payjoinFfiFeatures = "_test-utils"
43+
# Keep parity with other language test scripts: include _test-utils-bitcoind by default.
44+
$payjoinFfiFeatures = "_test-utils-bitcoind"
4545
}
4646

4747
if ($payjoinFfiFeatures) {

payjoin-ffi/csharp/scripts/generate_bindings.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2222
cd "$SCRIPT_DIR/../.."
2323

2424
echo "Generating payjoin C#..."
25-
# Keep parity with other language test scripts: include _test-utils by default.
26-
PAYJOIN_FFI_FEATURES=${PAYJOIN_FFI_FEATURES:-_test-utils}
25+
# Keep parity with other language test scripts: include _test-utils-bitcoind by default.
26+
PAYJOIN_FFI_FEATURES=${PAYJOIN_FFI_FEATURES:-_test-utils-bitcoind}
2727
GENERATOR_FEATURES="csharp"
2828
if [[ -n $PAYJOIN_FFI_FEATURES ]]; then
2929
GENERATOR_FEATURES="$GENERATOR_FEATURES,$PAYJOIN_FFI_FEATURES"

payjoin-ffi/dart/native/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ publish = false
1010

1111
[features]
1212
_test-utils = ["payjoin-ffi/_test-utils"]
13+
_test-utils-bitcoind = ["payjoin-ffi/_test-utils-bitcoind"]
1314

1415
[lib]
1516
name = "payjoin_ffi_wrapper"

payjoin-ffi/dart/scripts/generate_bindings.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919

2020
cd ../
2121
echo "Generating payjoin dart..."
22-
cargo build --features dart,_test-utils --profile dev
23-
cargo run --features dart,_test-utils --profile dev --bin uniffi-bindgen -- --library ../target/debug/$LIBNAME --language dart --out-dir dart/lib/
22+
cargo build --features dart,_test-utils-bitcoind --profile dev
23+
cargo run --features dart,_test-utils-bitcoind --profile dev --bin uniffi-bindgen -- --library ../target/debug/$LIBNAME --language dart --out-dir dart/lib/
2424

2525
echo "All done!"

payjoin-ffi/python/scripts/generate_bindings.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ uv run python --version
1919

2020
cd ../
2121
# This is a test script the actual release should not include the test utils feature
22-
cargo build --features _test-utils --profile dev
23-
cargo run --features _test-utils --profile dev --bin uniffi-bindgen generate --library ../target/debug/$LIBNAME --language python --out-dir python/src/payjoin/
22+
cargo build --features _test-utils-bitcoind --profile dev
23+
cargo run --features _test-utils-bitcoind --profile dev --bin uniffi-bindgen generate --library ../target/debug/$LIBNAME --language python --out-dir python/src/payjoin/
2424

2525
if [[ $OS == "Darwin" ]]; then
2626
echo "Generating native binaries..."
2727
rustup target add aarch64-apple-darwin x86_64-apple-darwin
2828
# This is a test script the actual release should not include the test utils feature
29-
cargo build --profile dev --target aarch64-apple-darwin --features _test-utils &
30-
cargo build --profile dev --target x86_64-apple-darwin --features _test-utils &
29+
cargo build --profile dev --target aarch64-apple-darwin --features _test-utils-bitcoind &
30+
cargo build --profile dev --target x86_64-apple-darwin --features _test-utils-bitcoind &
3131
wait
3232

3333
echo "Building macos fat library"
@@ -39,7 +39,7 @@ else
3939
echo "Generating native binaries..."
4040
rustup target add x86_64-unknown-linux-gnu
4141
# This is a test script the actual release should not include the test utils feature
42-
cargo build --profile dev --target x86_64-unknown-linux-gnu --features _test-utils
42+
cargo build --profile dev --target x86_64-unknown-linux-gnu --features _test-utils-bitcoind
4343

4444
echo "Copying payjoin_ffi binary"
4545
cp ../target/x86_64-unknown-linux-gnu/debug/$LIBNAME python/src/payjoin/$LIBNAME

payjoin-ffi/src/test_utils.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ use std::io;
22
use std::sync::Arc;
33

44
use lazy_static::lazy_static;
5-
use payjoin_test_utils::corepc_node::AddressType;
5+
#[cfg(feature = "_test-utils-bitcoind")]
6+
use payjoin_test_utils::corepc_node::{self, AddressType};
67
use payjoin_test_utils::{
7-
corepc_node, EXAMPLE_URL, INVALID_PSBT, ORIGINAL_PSBT, PAYJOIN_PROPOSAL,
8-
PAYJOIN_PROPOSAL_WITH_SENDER_INFO, QUERY_PARAMS, RECEIVER_INPUT_CONTRIBUTION,
8+
EXAMPLE_URL, INVALID_PSBT, ORIGINAL_PSBT, PAYJOIN_PROPOSAL, PAYJOIN_PROPOSAL_WITH_SENDER_INFO,
9+
QUERY_PARAMS, RECEIVER_INPUT_CONTRIBUTION,
910
};
11+
#[cfg(feature = "_test-utils-bitcoind")]
1012
use serde_json::Value;
1113
use tokio::runtime::Runtime;
1214
use tokio::sync::Mutex;
@@ -16,13 +18,15 @@ lazy_static! {
1618
Arc::new(std::sync::Mutex::new(Runtime::new().expect("Failed to create Tokio runtime")));
1719
}
1820

21+
#[cfg(feature = "_test-utils-bitcoind")]
1922
#[derive(uniffi::Object)]
2023
pub struct BitcoindEnv {
2124
pub bitcoind: Arc<BitcoindInstance>,
2225
pub receiver: Arc<RpcClient>,
2326
pub sender: Arc<RpcClient>,
2427
}
2528

29+
#[cfg(feature = "_test-utils-bitcoind")]
2630
#[uniffi::export]
2731
impl BitcoindEnv {
2832
pub fn get_receiver(&self) -> Arc<RpcClient> { self.receiver.clone() }
@@ -32,16 +36,19 @@ impl BitcoindEnv {
3236
pub fn get_bitcoind(&self) -> Arc<BitcoindInstance> { self.bitcoind.clone() }
3337
}
3438

39+
#[cfg(feature = "_test-utils-bitcoind")]
3540
#[derive(uniffi::Object)]
3641
pub struct BitcoindInstance {
3742
_inner: corepc_node::Node,
3843
}
3944

45+
#[cfg(feature = "_test-utils-bitcoind")]
4046
#[derive(uniffi::Object)]
4147
pub struct RpcClient {
4248
inner: corepc_node::Client,
4349
}
4450

51+
#[cfg(feature = "_test-utils-bitcoind")]
4552
#[uniffi::export]
4653
impl RpcClient {
4754
pub fn call(&self, method: String, params: Vec<Option<String>>) -> Result<String, FfiError> {
@@ -63,6 +70,7 @@ impl RpcClient {
6370
}
6471
}
6572

73+
#[cfg(feature = "_test-utils-bitcoind")]
6674
#[derive(Debug, thiserror::Error, PartialEq, Eq, uniffi::Error)]
6775
pub enum FfiError {
6876
#[error("Init error: {0}")]
@@ -73,6 +81,7 @@ pub enum FfiError {
7381
Message(String),
7482
}
7583

84+
#[cfg(feature = "_test-utils-bitcoind")]
7685
impl FfiError {
7786
pub fn new(msg: impl Into<String>) -> Self { FfiError::Message(msg.into()) }
7887
}
@@ -177,6 +186,7 @@ impl TestServices {
177186
}
178187
}
179188

189+
#[cfg(feature = "_test-utils-bitcoind")]
180190
#[uniffi::export]
181191
pub fn init_bitcoind_sender_receiver() -> Result<Arc<BitcoindEnv>, FfiError> {
182192
let (bitcoind, receiver, sender) = payjoin_test_utils::init_bitcoind_sender_receiver(

0 commit comments

Comments
 (0)