Skip to content

Commit 560e7b8

Browse files
committed
Merge #538: Various fixes for Nix compatibility
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
2 parents 466dd49 + f50cbbb commit 560e7b8

18 files changed

+51
-37
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ required-features = ["compiler","std"]
6666
[[example]]
6767
name = "psbt_sign_finalize"
6868
required-features = ["std", "base64"]
69+
70+
[workspace]
71+
members = ["bitcoind-tests", "fuzz"]
72+
exclude = ["embedded"]

bitcoind-tests/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ name = "bitcoind-tests"
33
version = "0.1.0"
44
authors = ["sanket1729 <[email protected]>"]
55
edition = "2018"
6+
publish = false
67

78
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
89

910
[dependencies]
1011
miniscript = {path = "../"}
1112
bitcoind = { version = "0.29.3" }
1213
actual-rand = { package = "rand", version = "0.8.4"}
13-
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
14+
secp256k1 = {version = "0.27.0", features = ["rand-std"]}

bitcoind-tests/tests/setup/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@ pub mod test_util;
1010
pub fn setup() -> BitcoinD {
1111
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
1212
let key = "BITCOIND_EXE";
13-
let curr_dir_path = std::env::current_dir().unwrap();
14-
let bitcoind_path = curr_dir_path.join("bin").join("bitcoind");
15-
std::env::set_var(key, bitcoind_path);
13+
if std::env::var(key).is_err() {
14+
let mut root_path = std::env::current_dir().unwrap();
15+
while std::fs::metadata(root_path.join("LICENSE")).is_err() {
16+
if !root_path.pop() {
17+
panic!("Could not find LICENSE file; do not know where repo root is.");
18+
}
19+
}
20+
21+
let bitcoind_path = root_path
22+
.join("bitcoind-tests")
23+
.join("bin")
24+
.join("bitcoind");
25+
std::env::set_var(key, bitcoind_path);
26+
}
1627

1728
let exe_path = bitcoind::exe_path().unwrap();
1829
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();

bitcoind-tests/tests/setup/test_util.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
2020
use std::str::FromStr;
2121

22-
use miniscript::bitcoin;
2322
use actual_rand as rand;
2423
use bitcoin::hashes::hex::ToHex;
2524
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
2625
use bitcoin::secp256k1;
2726
use miniscript::descriptor::{SinglePub, SinglePubKey};
2827
use miniscript::{
29-
hash256, Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext, TranslatePk,
30-
Translator,
28+
bitcoin, hash256, Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext,
29+
TranslatePk, Translator,
3130
};
3231
use rand::RngCore;
3332

bitcoind-tests/tests/test_cpp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ use bitcoin::util::psbt;
1515
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
1616
use bitcoin::{Amount, LockTime, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid};
1717
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
18-
use miniscript::bitcoin;
1918
use miniscript::psbt::PsbtExt;
20-
use miniscript::Descriptor;
19+
use miniscript::{bitcoin, Descriptor};
2120

2221
mod setup;
2322
use setup::test_util::{self, PubData, TestData};

bitcoind-tests/tests/test_desc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use std::collections::BTreeMap;
88
use std::{error, fmt};
99

10-
use miniscript::bitcoin;
1110
use actual_rand as rand;
1211
use bitcoin::blockdata::witness::Witness;
1312
use bitcoin::hashes::{sha256d, Hash};
@@ -16,12 +15,12 @@ use bitcoin::util::sighash::SighashCache;
1615
use bitcoin::util::taproot::{LeafVersion, TapLeafHash};
1716
use bitcoin::util::{psbt, sighash};
1817
use bitcoin::{
19-
secp256k1, Amount, LockTime, OutPoint, SchnorrSig, Script, Sequence, Transaction, TxIn,
20-
TxOut, Txid,
18+
secp256k1, Amount, LockTime, OutPoint, SchnorrSig, Script, Sequence, Transaction, TxIn, TxOut,
19+
Txid,
2120
};
2221
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
2322
use miniscript::psbt::{PsbtExt, PsbtInputExt};
24-
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
23+
use miniscript::{bitcoin, Descriptor, Miniscript, ScriptContext, ToPublicKey};
2524
mod setup;
2625

2726
use rand::RngCore;

contrib/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fi
4040
# Test bitcoind integration tests if told to (this only works with the stable toolchain)
4141
if [ "$DO_BITCOIND_TESTS" = true ]; then
4242
cd bitcoind-tests
43+
BITCOIND_EXE="$(git rev-parse --show-toplevel)/bitcoind-tests/bin/bitcoind" \
4344
cargo test --verbose
4445

4546
# Exit integration tests, do not run other tests.

embedded/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2018"
77
readme = "README.md"
88
name = "embedded"
99
version = "0.1.0"
10+
publish = false
1011

1112
[dependencies]
1213
cortex-m = "0.6.0"
@@ -25,4 +26,4 @@ bench = false
2526
codegen-units = 1 # better optimizations
2627
debug = true # symbols are nice and they don't increase the size on Flash
2728
lto = true # better optimizations
28-
opt-level = "z"
29+
opt-level = "z"

embedded/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ extern crate alloc;
88
use alloc::string::ToString;
99
use core::alloc::Layout;
1010
use core::panic::PanicInfo;
11-
12-
use alloc_cortex_m::CortexMHeap;
13-
1411
use core::str::FromStr;
1512

13+
use alloc_cortex_m::CortexMHeap;
1614
use cortex_m::asm;
1715
use cortex_m_rt::entry;
1816
use cortex_m_semihosting::{debug, hprintln};

fuzz/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ afl_fuzz = ["afl"]
1212
honggfuzz_fuzz = ["honggfuzz"]
1313

1414
[dependencies]
15-
honggfuzz = { version = "0.5", default-features = false, optional = true }
15+
honggfuzz = { version = "0.5.55", default-features = false, optional = true }
1616
afl = { version = "0.8", optional = true }
1717
regex = { version = "1.4"}
1818
miniscript = { path = "..", features = ["compiler"] }
1919

20-
# Prevent this from interfering with workspaces
21-
[workspace]
22-
members = ["."]
23-
2420
[[bin]]
2521
name = "roundtrip_descriptor"
2622
path = "fuzz_targets/roundtrip_descriptor.rs"

fuzz/fuzz_targets/compile_descriptor.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
extern crate miniscript;
22

3-
use miniscript::Segwitv0;
4-
use miniscript::{policy, Miniscript};
5-
use policy::Liftable;
6-
73
use std::str::FromStr;
84

5+
use miniscript::{policy, Miniscript, Segwitv0};
6+
use policy::Liftable;
7+
98
type Script = Miniscript<String, Segwitv0>;
109
type Policy = policy::Concrete<String>;
1110

@@ -15,7 +14,10 @@ fn do_test(data: &[u8]) {
1514
// Compile
1615
if let Ok(desc) = pol.compile::<Segwitv0>() {
1716
// Lift
18-
assert_eq!(desc.clone().lift().unwrap().sorted(), pol.clone().lift().unwrap().sorted());
17+
assert_eq!(
18+
desc.clone().lift().unwrap().sorted(),
19+
pol.clone().lift().unwrap().sorted()
20+
);
1921
// Try to roundtrip the output of the compiler
2022
let output = desc.to_string();
2123
if let Ok(desc) = Script::from_str(&output) {

fuzz/fuzz_targets/parse_descriptor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
extern crate miniscript;
22

3-
use miniscript::DescriptorPublicKey;
43
use std::str::FromStr;
54

5+
use miniscript::DescriptorPublicKey;
6+
67
fn do_test(data: &[u8]) {
78
let data_str = String::from_utf8_lossy(data);
89
if let Ok(dpk) = DescriptorPublicKey::from_str(&data_str) {

fuzz/fuzz_targets/parse_descriptor_secret.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
extern crate miniscript;
22

3-
use miniscript::descriptor::DescriptorSecretKey;
43
use std::str::FromStr;
54

5+
use miniscript::descriptor::DescriptorSecretKey;
6+
67
fn do_test(data: &[u8]) {
78
let data_str = String::from_utf8_lossy(data);
89
if let Ok(dsk) = DescriptorSecretKey::from_str(&data_str) {

fuzz/fuzz_targets/roundtrip_concrete.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
extern crate miniscript;
22
extern crate regex;
3+
use std::str::FromStr;
4+
35
use miniscript::policy;
46
use regex::Regex;
5-
use std::str::FromStr;
67

78
type Policy = policy::Concrete<String>;
89

fuzz/fuzz_targets/roundtrip_descriptor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
extern crate miniscript;
22
extern crate regex;
33

4+
use std::str::FromStr;
5+
46
use miniscript::Descriptor;
57
use regex::Regex;
6-
use std::str::FromStr;
78

89
fn do_test(data: &[u8]) {
910
let s = String::from_utf8_lossy(data);

fuzz/fuzz_targets/roundtrip_miniscript_script.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
extern crate miniscript;
22

33
use miniscript::bitcoin::blockdata::script;
4-
use miniscript::Miniscript;
5-
use miniscript::Segwitv0;
4+
use miniscript::{Miniscript, Segwitv0};
65

76
fn do_test(data: &[u8]) {
87
// Try round-tripping as a script

fuzz/fuzz_targets/roundtrip_miniscript_str.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
extern crate miniscript;
22
extern crate regex;
33

4-
use regex::Regex;
54
use std::str::FromStr;
65

7-
use miniscript::Miniscript;
8-
use miniscript::Segwitv0;
6+
use miniscript::{Miniscript, Segwitv0};
7+
use regex::Regex;
98

109
fn do_test(data: &[u8]) {
1110
let s = String::from_utf8_lossy(data);

fuzz/fuzz_targets/roundtrip_semantic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
extern crate miniscript;
22

3-
use miniscript::policy;
43
use std::str::FromStr;
54

5+
use miniscript::policy;
6+
67
type Policy = policy::Semantic<String>;
78

89
fn do_test(data: &[u8]) {

0 commit comments

Comments
 (0)