Skip to content

Commit 1f0344a

Browse files
committed
deps(bdk_testenv): bump electrsd to 0.36.1
- upgrades the `electrsd` to latest `0.36.1`. - updates the `electrsd` features to use `corepc-node_28_2`, it's the previously named `bitcoind`. - introduce `bitcoin` as a dependency, in order to use the `bitcoind/rand-std` feature, which is now toggled by `bdk_testenv/std`. - remove the MSRV pinned `home` dependency, it's not currently required.
1 parent d0eaadf commit 1f0344a

3 files changed

Lines changed: 55 additions & 54 deletions

File tree

ci/pin-msrv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ set -euo pipefail
1010
# cargo clean
1111
# rustup override set 1.85.0
1212

13-
cargo update -p home --precise "0.5.11"
13+
# e.g cargo update -p home --precise "0.5.11"

crates/testenv/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ workspace = true
1717

1818
[dependencies]
1919
bdk_chain = { path = "../chain", version = "0.23.1", default-features = false }
20-
electrsd = { version = "0.28.0", features = [ "legacy" ], default-features = false }
20+
electrsd = { version = "0.36.1", features = [ "legacy" ], default-features = false }
21+
bitcoin = { version = "0.32.0", default-features = false }
2122

2223
[dev-dependencies]
2324
bdk_testenv = { path = "." }
2425

2526
[features]
2627
default = ["std", "download"]
27-
download = ["electrsd/bitcoind_25_0", "electrsd/esplora_a33e97e1"]
28-
std = ["bdk_chain/std"]
28+
download = ["electrsd/corepc-node_28_2", "electrsd/esplora_a33e97e1"]
29+
std = ["bdk_chain/std", "bitcoin/rand-std"]
2930
serde = ["bdk_chain/serde"]
3031

3132
[package.metadata.docs.rs]

crates/testenv/src/lib.rs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,33 @@ pub mod utils;
55
use bdk_chain::{
66
bitcoin::{
77
address::NetworkChecked, block::Header, hash_types::TxMerkleNode, hashes::Hash,
8-
secp256k1::rand::random, transaction, Address, Amount, Block, BlockHash, CompactTarget,
9-
ScriptBuf, ScriptHash, Transaction, TxIn, TxOut, Txid,
8+
secp256k1::rand::random, transaction, Address, Amount, Block, BlockHash, ScriptBuf,
9+
ScriptHash, Transaction, TxIn, TxOut, Txid,
1010
},
1111
local_chain::CheckPoint,
1212
};
13-
use bitcoincore_rpc::{
14-
bitcoincore_rpc_json::{GetBlockTemplateModes, GetBlockTemplateRules},
15-
RpcApi,
16-
};
17-
use electrsd::bitcoind::anyhow::Context;
13+
use electrsd::corepc_node::{anyhow::Context, TemplateRequest, TemplateRules};
1814

1915
pub use electrsd;
20-
pub use electrsd::bitcoind;
21-
pub use electrsd::bitcoind::anyhow;
22-
pub use electrsd::bitcoind::bitcoincore_rpc;
16+
pub use electrsd::corepc_client;
17+
pub use electrsd::corepc_node;
18+
pub use electrsd::corepc_node::anyhow;
2319
pub use electrsd::electrum_client;
2420
use electrsd::electrum_client::ElectrumApi;
2521
use std::time::Duration;
2622

2723
/// Struct for running a regtest environment with a single `bitcoind` node with an `electrs`
2824
/// instance connected to it.
2925
pub struct TestEnv {
30-
pub bitcoind: electrsd::bitcoind::BitcoinD,
26+
pub bitcoind: electrsd::corepc_node::Node,
3127
pub electrsd: electrsd::ElectrsD,
3228
}
3329

