Crates.io | bitcoind |
lib.rs | bitcoind |
version | 0.34.3 |
source | src |
created_at | 2021-05-13 16:19:43.44038 |
updated_at | 2024-08-19 15:36:12.060055 |
description | Utility to run a regtest bitcoind process, useful in integration testing environment |
homepage | |
repository | https://github.com/RCasatta/bitcoind |
max_upload_size | |
id | 396987 |
size | 78,955 |
Utility to run a regtest bitcoind process, useful in integration testing environment.
When the auto-download feature is selected by activating one of the version feature, such as 25_1
for bitcoin core 25.1, starting a regtest node is as simple as that:
// the download feature is enabled whenever a specific version is enabled, for example `25_1` or `24_0_1`
#[cfg(feature = "download")]
{
use bitcoincore_rpc::RpcApi;
let bitcoind = bitcoind::BitcoinD::from_downloaded().unwrap();
assert_eq!(0, bitcoind.client.get_blockchain_info().unwrap().blocks);
}
The build script will automatically download the bitcoin core version 25.1 from bitcoin core,
verify the hashes and place it in the build directory for this crate. If you wish to download from an
alternate location, for example locally for CI, use the BITCOIND_DOWNLOAD_ENDPOINT
env var.
When you don't use the auto-download feature you have the following options:
bitcoind
executable in the PATH
bitcoind
executable via the BITCOIND_EXEC
env varuse bitcoincore_rpc::RpcApi;
if let Ok(exe_path) = bitcoind::exe_path() {
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();
assert_eq!(0, bitcoind.client.get_blockchain_info().unwrap().blocks);
}
Startup options could be configured via the [Conf
] struct using [BitcoinD::with_conf
] or
[BitcoinD::from_downloaded_with_conf
]
I used integration testing based on external bash script launching needed external processes, there are many issues with this approach like:
bitcoind
use a temporary directory as datadir. You can specify the root of your temp directories
so that you have node's datadir in a RAM disk (eg /dev/shm
)Thanks to these features every #[test]
could easily run isolated with its own environment.
To build docs:
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --features download,doc --open
The MSRV is 1.48.0 for version 0.29.* if no feature is used, otherwise is 1.57
Note: to respect 1.48.0 MSRV you need to use and older version of some dependencies, in CI the below dependency versions are pinned:
cargo update
cargo update -p which --precise 4.2.5
cargo update -p tempfile --precise 3.3.0
cargo update -p log --precise 0.4.18
cargo update -p serde_json --precise 1.0.99
cargo update -p serde --precise 1.0.156
cargo update -p regex --precise 1.7.3
cargo update -p thiserror --precise 1.0.40
cargo update -p quote --precise 1.0.28
cargo update -p syn:2.0.37 --precise 2.0.32
cargo update -p proc-macro2 --precise 1.0.63
Pinning in Cargo.toml
is avoided because it could cause
compilation issues downstream.
For reproducibility reasons, Nix build scripts cannot hit the internet, but the
auto-download feature does exactly that. To successfully build under Nix the
user must provide the tarball locally and specify its location via the
BITCOIND_TARBALL_FILE
env var.
Alternatively, use the dep without auto-download feature.