Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Improve feature coverage in CI test suite #147

Merged
merged 5 commits into from
Feb 3, 2022
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ serde-std = ["serde/std"]
unstable = [] # for benchmarking

[dependencies]
# Only enable this if you explicitly do not want to use "std", otherwise enable "serde-std".
serde = { version = "1.0", default-features = false, optional = true }
# Can only be used with "std" enabled.
schemars = { version = "<=0.8.3", optional = true }
# Only enable this if you explicitly do not want to use an allocator, otherwise enable "alloc".
core2 = { version = "0.3.0", optional = true, default_features = false }

[dev-dependencies]
Expand Down
14 changes: 8 additions & 6 deletions contrib/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh -ex

# TODO: Add core2 here once we bump MSRV past 1.29
FEATURES="serde serde-std std"

if [ "$DO_ALLOC_TESTS" = true ]; then
Expand Down Expand Up @@ -28,21 +29,22 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then

# All features
cargo build --all --no-default-features --features="$FEATURES"
cargo test --all --features="$FEATURES"
cargo test --all --no-default-features --features="$FEATURES"
# Single features
for feature in ${FEATURES}
do
cargo build --all --no-default-features --features="$feature"
cargo test --all --features="$feature"
cargo test --all --no-default-features --features="$feature"
# All combos of two features
for featuretwo in ${FEATURES}; do
cargo build --all --no-default-features --features="$feature $featuretwo"
cargo test --all --features="$feature $featuretwo"
cargo test --all --no-default-features --features="$feature $featuretwo"
done
done

# Other combos
cargo test --all --features="serde-std"
# TODO: Add this test once we bump MSRV past 1.29
# cargo test --all --no-default-features --features="std,schemars"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In af992d7:

Did you intend to comment out this line? From your commit message it sounds like you do intend to test std and schemars.

We definitely need schemars to be tested in CI somehow. Historically we have had breakage from this dependency that went undetected by CI. (This is why, incidentally, I worte all my own independent CI scripts, and also why schemars is not a dependency in any other rust-bitcoin crate.)

Copy link
Member Author

@tcharding tcharding Feb 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shit, I've been a bit sloppy lately fixing commit messages when re-basing. I'm still struggling big time with Rust 1.29, I have some shell functions to build with 1.29 but I often forget to use them because they are not well tied in with my editor ... so I'm constantly re-basing and getting punished by CI. You might have noticed all the force pushes in my PRs :) I'm being lazy, we are so close to bumping to 1.41

We have extended_tests which test bitcoin_hashes with serde, schemars, and std enabled. The schemars feature doesn't build on its own at the moment cargo check --no-default-features --features=schemars fails. I didn't investigate why I just added this comment to remind us.

I added this commented out line with the MSRV comment since I've seen that done in a few places and have started doing it. Now as I write this message I think it would be better to add all these to the edition 2018 tracking issue instead of leaving it in the code. Oh that's right, the tracking issue is not on this repo its on rust-bitcoin.

Will fix the commit log.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good observation that we'll be bumping to 1.41.0 soon, and at that point we can put schemars into the normal CI pipeline.

fi

if [ "$DO_SCHEMARS_TESTS" = true ]; then
Expand All @@ -69,11 +71,11 @@ if [ "$DO_ASAN" = true ]; then
CC='clang -fsanitize=address -fno-omit-frame-pointer' \
RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
cargo test --lib --all --no-default-features --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
cargo clean
CC='clang -fsanitize=memory -fno-omit-frame-pointer' \
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes' \
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
cargo test --lib --all --no-default-features --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
fi

