mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-01 00:41:20 +00:00
Add skip_slots to test_harness yaml processor
This commit is contained in:
parent
8b06fa31da
commit
1479013bd0
@ -8,6 +8,7 @@ test_cases:
|
|||||||
epoch_length: 64
|
epoch_length: 64
|
||||||
deposits_for_chain_start: 1000
|
deposits_for_chain_start: 1000
|
||||||
num_slots: 32 # Testing advancing state to slot < SlotsPerEpoch
|
num_slots: 32 # Testing advancing state to slot < SlotsPerEpoch
|
||||||
|
skip_slots: [2, 3]
|
||||||
results:
|
results:
|
||||||
slot: 32
|
slot: 32
|
||||||
num_validators: 1000
|
num_validators: 1000
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use self::beacon_chain_harness::BeaconChainHarness;
|
use self::beacon_chain_harness::BeaconChainHarness;
|
||||||
use self::validator_harness::ValidatorHarness;
|
use self::validator_harness::ValidatorHarness;
|
||||||
|
use beacon_chain::CheckPoint;
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use env_logger::{Builder, Env};
|
use env_logger::{Builder, Env};
|
||||||
use log::info;
|
use log::{info, warn};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::{fs::File, io::prelude::*};
|
use std::{fs::File, io::prelude::*};
|
||||||
use types::*;
|
use types::*;
|
||||||
use yaml_rust::{Yaml, YamlLoader};
|
use yaml_rust::{Yaml, YamlLoader};
|
||||||
@ -39,7 +41,7 @@ fn main() {
|
|||||||
for doc in &docs {
|
for doc in &docs {
|
||||||
for test_case in doc["test_cases"].as_vec().unwrap() {
|
for test_case in doc["test_cases"].as_vec().unwrap() {
|
||||||
let manifest = Manifest::from_yaml(test_case);
|
let manifest = Manifest::from_yaml(test_case);
|
||||||
manifest.execute();
|
manifest.assert_result_valid(manifest.execute())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,7 +70,7 @@ impl Manifest {
|
|||||||
spec
|
spec
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(&self) {
|
pub fn execute(&self) -> ExecutionResult {
|
||||||
let spec = self.spec();
|
let spec = self.spec();
|
||||||
let validator_count = self.config.deposits_for_chain_start;
|
let validator_count = self.config.deposits_for_chain_start;
|
||||||
let slots = self.results.slot;
|
let slots = self.results.slot;
|
||||||
@ -82,18 +84,47 @@ impl Manifest {
|
|||||||
|
|
||||||
info!("Starting simulation across {} slots...", slots);
|
info!("Starting simulation across {} slots...", slots);
|
||||||
|
|
||||||
for _ in 0..self.results.slot {
|
for slot_height in 0..self.results.slot {
|
||||||
|
match self.config.skip_slots {
|
||||||
|
Some(ref skip_slots) if skip_slots.contains(&slot_height) => {
|
||||||
|
warn!("Skipping slot at height {}.", slot_height);
|
||||||
|
harness.increment_beacon_chain_slot();
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
info!("Producing block at slot height {}.", slot_height);
|
||||||
harness.advance_chain_with_block();
|
harness.advance_chain_with_block();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
harness.run_fork_choice();
|
harness.run_fork_choice();
|
||||||
|
|
||||||
let dump = harness.chain_dump().expect("Chain dump failed.");
|
info!("Test execution complete!");
|
||||||
|
|
||||||
assert_eq!(dump.len() as u64, slots + 1); // + 1 for genesis block.
|
ExecutionResult {
|
||||||
|
chain: harness.chain_dump().expect("Chain dump failed."),
|
||||||
// harness.dump_to_file("/tmp/chaindump.json".to_string(), &dump);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn assert_result_valid(&self, result: ExecutionResult) {
|
||||||
|
info!("Verifying test results...");
|
||||||
|
|
||||||
|
if let Some(ref skip_slots) = self.config.skip_slots {
|
||||||
|
for checkpoint in result.chain {
|
||||||
|
let block_slot = checkpoint.beacon_block.slot.as_u64();
|
||||||
|
assert!(
|
||||||
|
!skip_slots.contains(&block_slot),
|
||||||
|
"Slot {} was not skipped.",
|
||||||
|
block_slot
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info!("OK: Skipped slots not present in chain.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ExecutionResult {
|
||||||
|
pub chain: Vec<CheckPoint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Results {
|
struct Results {
|
||||||
@ -117,6 +148,7 @@ impl Results {
|
|||||||
struct Config {
|
struct Config {
|
||||||
pub deposits_for_chain_start: usize,
|
pub deposits_for_chain_start: usize,
|
||||||
pub epoch_length: Option<u64>,
|
pub epoch_length: Option<u64>,
|
||||||
|
pub skip_slots: Option<Vec<u64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -125,6 +157,7 @@ impl Config {
|
|||||||
deposits_for_chain_start: as_usize(&yaml, "deposits_for_chain_start")
|
deposits_for_chain_start: as_usize(&yaml, "deposits_for_chain_start")
|
||||||
.expect("Must specify validator count"),
|
.expect("Must specify validator count"),
|
||||||
epoch_length: as_u64(&yaml, "epoch_length"),
|
epoch_length: as_u64(&yaml, "epoch_length"),
|
||||||
|
skip_slots: as_vec_u64(yaml, "skip_slots"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user