Skip to content

Commit f6e9ac9

Browse files
committed
Skip tests requiring block generation when RPC miner unavailable
Add supports_mining probe to DashCoreNode that detects whether the dashd binary has generatetoaddress compiled in. Some builds (e.g. Windows release binaries) ship without the RPC miner. Tests that generate blocks after initial sync now skip gracefully instead of panicking.
1 parent af9b222 commit f6e9ac9

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

dash-spv-ffi/tests/callback_integration_test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ fn test_callbacks_post_sync_transactions_and_disconnect() {
129129
let Some(mut dashd) = rt.block_on(DashdTestContext::new()) else {
130130
return;
131131
};
132+
if !dashd.supports_mining {
133+
eprintln!("Skipping test (dashd RPC miner not available)");
134+
return;
135+
}
132136

133137
unsafe {
134138
let ctx = FFITestContext::new(dashd.addr);

dash-spv-ffi/tests/dashd_ffi_sync_test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ fn test_ffi_sync_then_generate_blocks() {
6969
let Some(mut dashd) = rt.block_on(DashdTestContext::new()) else {
7070
return;
7171
};
72+
if !dashd.supports_mining {
73+
eprintln!("Skipping test (dashd RPC miner not available)");
74+
return;
75+
}
7276

7377
unsafe {
7478
let ctx = FFITestContext::new(dashd.addr);

dash-spv/src/test_utils/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct DashdTestContext {
2121
pub addr: SocketAddr,
2222
pub expected_height: u32,
2323
pub wallet: WalletFile,
24+
pub supports_mining: bool,
2425
_datadir: TempDir,
2526
}
2627

@@ -67,11 +68,17 @@ impl DashdTestContext {
6768
let expected_height = node.get_block_count().await;
6869
info!("Dashd has {} blocks", expected_height);
6970

71+
let supports_mining = node.supports_mining();
72+
if !supports_mining {
73+
info!("RPC miner not available (tests requiring block generation will be skipped)");
74+
}
75+
7076
Some(DashdTestContext {
7177
node,
7278
addr,
7379
expected_height,
7480
wallet,
81+
supports_mining,
7582
_datadir: datadir,
7683
})
7784
}

dash-spv/src/test_utils/node.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,25 @@ impl DashCoreNode {
316316
address.assume_checked()
317317
}
318318

319+
/// Check if the connected dashd supports `generatetoaddress` (RPC miner).
320+
///
321+
/// Some builds (e.g. Windows release binaries) ship without the RPC miner compiled in.
322+
pub fn supports_mining(&self) -> bool {
323+
let client = self.rpc_client();
324+
let addr = self.get_new_address();
325+
match client.generate_to_address(0, &addr) {
326+
Ok(_) => true,
327+
Err(dashcore_rpc::Error::JsonRpc(dashcore_rpc::jsonrpc::Error::Rpc(ref e)))
328+
if e.message.contains("not available") =>
329+
{
330+
false
331+
}
332+
// Any other error (auth, network) still counts as "available" —
333+
// a real generate call will surface the actual error.
334+
Err(_) => true,
335+
}
336+
}
337+
319338
/// Generate blocks to the given address.
320339
pub fn generate_blocks(&self, count: u64, address: &Address) -> Vec<BlockHash> {
321340
let client = self.rpc_client();

dash-spv/tests/dashd_sync.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@ async fn test_sync_then_generate_blocks() {
760760
let Some(ctx) = TestContext::new().await else {
761761
return;
762762
};
763+
if !ctx.dashd.supports_mining {
764+
eprintln!("Skipping test (dashd RPC miner not available)");
765+
return;
766+
}
763767

764768
let (wallet, wallet_id) = ctx.create_wallet();
765769

@@ -828,6 +832,10 @@ async fn test_multiple_transactions_in_single_block() {
828832
let Some(ctx) = TestContext::new().await else {
829833
return;
830834
};
835+
if !ctx.dashd.supports_mining {
836+
eprintln!("Skipping test (dashd RPC miner not available)");
837+
return;
838+
}
831839

832840
let (wallet, wallet_id) = ctx.create_wallet();
833841

@@ -909,6 +917,10 @@ async fn test_multiple_transactions_across_blocks() {
909917
let Some(ctx) = TestContext::new().await else {
910918
return;
911919
};
920+
if !ctx.dashd.supports_mining {
921+
eprintln!("Skipping test (dashd RPC miner not available)");
922+
return;
923+
}
912924

913925
let (wallet, wallet_id) = ctx.create_wallet();
914926

0 commit comments

Comments
 (0)