# Bench
Expand Down
26 changes: 13 additions & 13 deletions src/hash160.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ impl HashTrait for Hash {

#[cfg(test)]
mod tests {
use hash160;
use hex::{FromHex, ToHex};
use Hash;
use HashEngine;

#[derive(Clone)]
struct Test {
input: Vec<u8>,
output: Vec<u8>,
output_str: &'static str,
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test() {
use {hash160, Hash, HashEngine};
use hex::{FromHex, ToHex};

#[derive(Clone)]
#[cfg(any(feature = "std", feature = "alloc"))]
struct Test {
input: Vec<u8>,
output: Vec<u8>,
output_str: &'static str,
}

let tests = vec![
// Uncompressed pubkey obtained from Bitcoin key; data from validateaddress
Test {
Expand Down Expand Up @@ -161,8 +161,8 @@ mod tests {
#[cfg(feature = "serde")]
#[test]
fn ripemd_serde() {

use serde_test::{Configure, Token, assert_tokens};
use {hash160, Hash};

static HASH_BYTES: [u8; 20] = [
0x13, 0x20, 0x72, 0xdf,
Expand Down
2 changes: 2 additions & 0 deletions src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ mod tests {
use core::fmt;

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn hex_roundtrip() {
let expected = "0123456789abcdef";
let expected_up = "0123456789ABCDEF";
Expand Down Expand Up @@ -361,6 +362,7 @@ mod tests {
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn hex_error() {
let oddlen = "0123456789abcdef0";
let badchar1 = "Z123456789abcdef";
Expand Down
22 changes: 11 additions & 11 deletions src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,18 @@ impl<'de, T: HashTrait + Deserialize<'de>> Deserialize<'de> for Hmac<T> {

#[cfg(test)]
mod tests {
use sha256;
#[cfg(feature = "serde")] use sha512;
use {Hash, HashEngine, Hmac, HmacEngine};

#[derive(Clone)]
struct Test {
key: Vec<u8>,
input: Vec<u8>,
output: Vec<u8>,
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test() {
use {sha256, HashEngine, HmacEngine, Hash, Hmac};

#[derive(Clone)]
struct Test {
key: Vec<u8>,
input: Vec<u8>,
output: Vec<u8>,
}

let tests = vec![
// Test vectors copied from libsecp256k1
// Sadly the RFC2104 test vectors all use MD5 as their underlying hash function,
Expand Down Expand Up @@ -369,6 +368,7 @@ mod tests {
#[test]
fn hmac_sha512_serde() {
use serde_test::{Configure, Token, assert_tokens};
use {sha512, Hash, Hmac};

static HASH_BYTES: [u8; 64] = [
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21,
Expand Down
25 changes: 13 additions & 12 deletions src/ripemd160.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,20 @@ impl HashEngine {

#[cfg(test)]
mod tests {
use ripemd160;
use hex::{FromHex, ToHex};
use Hash;
use HashEngine;

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test() {
use ripemd160;
use {Hash, HashEngine};
use hex::{FromHex, ToHex};

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

let tests = vec![
// Test messages from FIPS 180-1
Test {
Expand Down Expand Up @@ -545,6 +545,7 @@ mod tests {
#[test]
fn ripemd_serde() {
use serde_test::{Configure, Token, assert_tokens};
use {ripemd160, Hash};

static HASH_BYTES: [u8; 20] = [
0x13, 0x20, 0x72, 0xdf,
Expand Down
25 changes: 13 additions & 12 deletions src/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,20 @@ impl HashEngine {

#[cfg(test)]
mod tests {
use sha1;
use hex::{FromHex, ToHex};
use Hash;
use HashEngine;

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test() {
use {sha1, Hash, HashEngine};
use hex::{FromHex, ToHex};

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}


let tests = vec![
// Examples from wikipedia
Test {
Expand Down Expand Up @@ -270,6 +270,7 @@ mod tests {
#[test]
fn sha1_serde() {
use serde_test::{Configure, Token, assert_tokens};
use {sha1, Hash};

static HASH_BYTES: [u8; 20] = [
0x13, 0x20, 0x72, 0xdf,
Expand Down
18 changes: 10 additions & 8 deletions src/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,20 @@ impl HashEngine {
#[cfg(test)]
mod tests {
use sha256;
use hex::{FromHex, ToHex};
use {Hash, HashEngine};

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test() {
use hex::{FromHex, ToHex};

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

let tests = vec![
// Examples from wikipedia
Test {
Expand Down
24 changes: 12 additions & 12 deletions src/sha256d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,19 @@ impl HashTrait for Hash {

#[cfg(test)]
mod tests {
use sha256d;
use hex::{FromHex, ToHex};
use Hash;
use HashEngine;

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test() {
use {sha256d, Hash, HashEngine};
use hex::{FromHex, ToHex};

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

let tests = vec![
// Test vector copied out of rust-bitcoin
Test {
Expand Down Expand Up @@ -150,6 +149,7 @@ mod tests {
#[test]
fn sha256_serde() {
use serde_test::{Configure, Token, assert_tokens};
use {sha256d, Hash};

static HASH_BYTES: [u8; 32] = [
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7,
Expand Down
3 changes: 3 additions & 0 deletions src/sha256t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl<'de, T: Tag> ::serde::Deserialize<'de> for Hash<T> {
#[cfg(test)]
mod tests {
use ::{Hash, sha256, sha256t};
#[cfg(any(feature = "std", feature = "alloc"))]
use ::hex::ToHex;

const TEST_MIDSTATE: [u8; 32] = [
Expand All @@ -266,11 +267,13 @@ mod tests {
}

/// A hash tagged with `$name`.
#[cfg(any(feature = "std", feature = "alloc"))]
pub type TestHash = sha256t::Hash<TestHashTag>;

sha256t_hash_newtype!(NewTypeHash, NewTypeTag, TEST_MIDSTATE, 64, doc="test hash", true);

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test_sha256t() {
assert_eq!(
TestHash::hash(&[0]).to_hex(),
Expand Down
24 changes: 12 additions & 12 deletions src/sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,19 @@ impl HashEngine {

#[cfg(test)]
mod tests {
use sha512;
use hex::{FromHex, ToHex};
use Hash;
use HashEngine;

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

#[test]
#[cfg(any(feature = "std", feature = "alloc"))]
fn test() {
use {sha512, Hash, HashEngine};
use hex::{FromHex, ToHex};

#[derive(Clone)]
struct Test {
input: &'static str,
output: Vec<u8>,
output_str: &'static str,
}

let tests = vec![
// Test vectors computed with `sha512sum`
Test {
Expand Down Expand Up @@ -430,6 +429,7 @@ mod tests {
#[test]
fn sha512_serde() {
use serde_test::{Configure, Token, assert_tokens};
use {sha512, Hash};

static HASH_BYTES: [u8; 64] = [
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21,
Expand Down