Add tests and benches for epoch processing
This commit is contained in:
parent
53663e54b5
commit
906131f882
@ -4,6 +4,15 @@ version = "0.1.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[[bench]]
|
||||
name = "benches"
|
||||
harness = false
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.2"
|
||||
test_harness = { path = "../../beacon_node/beacon_chain/test_harness" }
|
||||
env_logger = "0.6.0"
|
||||
|
||||
[dependencies]
|
||||
hashing = { path = "../utils/hashing" }
|
||||
int_to_bytes = { path = "../utils/int_to_bytes" }
|
||||
|
28
eth2/state_processing/benches/benches.rs
Normal file
28
eth2/state_processing/benches/benches.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use criterion::Criterion;
|
||||
use criterion::{black_box, criterion_group, criterion_main};
|
||||
// use env_logger::{Builder, Env};
|
||||
use state_processing::SlotProcessable;
|
||||
use types::{beacon_state::BeaconStateBuilder, ChainSpec, Hash256};
|
||||
|
||||
fn epoch_processing(c: &mut Criterion) {
|
||||
// Builder::from_env(Env::default().default_filter_or("debug")).init();
|
||||
|
||||
let mut builder = BeaconStateBuilder::with_random_validators(8);
|
||||
builder.spec = ChainSpec::few_validators();
|
||||
|
||||
builder.genesis().unwrap();
|
||||
builder.teleport_to_end_of_epoch(builder.spec.genesis_epoch + 4);
|
||||
|
||||
let state = builder.build().unwrap();
|
||||
|
||||
c.bench_function("epoch processing", move |b| {
|
||||
let spec = &builder.spec;
|
||||
b.iter_with_setup(
|
||||
|| state.clone(),
|
||||
|mut state| black_box(state.per_slot_processing(Hash256::zero(), spec).unwrap()),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, epoch_processing,);
|
||||
criterion_main!(benches);
|
@ -9,6 +9,8 @@ use types::{
|
||||
Crosslink, Epoch, Hash256, InclusionError, PendingAttestation, RelativeEpoch,
|
||||
};
|
||||
|
||||
mod tests;
|
||||
|
||||
macro_rules! safe_add_assign {
|
||||
($a: expr, $b: expr) => {
|
||||
$a = $a.saturating_add($b);
|
||||
@ -725,11 +727,3 @@ impl From<BeaconStateError> for WinningRootError {
|
||||
WinningRootError::BeaconStateError(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
|
21
eth2/state_processing/src/epoch_processable/tests.rs
Normal file
21
eth2/state_processing/src/epoch_processable/tests.rs
Normal file
@ -0,0 +1,21 @@
|
||||
#![cfg(test)]
|
||||
use crate::EpochProcessable;
|
||||
use env_logger::{Builder, Env};
|
||||
use types::beacon_state::BeaconStateBuilder;
|
||||
use types::*;
|
||||
|
||||
#[test]
|
||||
fn runs_without_error() {
|
||||
Builder::from_env(Env::default().default_filter_or("error")).init();
|
||||
|
||||
let mut builder = BeaconStateBuilder::with_random_validators(8);
|
||||
builder.spec = ChainSpec::few_validators();
|
||||
|
||||
builder.genesis().unwrap();
|
||||
builder.teleport_to_end_of_epoch(builder.spec.genesis_epoch + 4);
|
||||
|
||||
let mut state = builder.build().unwrap();
|
||||
|
||||
let spec = &builder.spec;
|
||||
state.per_epoch_processing(spec).unwrap();
|
||||
}
|
Loading…
Reference in New Issue
Block a user