Fix failing tests

This commit is contained in:
Paul Hauner 2019-01-26 22:22:52 +11:00
parent 7ee836d118
commit 22a08e5160
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
4 changed files with 23 additions and 14 deletions

View File

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

View File

@ -4,17 +4,19 @@ use types::ChainSpec;
mod utils;
#[test]
#[ignore]
fn it_can_produce_blocks() {
let validator_count = 2;
let blocks = 3;
let mut rig = TestRig::new(ChainSpec::foundation(), validator_count);
let blocks = rig.spec.epoch_length + 1;
for _ in 0..blocks {
rig.produce_next_slot();
}
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);
}

View File

@ -19,6 +19,7 @@ pub struct TestRig {
block_store: Arc<BeaconBlockStore<MemoryDB>>,
state_store: Arc<BeaconStateStore<MemoryDB>>,
validators: Vec<TestValidator>,
pub spec: ChainSpec,
}
impl TestRig {
@ -50,8 +51,13 @@ impl TestRig {
// Create the Beacon Chain
let beacon_chain = Arc::new(
BeaconChain::genesis(state_store.clone(), block_store.clone(), slot_clock, spec)
.unwrap(),
BeaconChain::genesis(
state_store.clone(),
block_store.clone(),
slot_clock,
spec.clone(),
)
.unwrap(),
);
// Spawn the test validator instances.
@ -66,6 +72,7 @@ impl TestRig {
block_store,
state_store,
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_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![],
batched_block_roots: vec![],
/*
@ -193,9 +193,9 @@ mod tests {
assert_eq!(*block, Hash256::zero());
}
// Test latest_penalized_exit_balances
assert_eq!(state.latest_penalized_exit_balances.len(), 8_192);
for item in state.latest_penalized_exit_balances.iter() {
// Test latest_penalized_balances
assert_eq!(state.latest_penalized_balances.len(), 8_192);
for item in state.latest_penalized_balances.iter() {
assert!(*item == 0);
}