Fix failing tests

This commit is contained in:
Paul Hauner
2019-01-26 22:22:52 +11:00
parent 7ee836d118
commit 22a08e5160
4 changed files with 23 additions and 14 deletions

View File

@@ -240,11 +240,7 @@ where
ensure!( ensure!(
attestation.data.justified_block_root attestation.data.justified_block_root
== *state == *state
.get_block_root( .get_block_root(attestation.data.justified_slot, &self.spec)
&state,
attestation.data.justified_slot,
self.spec.latest_block_roots_length
)
.ok_or(Error::NoBlockRoot)?, .ok_or(Error::NoBlockRoot)?,
Error::BadAttestation Error::BadAttestation
); );
@@ -364,6 +360,10 @@ where
Error::BadCustodyResponses Error::BadCustodyResponses
); );
if state.slot % self.spec.epoch_length == 0 {
state.per_epoch_processing(&self.spec);
}
Ok(state) Ok(state)
} }
} }

View File

@@ -4,17 +4,19 @@ use types::ChainSpec;
mod utils; mod utils;
#[test] #[test]
#[ignore]
fn it_can_produce_blocks() { fn it_can_produce_blocks() {
let validator_count = 2; let validator_count = 2;
let blocks = 3;
let mut rig = TestRig::new(ChainSpec::foundation(), validator_count); let mut rig = TestRig::new(ChainSpec::foundation(), validator_count);
let blocks = rig.spec.epoch_length + 1;
for _ in 0..blocks { for _ in 0..blocks {
rig.produce_next_slot(); rig.produce_next_slot();
} }
let dump = rig.chain_dump().expect("Chain dump failed."); let dump = rig.chain_dump().expect("Chain dump failed.");
assert_eq!(dump.len(), blocks + 1); // + 1 for genesis block. assert_eq!(dump.len() as u64, blocks + 1); // + 1 for genesis block.
rig.dump_to_file("/tmp/chaindump.json".to_string(), &dump); rig.dump_to_file("/tmp/chaindump.json".to_string(), &dump);
} }

View File

@@ -19,6 +19,7 @@ pub struct TestRig {
block_store: Arc<BeaconBlockStore<MemoryDB>>, block_store: Arc<BeaconBlockStore<MemoryDB>>,
state_store: Arc<BeaconStateStore<MemoryDB>>, state_store: Arc<BeaconStateStore<MemoryDB>>,
validators: Vec<TestValidator>, validators: Vec<TestValidator>,
pub spec: ChainSpec,
} }
impl TestRig { impl TestRig {
@@ -50,8 +51,13 @@ impl TestRig {
// Create the Beacon Chain // Create the Beacon Chain
let beacon_chain = Arc::new( let beacon_chain = Arc::new(
BeaconChain::genesis(state_store.clone(), block_store.clone(), slot_clock, spec) BeaconChain::genesis(
.unwrap(), state_store.clone(),
block_store.clone(),
slot_clock,
spec.clone(),
)
.unwrap(),
); );
// Spawn the test validator instances. // Spawn the test validator instances.
@@ -66,6 +72,7 @@ impl TestRig {
block_store, block_store,
state_store, state_store,
validators, validators,
spec,
} }
} }

View File

@@ -73,7 +73,7 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
*/ */
latest_crosslinks: vec![initial_crosslink; spec.shard_count as usize], latest_crosslinks: vec![initial_crosslink; spec.shard_count as usize],
latest_block_roots: vec![spec.zero_hash; spec.latest_block_roots_length as usize], latest_block_roots: vec![spec.zero_hash; spec.latest_block_roots_length as usize],
latest_penalized_exit_balances: vec![0; spec.latest_penalized_exit_length as usize], latest_penalized_balances: vec![0; spec.latest_penalized_exit_length as usize],
latest_attestations: vec![], latest_attestations: vec![],
batched_block_roots: vec![], batched_block_roots: vec![],
/* /*
@@ -193,9 +193,9 @@ mod tests {
assert_eq!(*block, Hash256::zero()); assert_eq!(*block, Hash256::zero());
} }
// Test latest_penalized_exit_balances // Test latest_penalized_balances
assert_eq!(state.latest_penalized_exit_balances.len(), 8_192); assert_eq!(state.latest_penalized_balances.len(), 8_192);
for item in state.latest_penalized_exit_balances.iter() { for item in state.latest_penalized_balances.iter() {
assert!(*item == 0); assert!(*item == 0);
} }