3430
/// Configuration parameters.
3531
#[derive(Debug)]
3632
pub struct Config<'a> {
3733
/// [`bitcoind::Conf`]
38-
pub bitcoind: bitcoind::Conf<'a>,
34+
pub bitcoind: corepc_node::Conf<'a>,
3935
/// [`electrsd::Conf`]
4036
pub electrsd: electrsd::Conf<'a>,
4137
}
@@ -45,7 +41,7 @@ impl Default for Config<'_> {
4541
/// which is required for testing `bdk_esplora`.
4642
fn default() -> Self {
4743
Self {
48-
bitcoind: bitcoind::Conf::default(),
44+
bitcoind: corepc_node::Conf::default(),
4945
electrsd: {
5046
let mut conf = electrsd::Conf::default();
5147
conf.http_enabled = true;
@@ -65,11 +61,11 @@ impl TestEnv {
6561
pub fn new_with_config(config: Config) -> anyhow::Result<Self> {
6662
let bitcoind_exe = match std::env::var("BITCOIND_EXE") {
6763
Ok(path) => path,
68-
Err(_) => bitcoind::downloaded_exe_path().context(
64+
Err(_) => corepc_node::downloaded_exe_path().context(
6965
"you need to provide an env var BITCOIND_EXE or specify a bitcoind version feature",
7066
)?,
7167
};
72-
let bitcoind = bitcoind::BitcoinD::with_conf(bitcoind_exe, &config.bitcoind)?;
68+
let bitcoind = corepc_node::Node::with_conf(bitcoind_exe, &config.bitcoind)?;
7369

7470
let electrs_exe = match std::env::var("ELECTRS_EXE") {
7571
Ok(path) => path,
@@ -87,7 +83,7 @@ impl TestEnv {
8783
}
8884

8985
/// Exposes the [`RpcApi`] calls from [`bitcoincore_rpc`].
90-
pub fn rpc_client(&self) -> &impl RpcApi {
86+
pub fn rpc_client(&self) -> &corepc_node::Client {
9187
&self.bitcoind.client
9288
}
9389

@@ -118,26 +114,27 @@ impl TestEnv {
118114
) -> anyhow::Result<Vec<BlockHash>> {
119115
let coinbase_address = match address {
120116
Some(address) => address,
121-
None => self
122-
.bitcoind
123-
.client
124-
.get_new_address(None, None)?
125-
.assume_checked(),
117+
None => self.bitcoind.client.new_address()?,
126118
};
127119
let block_hashes = self
128120
.bitcoind
129121
.client
130-
.generate_to_address(count as _, &coinbase_address)?;
122+
.generate_to_address(count as _, &coinbase_address)?
123+
.into_model()?
124+
.0;
131125
Ok(block_hashes)
132126
}
133127

134128
/// Mine a block that is guaranteed to be empty even with transactions in the mempool.
135129
pub fn mine_empty_block(&self) -> anyhow::Result<(usize, BlockHash)> {
136-
let bt = self.bitcoind.client.get_block_template(
137-
GetBlockTemplateModes::Template,
138-
&[GetBlockTemplateRules::SegWit],
139-
&[],
140-
)?;
130+
let request = TemplateRequest {
131+
rules: vec![TemplateRules::Segwit],
132+
};
133+
let bt = self
134+
.bitcoind
135+
.client
136+
.get_block_template(&request)?
137+
.into_model()?;
141138

142139
let txdata = vec![Transaction {
143140
version: transaction::Version::ONE,
@@ -146,7 +143,7 @@ impl TestEnv {
146143
previous_output: bdk_chain::bitcoin::OutPoint::default(),
147144
script_sig: ScriptBuf::builder()
148145
.push_int(bt.height as _)
149-
// randomn number so that re-mining creates unique block
146+
// random number so that re-mining creates unique block
150147
.push_int(random())
151148
.into_script(),
152149
sequence: bdk_chain::bitcoin::Sequence::default(),
@@ -158,19 +155,16 @@ impl TestEnv {
158155
}],
159156
}];
160157

161-
let bits: [u8; 4] = bt
162-
.bits
163-
.clone()
164-
.try_into()
165-
.expect("rpc provided us with invalid bits");
166-
167158
let mut block = Block {
168159
header: Header {
169-
version: bdk_chain::bitcoin::block::Version::default(),
160+
version: bt.version,
170161
prev_blockhash: bt.previous_block_hash,
171162
merkle_root: TxMerkleNode::all_zeros(),
172-
time: Ord::max(bt.min_time, std::time::UNIX_EPOCH.elapsed()?.as_secs()) as u32,
173-
bits: CompactTarget::from_consensus(u32::from_be_bytes(bits)),
163+
time: Ord::max(
164+
bt.min_time,
165+
std::time::UNIX_EPOCH.elapsed()?.as_secs() as u32,
166+
),
167+
bits: bt.bits,
174168
nonce: 0,
175169
},
176170
txdata,
@@ -186,6 +180,7 @@ impl TestEnv {
186180
}
187181

188182
self.bitcoind.client.submit_block(&block)?;
183+
189184
Ok((bt.height as usize, block.block_hash()))
190185
}
191186

@@ -238,14 +233,15 @@ impl TestEnv {
238233

239234
/// Invalidate a number of blocks of a given size `count`.
240235
pub fn invalidate_blocks(&self, count: usize) -> anyhow::Result<()> {
241-
let mut hash = self.bitcoind.client.get_best_block_hash()?;
236+
let mut hash = self.bitcoind.client.get_best_block_hash()?.block_hash()?;
242237
for _ in 0..count {
243238
let prev_hash = self
244239
.bitcoind
245240
.client
246-
.get_block_info(&hash)?
247-
.previousblockhash;
248-
self.bitcoind.client.invalidate_block(&hash)?;
241+
.get_block_verbose_one(hash)?
242+
.into_model()?
243+
.previous_block_hash;
244+
self.bitcoind.client.invalidate_block(hash)?;
249245
match prev_hash {
250246
Some(prev_hash) => hash = prev_hash,
251247
None => break,
@@ -290,35 +286,39 @@ impl TestEnv {
290286
let txid = self
291287
.bitcoind
292288
.client
293-
.send_to_address(address, amount, None, None, None, None, None, None)?;
289+
.send_to_address(address, amount)?
290+
.txid()?;
294291
Ok(txid)
295292
}
296293

297294
/// Create a checkpoint linked list of all the blocks in the chain.
298295
pub fn make_checkpoint_tip(&self) -> CheckPoint<BlockHash> {
299296
CheckPoint::from_blocks((0_u32..).map_while(|height| {
300-
self.bitcoind
301-
.client
302-
.get_block_hash(height as u64)
297+
self.get_block_hash(height as u64)
303298
.ok()
304-
.map(|hash| (height, hash))
299+
.map(|block_hash| (height, block_hash))
305300
}))
306301
.expect("must craft tip")
307302
}
308303

309304
/// Get the genesis hash of the blockchain.
310305
pub fn genesis_hash(&self) -> anyhow::Result<BlockHash> {
311-
let hash = self.bitcoind.client.get_block_hash(0)?;
306+
let hash = self.bitcoind.client.get_block_hash(0)?.into_model()?.0;
312307
Ok(hash)
313308
}
309+
310+
/// Get block hash by `height` from the `bitcoind` client.
311+
pub fn get_block_hash(&self, height: u64) -> anyhow::Result<BlockHash> {
312+
Ok(self.bitcoind.client.get_block_hash(height)?.block_hash()?)
313+
}
314314
}
315315

316316
#[cfg(test)]
317317
#[cfg_attr(coverage_nightly, coverage(off))]
318318
mod test {
319319
use crate::TestEnv;
320320
use core::time::Duration;
321-
use electrsd::bitcoind::{anyhow::Result, bitcoincore_rpc::RpcApi};
321+
use electrsd::corepc_node::anyhow::Result;
322322

323323
/// This checks that reorgs initiated by `bitcoind` is detected by our `electrsd` instance.
324324
#[test]
@@ -328,15 +328,15 @@ mod test {
328328
// Mine some blocks.
329329
env.mine_blocks(101, None)?;
330330
env.wait_until_electrum_sees_block(Duration::from_secs(6))?;
331-
let height = env.bitcoind.client.get_block_count()?;
331+
let height = env.bitcoind.client.get_block_count()?.into_model().0;
332332
let blocks = (0..=height)
333333
.map(|i| env.bitcoind.client.get_block_hash(i))
334334
.collect::<Result<Vec<_>, _>>()?;
335335

336336
// Perform reorg on six blocks.
337337
env.reorg(6)?;
338338
env.wait_until_electrum_sees_block(Duration::from_secs(6))?;
339-
let reorged_height = env.bitcoind.client.get_block_count()?;
339+
let reorged_height = env.bitcoind.client.get_block_count()?.into_model().0;
340340
let reorged_blocks = (0..=height)
341341
.map(|i| env.bitcoind.client.get_block_hash(i))
342342
.collect::<Result<Vec<_>, _>>()?;

0 commit comments

Comments
 (0)