testing: add a fake_crypto feature

This commit is contained in:
Michael Sproul
2019-04-02 17:51:12 +11:00
parent 300fcd6ec3
commit 71a0fed8eb
6 changed files with 50 additions and 27 deletions

View File

@@ -13,3 +13,6 @@ serde_derive = "1.0"
serde_hex = { path = "../serde_hex" }
ssz = { path = "../ssz" }
tree_hash = { path = "../tree_hash" }
[features]
fake_crypto = []

19
eth2/utils/bls/build.rs Normal file
View File

@@ -0,0 +1,19 @@
// This build script is symlinked from each project that requires BLS's "fake crypto",
// so that the `fake_crypto` feature of every sub-crate can be turned on by running
// with FAKE_CRYPTO=1 from the top-level workspace.
// At some point in the future it might be possible to do:
// $ cargo test --all --release --features fake_crypto
// but at the present time this doesn't work.
// Related: https://github.com/rust-lang/cargo/issues/5364
fn main() {
if let Ok(fake_crypto) = std::env::var("FAKE_CRYPTO") {
if fake_crypto == "1" {
println!("cargo:rustc-cfg=feature=\"fake_crypto\"");
println!("cargo:rerun-if-env-changed=FAKE_CRYPTO");
println!(
"cargo:warning=[{}]: Compiled with fake BLS cryptography. DO NOT USE, TESTING ONLY",
std::env::var("CARGO_PKG_NAME").unwrap()
);
}
}
}

View File

@@ -6,22 +6,22 @@ mod keypair;
mod public_key;
mod secret_key;
#[cfg(not(debug_assertions))]
#[cfg(not(feature = "fake_crypto"))]
mod aggregate_signature;
#[cfg(not(debug_assertions))]
#[cfg(not(feature = "fake_crypto"))]
mod signature;
#[cfg(not(debug_assertions))]
#[cfg(not(feature = "fake_crypto"))]
pub use crate::aggregate_signature::AggregateSignature;
#[cfg(not(debug_assertions))]
#[cfg(not(feature = "fake_crypto"))]
pub use crate::signature::Signature;
#[cfg(debug_assertions)]
#[cfg(feature = "fake_crypto")]
mod fake_aggregate_signature;
#[cfg(debug_assertions)]
#[cfg(feature = "fake_crypto")]
mod fake_signature;
#[cfg(debug_assertions)]
#[cfg(feature = "fake_crypto")]
pub use crate::fake_aggregate_signature::FakeAggregateSignature as AggregateSignature;
#[cfg(debug_assertions)]
#[cfg(feature = "fake_crypto")]
pub use crate::fake_signature::FakeSignature as Signature;
pub use crate::aggregate_public_key::AggregatePublicKey;