Skip to content

Enable test with --no-default-features #386

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 7 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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ rand = { version = "0.6", features = ["wasm-bindgen"] }

[[example]]
name = "sign_verify_recovery"
required-features = ["recovery"]
required-features = ["std", "recovery"]

[[example]]
name = "sign_verify"
required-features = ["std"]

[[example]]
name = "generate_keys"
required-features = ["rand"]
required-features = ["std", "rand-std"]

[workspace]
members = ["secp256k1-sys"]
Expand Down
16 changes: 8 additions & 8 deletions contrib/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh -ex

FEATURES="bitcoin_hashes global-context lowmemory rand rand-std recovery serde"
# TODO: Add "alloc" once we bump MSRV to past 1.29
FEATURES="bitcoin_hashes global-context lowmemory rand rand-std recovery serde std"

# Use toolchain if explicitly specified
if [ -n "$TOOLCHAIN" ]
Expand All @@ -20,17 +21,16 @@ cargo test --all

if [ "$DO_FEATURE_MATRIX" = true ]; then
cargo build --all --no-default-features
#This doesn't work but probably should --andrew
#cargo test --all --no-default-features
cargo test --all --no-default-features

# 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"
done

# Other combos
Expand All @@ -45,9 +45,9 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
fi

# Examples
cargo run --example sign_verify
cargo run --example sign_verify_recovery --features=recovery
cargo run --example generate_keys --features=rand
cargo run --example sign_verify --features=std
cargo run --example sign_verify_recovery --features=std,recovery
cargo run --example generate_keys --features=std,rand-std
fi

# Docs
Expand Down
4 changes: 2 additions & 2 deletions secp256k1-sys/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(non_camel_case_types)]
use core::{fmt, mem};
use core::fmt;

pub type c_int = i32;
pub type c_uchar = u8;
Expand Down Expand Up @@ -46,7 +46,7 @@ impl AlignedType {
}

#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
pub(crate) const ALIGN_TO: usize = mem::align_of::<AlignedType>();
pub(crate) const ALIGN_TO: usize = ::core::mem::align_of::<AlignedType>();

#[cfg(test)]
mod tests {
Expand Down
3 changes: 2 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Secp256k1;
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
pub use self::alloc_only::*;

#[cfg(feature = "global-context-less-secure")]
#[cfg(all(feature = "global-context-less-secure", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "global-context", feature = "global-context-less-secure"))))]
/// Module implementing a singleton pattern for a global `Secp256k1` context
pub mod global {
Expand All @@ -35,6 +35,7 @@ pub mod global {
impl Deref for GlobalContext {
type Target = Secp256k1<All>;

#[allow(unused_mut)] // Unused when "global-context" is not enabled.
fn deref(&self) -> &Self::Target {
static ONCE: Once = Once::new();
static mut CONTEXT: Option<Secp256k1<All>> = None;
Expand Down
7 changes: 6 additions & 1 deletion src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl SharedSecret {
/// `SharedSecret` can be easily created via the `From` impl from arrays.
/// # Examples
/// ```
/// # #[cfg(any(feature = "alloc", features = "std"))] {
/// # use secp256k1::ecdh::SharedSecret;
/// # use secp256k1::{Secp256k1, PublicKey, SecretKey};
/// # fn sha2(_a: &[u8], _b: &[u8]) -> [u8; 32] {[0u8; 32]}
Expand All @@ -139,7 +140,7 @@ impl SharedSecret {
/// let hash: [u8; 32] = sha2(&x,&y);
/// hash.into()
/// });
///
/// # }
/// ```
pub fn new_with_hash<F>(point: &PublicKey, scalar: &SecretKey, mut hash_function: F) -> SharedSecret
where F: FnMut([u8; 32], [u8; 32]) -> SharedSecret {
Expand Down Expand Up @@ -168,6 +169,7 @@ impl SharedSecret {
}

#[cfg(test)]
#[allow(unused_imports)]
mod tests {
use super::*;
use rand::thread_rng;
Expand All @@ -177,6 +179,7 @@ mod tests {
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn ecdh() {
let s = Secp256k1::signing_only();
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
Expand All @@ -190,6 +193,7 @@ mod tests {
}

#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn ecdh_with_hash() {
let s = Secp256k1::signing_only();
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
Expand All @@ -203,6 +207,7 @@ mod tests {
}

#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn ecdh_with_hash_callback() {
let s = Secp256k1::signing_only();
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
Expand Down
4 changes: 2 additions & 2 deletions src/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl<C: Verification> Secp256k1<C> {
/// verify-capable context.
///
/// ```rust
/// # #[cfg(feature="rand")] {
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
/// # use secp256k1::rand::rngs::OsRng;
/// # use secp256k1::{Secp256k1, Message, Error};
/// #
Expand Down Expand Up @@ -460,7 +460,7 @@ impl<C: Verification> Secp256k1<C> {
/// verify-capable context.
///
/// ```rust
/// # #[cfg(feature="rand")] {
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
/// # use secp256k1::rand::rngs::OsRng;
/// # use secp256k1::{Secp256k1, Message, Error};
/// #
Expand Down
6 changes: 6 additions & 0 deletions src/ecdsa/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ impl<C: Verification> Secp256k1<C> {


#[cfg(test)]
#[allow(unused_imports)]
mod tests {
use super::*;
use rand::{RngCore, thread_rng};
Expand All @@ -210,6 +211,7 @@ mod tests {
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn capabilities() {
let sign = Secp256k1::signing_only();
let vrfy = Secp256k1::verification_only();
Expand Down Expand Up @@ -243,6 +245,7 @@ mod tests {

#[test]
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn sign() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
Expand All @@ -266,6 +269,7 @@ mod tests {
}

#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn sign_and_verify_fail() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
Expand All @@ -289,6 +293,7 @@ mod tests {
}

#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn sign_with_recovery() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
Expand All @@ -305,6 +310,7 @@ mod tests {
}

#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
fn bad_recovery() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
Expand Down
Loading