Skip to content

Commit

Permalink
Merge rust-bitcoin#538: Various fixes for Nix compatibility
Browse files Browse the repository at this point in the history
f50cbbb set honggfuzz dependency to 0.5.55 (Andrew Poelstra)
73bcffc cargo fmt new workspaces (bitcoin-tests, fuzz) (Andrew Poelstra)
cd0abcd bitcoind-tests: find the bitcoind executable no matter where we are running from (Andrew Poelstra)
bf98e2a bitcoind-tests: allow overriding the BITCOIND_EXE variable (Andrew Poelstra)
54d7657 promote bitcoind-tests and fuzz to workspaces (Andrew Poelstra)

Pull request description:

  This brings the fuzztests and bitcoind-tests into workspaces along with the root crate. This means they are covered by `cargo test --all` and `cargo fmt --all` without any special action, and also means that `crate2nix` can test them independently without my manually messing around with directories. I run `cargo +nightly fmt` to bring the two new workspaces into proper formatting -- there were no changes that I'd consider controversial.

  It also allows the `bitcoin-tests` directory to be run with a custom `BITCOIND_EXE` variable, and computes the default version more flexibly so that you can run the tests from any directory.

  Finally I set the minimum honggfuzz version to 0.5.55, since the dep currently was set to 0.5.0, which definitely did not work.

  With these changes, everything in this repo should work with a lockfile generated by `cargo +nightly update -Z minimal-versions`, and I am able to run both the bitcoind and fuzz tests (for five minutes per unit locally). I'll push some code to my [local-nix-ci repo](https://github.com/apoelstra/local-nix-ci) tomorrow to demonstrate whan I'm doing.

  This PR does **not** do more dramatic rearrangemeent of the fuzztests ... though when rust-bitcoin/rust-bitcoin#1732 gets merged I will open a similar PR here which does that.

ACKs for top commit:
  sanket1729:
    ACK f50cbbb.

Tree-SHA512: a234f9f09ad059b051b2336738a1f8fb4d807af4523380037c8121173cfd05ab0deb567b92abfae3fc794d9ad91966f43d7396623a453df242bc5392a1bcb489
  • Loading branch information
sanket1729 authored and gruve-p committed Aug 28, 2023
1 parent 5d003c4 commit dcd6915
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions bitcoind-tests/tests/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
extern crate miniscript;

use bitcoind::bitcoincore_rpc::RpcApi;
use bitcoind::BitcoinD;
use miniscript::bitcoin;

pub mod test_util;

// Launch an instance of bitcoind with
pub fn setup() -> BitcoinD {
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
let key = "BITCOIND_EXE";
if std::env::var(key).is_err() {
let mut root_path = std::env::current_dir().unwrap();
while std::fs::metadata(root_path.join("LICENSE")).is_err() {
if !root_path.pop() {
panic!("Could not find LICENSE file; do not know where repo root is.");
}
}

let bitcoind_path = root_path
.join("bitcoind-tests")
.join("bin")
.join("bitcoind");
std::env::set_var(key, bitcoind_path);
}

let exe_path = bitcoind::exe_path().unwrap();
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();
let cl = &bitcoind.client;
// generate to an address by the wallet. And wait for funds to mature
let addr = cl.get_new_address(None, None).unwrap();
let blks = cl.generate_to_address(101, &addr).unwrap();
assert_eq!(blks.len(), 101);

assert_eq!(
cl.get_balance(Some(1) /*min conf*/, None).unwrap(),
bitcoin::Amount::from_sat(100_000_000 * 50)
);
bitcoind
}

0 comments on commit dcd6915

Please sign in to comment.