Skip to content

Commit 9393832

Browse files
ValuedMammaloleonardolima
authored andcommitted
build(testenv): mine_empty_blocks requires std feature
Feature-gate TestEnv methods `mine_empty_blocks`, `reorg_empty_blocks` behind `std` feature, as they depend on `rand` which is only available when `std` feature is enabled.
1 parent cbad92e commit 9393832

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

crates/testenv/src/lib.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22

33
pub mod utils;
44

5-
use bdk_chain::{
6-
bitcoin::{
7-
address::NetworkChecked, block::Header, hash_types::TxMerkleNode, hashes::Hash,
8-
secp256k1::rand::random, transaction, Address, Amount, Block, BlockHash, ScriptBuf,
9-
ScriptHash, Transaction, TxIn, TxOut, Txid,
10-
},
11-
local_chain::CheckPoint,
12-
};
13-
use electrsd::corepc_node::{anyhow::Context, TemplateRequest, TemplateRules};
5+
use anyhow::Context;
6+
use bdk_chain::CheckPoint;
7+
use bitcoin::{address::NetworkChecked, Address, Amount, BlockHash, Txid};
8+
use std::time::Duration;
149

1510
pub use electrsd;
1611
pub use electrsd::corepc_client;
1712
pub use electrsd::corepc_node;
1813
pub use electrsd::corepc_node::anyhow;
1914
pub use electrsd::electrum_client;
2015
use electrsd::electrum_client::ElectrumApi;
21-
use std::time::Duration;
2216

2317
/// Struct for running a regtest environment with a single `bitcoind` node with an `electrs`
2418
/// instance connected to it.
@@ -126,7 +120,14 @@ impl TestEnv {
126120
}
127121

128122
/// Mine a block that is guaranteed to be empty even with transactions in the mempool.
123+
#[cfg(feature = "std")]
129124
pub fn mine_empty_block(&self) -> anyhow::Result<(usize, BlockHash)> {
125+
use bitcoin::secp256k1::rand::random;
126+
use bitcoin::{
127+
block::Header, hashes::Hash, transaction, Block, ScriptBuf, ScriptHash, Transaction,
128+
TxIn, TxMerkleNode, TxOut,
129+
};
130+
use corepc_node::{TemplateRequest, TemplateRules};
130131
let request = TemplateRequest {
131132
rules: vec![TemplateRules::Segwit],
132133
};
@@ -266,6 +267,7 @@ impl TestEnv {
266267
}
267268

268269
/// Reorg with a number of empty blocks of a given size `count`.
270+
#[cfg(feature = "std")]
269271
pub fn reorg_empty_blocks(&self, count: usize) -> anyhow::Result<Vec<(usize, BlockHash)>> {
270272
let start_height = self.bitcoind.client.get_block_count()?;
271273
self.invalidate_blocks(count)?;

0 commit comments

Comments
 (0)