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
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
6 changed files with 50 additions and 27 deletions

View File

@ -30,3 +30,6 @@ tree_hash = { path = "../utils/tree_hash" }
tree_hash_derive = { path = "../utils/tree_hash_derive" }
types = { path = "../types" }
rayon = "1.0"
[features]
fake_crypto = ["bls/fake_crypto"]

View File

@ -0,0 +1 @@
../utils/bls/build.rs

View File

@ -47,31 +47,28 @@ fn run_state_transition_test(test_name: &str) {
// Run Tests
let mut ok = true;
for (i, test_case) in doc.test_cases.iter().enumerate() {
let fake_crypto = cfg!(feature = "fake_crypto");
if !test_case.verify_signatures == fake_crypto {
println!("Running {}", test_case.name);
} else {
println!(
"Skipping {} (fake_crypto: {}, need fake: {})",
test_case.name, fake_crypto, !test_case.verify_signatures
);
continue;
}
let mut state = test_case.initial_state.clone();
for (j, block) in test_case.blocks.iter().enumerate() {
while block.slot > state.slot {
let latest_block_header = state.latest_block_header.clone();
per_slot_processing(&mut state, &latest_block_header, &test_case.config).unwrap();
}
if test_case.verify_signatures {
let res = per_block_processing(&mut state, &block, &test_case.config);
if res.is_err() {
println!("Error in {} (#{}), on block {}", test_case.name, i, j);
println!("{:?}", res);
ok = false;
};
} else {
let res = per_block_processing_without_verifying_block_signature(
&mut state,
&block,
&test_case.config,
);
if res.is_err() {
println!("Error in {} (#{}), on block {}", test_case.name, i, j);
println!("{:?}", res);
ok = false;
}
}
let res = per_block_processing(&mut state, &block, &test_case.config);
if res.is_err() {
println!("Error in {} (#{}), on block {}", test_case.name, i, j);
println!("{:?}", res);
ok = false;
};
}
}

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;