bitcoind 0.27.0

Utility to run a regtest bitcoind process, useful in integration testing environment
Documentation

MIT license Crates

Bitcoind

Utility to run a regtest bitcoind process, useful in integration testing environment.

use bitcoincore_rpc::RpcApi;
let exe_path = exe_path().expect("bitcoind executable must be provided in BITCOIND_EXE, or with a feature like '22_0', or be in PATH");
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();
assert_eq!(0, bitcoind.client.get_blockchain_info().unwrap().blocks);

Automatic binaries download

When a feature like 22_0 is selected, the build script will automatically download the bitcoin core version 22.0, verify the hashes and place it in the build directory for this crate. Use utility function downloaded_exe_path() to get the downloaded executable path.

Example

In your project Cargo.toml, activate the following features


[dev-dependencies]
bitcoind = { version = "0.20.0", features = [ "22_0" ] }

Then use it:

let bitcoind = bitcoind::BitcoinD::new(bitcoind::downloaded_exe_path().unwrap()).unwrap();

MSRV

1.41.1

Issues with traditional approach

I used integration testing based on external bash script launching needed external processes, there are many issues with this approach like:

Features

  • It waits until bitcoind daemon become ready to accept RPC commands
  • 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)
  • Free ports are asked to the OS (a low probability race condition is still possible)
  • the process is killed when the struct goes out of scope no matter how the test finishes
  • allows easy spawning of dependent process like https://github.com/RCasatta/electrsd

Thanks to these features every #[test] could easily run isolated with its own environment.

Used by

Via bdk dependency

Via electrsd dependency: