Skip to content

Various fixes for Nix compatibility #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ required-features = ["compiler","std"]
[[example]]
name = "psbt_sign_finalize"
required-features = ["std", "base64"]

[workspace]
members = ["bitcoind-tests", "fuzz"]
exclude = ["embedded"]
3 changes: 2 additions & 1 deletion bitcoind-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ name = "bitcoind-tests"
version = "0.1.0"
authors = ["sanket1729 <[email protected]>"]
edition = "2018"
publish = false

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

[dependencies]
miniscript = {path = "../"}
bitcoind = { version = "0.29.3" }
actual-rand = { package = "rand", version = "0.8.4"}
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
17 changes: 14 additions & 3 deletions bitcoind-tests/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ pub mod test_util;
pub fn setup() -> BitcoinD {
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
let key = "BITCOIND_EXE";
let curr_dir_path = std::env::current_dir().unwrap();
let bitcoind_path = curr_dir_path.join("bin").join("bitcoind");
std::env::set_var(key, bitcoind_path);
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();
Expand Down
5 changes: 2 additions & 3 deletions bitcoind-tests/tests/setup/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@

use std::str::FromStr;

use miniscript::bitcoin;
use actual_rand as rand;
use bitcoin::hashes::hex::ToHex;
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
use bitcoin::secp256k1;
use miniscript::descriptor::{SinglePub, SinglePubKey};
use miniscript::{
hash256, Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext, TranslatePk,
Translator,
bitcoin, hash256, Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext,
TranslatePk, Translator,
};
use rand::RngCore;

Expand Down
3 changes: 1 addition & 2 deletions bitcoind-tests/tests/test_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use bitcoin::util::psbt;
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
use bitcoin::{Amount, LockTime, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid};
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
use miniscript::bitcoin;
use miniscript::psbt::PsbtExt;
use miniscript::Descriptor;
use miniscript::{bitcoin, Descriptor};

mod setup;
use setup::test_util::{self, PubData, TestData};
Expand Down
7 changes: 3 additions & 4 deletions bitcoind-tests/tests/test_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use std::collections::BTreeMap;
use std::{error, fmt};

use miniscript::bitcoin;
use actual_rand as rand;
use bitcoin::blockdata::witness::Witness;
use bitcoin::hashes::{sha256d, Hash};
Expand All @@ -16,12 +15,12 @@ use bitcoin::util::sighash::SighashCache;
use bitcoin::util::taproot::{LeafVersion, TapLeafHash};
use bitcoin::util::{psbt, sighash};
use bitcoin::{
secp256k1, Amount, LockTime, OutPoint, SchnorrSig, Script, Sequence, Transaction, TxIn,
TxOut, Txid,
secp256k1, Amount, LockTime, OutPoint, SchnorrSig, Script, Sequence, Transaction, TxIn, TxOut,
Txid,
};
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
use miniscript::psbt::{PsbtExt, PsbtInputExt};
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
use miniscript::{bitcoin, Descriptor, Miniscript, ScriptContext, ToPublicKey};
mod setup;

use rand::RngCore;
Expand Down
1 change: 1 addition & 0 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fi
# Test bitcoind integration tests if told to (this only works with the stable toolchain)
if [ "$DO_BITCOIND_TESTS" = true ]; then
cd bitcoind-tests
BITCOIND_EXE="$(git rev-parse --show-toplevel)/bitcoind-tests/bin/bitcoind" \
cargo test --verbose

# Exit integration tests, do not run other tests.
Expand Down
3 changes: 2 additions & 1 deletion embedded/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
readme = "README.md"
name = "embedded"
version = "0.1.0"
publish = false

[dependencies]
cortex-m = "0.6.0"
Expand All @@ -25,4 +26,4 @@ bench = false
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
opt-level = "z"
opt-level = "z"
4 changes: 1 addition & 3 deletions embedded/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ extern crate alloc;
use alloc::string::ToString;
use core::alloc::Layout;
use core::panic::PanicInfo;

use alloc_cortex_m::CortexMHeap;

use core::str::FromStr;

use alloc_cortex_m::CortexMHeap;
use cortex_m::asm;
use cortex_m_rt::entry;
use cortex_m_semihosting::{debug, hprintln};
Expand Down
6 changes: 1 addition & 5 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ afl_fuzz = ["afl"]
honggfuzz_fuzz = ["honggfuzz"]

[dependencies]
honggfuzz = { version = "0.5", default-features = false, optional = true }
honggfuzz = { version = "0.5.55", default-features = false, optional = true }
afl = { version = "0.8", optional = true }
regex = { version = "1.4"}
miniscript = { path = "..", features = ["compiler"] }

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[[bin]]
name = "roundtrip_descriptor"
path = "fuzz_targets/roundtrip_descriptor.rs"
Expand Down
12 changes: 7 additions & 5 deletions fuzz/fuzz_targets/compile_descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
extern crate miniscript;

use miniscript::Segwitv0;
use miniscript::{policy, Miniscript};
use policy::Liftable;

use std::str::FromStr;

use miniscript::{policy, Miniscript, Segwitv0};
use policy::Liftable;

type Script = Miniscript<String, Segwitv0>;
type Policy = policy::Concrete<String>;

Expand All @@ -15,7 +14,10 @@ fn do_test(data: &[u8]) {
// Compile
if let Ok(desc) = pol.compile::<Segwitv0>() {
// Lift
assert_eq!(desc.clone().lift().unwrap().sorted(), pol.clone().lift().unwrap().sorted());
assert_eq!(
desc.clone().lift().unwrap().sorted(),
pol.clone().lift().unwrap().sorted()
);
// Try to roundtrip the output of the compiler
let output = desc.to_string();
if let Ok(desc) = Script::from_str(&output) {
Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/parse_descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extern crate miniscript;

use miniscript::DescriptorPublicKey;
use std::str::FromStr;

use miniscript::DescriptorPublicKey;

fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);
if let Ok(dpk) = DescriptorPublicKey::from_str(&data_str) {
Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/parse_descriptor_secret.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extern crate miniscript;

use miniscript::descriptor::DescriptorSecretKey;
use std::str::FromStr;

use miniscript::descriptor::DescriptorSecretKey;

fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);
if let Ok(dsk) = DescriptorSecretKey::from_str(&data_str) {
Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/roundtrip_concrete.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extern crate miniscript;
extern crate regex;
use std::str::FromStr;

use miniscript::policy;
use regex::Regex;
use std::str::FromStr;

type Policy = policy::Concrete<String>;

Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/roundtrip_descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
extern crate miniscript;
extern crate regex;

use std::str::FromStr;

use miniscript::Descriptor;
use regex::Regex;
use std::str::FromStr;

fn do_test(data: &[u8]) {
let s = String::from_utf8_lossy(data);
Expand Down
3 changes: 1 addition & 2 deletions fuzz/fuzz_targets/roundtrip_miniscript_script.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate miniscript;

use miniscript::bitcoin::blockdata::script;
use miniscript::Miniscript;
use miniscript::Segwitv0;
use miniscript::{Miniscript, Segwitv0};

fn do_test(data: &[u8]) {
// Try round-tripping as a script
Expand Down
5 changes: 2 additions & 3 deletions fuzz/fuzz_targets/roundtrip_miniscript_str.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
extern crate miniscript;
extern crate regex;

use regex::Regex;
use std::str::FromStr;

use miniscript::Miniscript;
use miniscript::Segwitv0;
use miniscript::{Miniscript, Segwitv0};
use regex::Regex;

fn do_test(data: &[u8]) {
let s = String::from_utf8_lossy(data);
Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/roundtrip_semantic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extern crate miniscript;

use miniscript::policy;
use std::str::FromStr;

use miniscript::policy;

type Policy = policy::Semantic<String>;

fn do_test(data: &[u8]) {
Expand Down