Test corrections (#925)

* Merge #913

* Correct release tests

* Completed release test corrections
This commit is contained in:
Age Manning
2020-03-17 23:05:55 +11:00
committed by GitHub
parent 95c8e476bc
commit 41c3294c16
7 changed files with 71 additions and 38 deletions

View File

@@ -56,7 +56,7 @@ fn attestation_validity() {
.expect("should get at least one attestation");
assert_eq!(
chain.process_attestation(valid_attestation.clone()),
chain.process_attestation(valid_attestation.clone(), Some(false)),
Ok(AttestationProcessingOutcome::Processed),
"should accept valid attestation"
);
@@ -71,7 +71,7 @@ fn attestation_validity() {
assert_eq!(
harness
.chain
.process_attestation(epoch_mismatch_attestation),
.process_attestation(epoch_mismatch_attestation, Some(false)),
Ok(AttestationProcessingOutcome::BadTargetEpoch),
"should not accept attestation where the slot is not in the same epoch as the target"
);
@@ -85,7 +85,9 @@ fn attestation_validity() {
early_attestation.data.slot = (current_epoch + 1).start_slot(MainnetEthSpec::slots_per_epoch());
assert_eq!(
harness.chain.process_attestation(early_attestation),
harness
.chain
.process_attestation(early_attestation, Some(false)),
Ok(AttestationProcessingOutcome::FutureEpoch {
attestation_epoch: current_epoch + 1,
current_epoch
@@ -118,7 +120,9 @@ fn attestation_validity() {
.expect("should get at least one late attestation");
assert_eq!(
harness.chain.process_attestation(late_attestation),
harness
.chain
.process_attestation(late_attestation, Some(false)),
Ok(AttestationProcessingOutcome::PastEpoch {
attestation_epoch: current_epoch - 2,
current_epoch
@@ -134,7 +138,9 @@ fn attestation_validity() {
bad_target_attestation.data.target.root = Hash256::from_low_u64_be(42);
assert_eq!(
harness.chain.process_attestation(bad_target_attestation),
harness
.chain
.process_attestation(bad_target_attestation, Some(false)),
Ok(AttestationProcessingOutcome::UnknownTargetRoot(
Hash256::from_low_u64_be(42)
)),
@@ -149,7 +155,9 @@ fn attestation_validity() {
future_block_attestation.data.slot -= 1;
assert_eq!(
harness.chain.process_attestation(future_block_attestation),
harness
.chain
.process_attestation(future_block_attestation, Some(false)),
Ok(AttestationProcessingOutcome::AttestsToFutureBlock {
block: current_slot,
attestation: current_slot - 1
@@ -165,7 +173,9 @@ fn attestation_validity() {
bad_head_attestation.data.beacon_block_root = Hash256::from_low_u64_be(42);
assert_eq!(
harness.chain.process_attestation(bad_head_attestation),
harness
.chain
.process_attestation(bad_head_attestation, Some(false)),
Ok(AttestationProcessingOutcome::UnknownHeadBlock {
beacon_block_root: Hash256::from_low_u64_be(42)
}),
@@ -183,7 +193,9 @@ fn attestation_validity() {
bad_signature_attestation.signature = agg_sig;
assert_eq!(
harness.chain.process_attestation(bad_signature_attestation),
harness
.chain
.process_attestation(bad_signature_attestation, Some(false)),
Ok(AttestationProcessingOutcome::InvalidSignature),
"should not accept bad_signature attestation"
);
@@ -199,7 +211,7 @@ fn attestation_validity() {
assert_eq!(
harness
.chain
.process_attestation(empty_bitfield_attestation),
.process_attestation(empty_bitfield_attestation, Some(false)),
Ok(AttestationProcessingOutcome::EmptyAggregationBitfield),
"should not accept empty_bitfield attestation"
);
@@ -247,7 +259,7 @@ fn attestation_that_skips_epochs() {
.expect("should get at least one attestation");
assert_eq!(
harness.chain.process_attestation(attestation),
harness.chain.process_attestation(attestation, Some(false)),
Ok(AttestationProcessingOutcome::Processed),
"should process attestation that skips slots"
);

View File

@@ -306,7 +306,7 @@ fn epoch_boundary_state_attestation_processing() {
.epoch;
let res = harness
.chain
.process_attestation_internal(attestation.clone());
.process_attestation_internal(attestation.clone(), Some(true));
let current_epoch = harness.chain.epoch().expect("should get epoch");
let attestation_epoch = attestation.data.target.epoch;

View File

@@ -449,7 +449,7 @@ fn attestations_with_increasing_slots() {
for attestation in attestations {
let attestation_epoch = attestation.data.target.epoch;
let res = harness.chain.process_attestation(attestation);
let res = harness.chain.process_attestation(attestation, Some(false));
if attestation_epoch + 1 < current_epoch {
assert_eq!(

View File

@@ -1,15 +1,13 @@
use beacon_chain::BeaconChainTypes;
use eth2_libp2p::Enr;
use rlp;
use std::sync::Arc;
use store::Store;
use store::{DBColumn, Error as StoreError, SimpleStoreItem};
use types::Hash256;
use store::{DBColumn, Error as StoreError, SimpleStoreItem, Store};
use types::{EthSpec, Hash256};
/// 32-byte key for accessing the `DhtEnrs`.
pub const DHT_DB_KEY: &str = "PERSISTEDDHTPERSISTEDDHTPERSISTE";
pub fn load_dht<T: BeaconChainTypes>(store: Arc<T::Store>) -> Vec<Enr> {
pub fn load_dht<T: Store<E>, E: EthSpec>(store: Arc<T>) -> Vec<Enr> {
// Load DHT from store
let key = Hash256::from_slice(&DHT_DB_KEY.as_bytes());
match store.get(&key) {
@@ -22,8 +20,8 @@ pub fn load_dht<T: BeaconChainTypes>(store: Arc<T::Store>) -> Vec<Enr> {
}
/// Attempt to persist the ENR's in the DHT to `self.store`.
pub fn persist_dht<T: BeaconChainTypes>(
store: Arc<T::Store>,
pub fn persist_dht<T: Store<E>, E: EthSpec>(
store: Arc<T>,
enrs: Vec<Enr>,
) -> Result<(), store::Error> {
let key = Hash256::from_slice(&DHT_DB_KEY.as_bytes());

View File

@@ -75,7 +75,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
// launch libp2p service
let (network_globals, mut libp2p) = LibP2PService::new(config, network_log.clone())?;
for enr in load_dht::<T>(store.clone()) {
for enr in load_dht::<T::Store, T::EthSpec>(store.clone()) {
libp2p.swarm.add_enr(enr);
}
@@ -135,7 +135,7 @@ fn spawn_service<T: BeaconChainTypes>(
"Number of peers" => format!("{}", enrs.len()),
);
match persist_dht::<T>(service.store.clone(), enrs) {
match persist_dht::<T::Store, T::EthSpec>(service.store.clone(), enrs) {
Err(e) => error!(
log,
"Failed to persist DHT on drop";

View File

@@ -2,7 +2,7 @@
#[cfg(test)]
mod tests {
use crate::persisted_dht::load_dht;
use crate::{NetworkConfig, Service};
use crate::{NetworkConfig, NetworkService};
use beacon_chain::test_utils::BeaconChainHarness;
use eth2_libp2p::Enr;
use futures::{Future, IntoFuture};
@@ -10,7 +10,6 @@ mod tests {
use sloggers::{null::NullLoggerBuilder, Build};
use std::str::FromStr;
use std::sync::Arc;
use store::MemoryStore;
use tokio::runtime::Runtime;
use types::{test_utils::generate_deterministic_keypairs, MinimalEthSpec};
@@ -44,14 +43,14 @@ mod tests {
.block_on_all(
// Create a new network service which implicitly gets dropped at the
// end of the block.
Service::new(beacon_chain.clone(), &config, &executor, log.clone())
NetworkService::start(beacon_chain.clone(), &config, &executor, log.clone())
.into_future()
.and_then(move |(_service, _)| Ok(())),
.and_then(move |(_globals, _service, _exit)| Ok(())),
)
.unwrap();
// Load the persisted dht from the store
let persisted_enrs = load_dht::<MemoryStore<MinimalEthSpec>, MinimalEthSpec>(store);
let persisted_enrs = load_dht(store);
assert!(
persisted_enrs.contains(&enrs[0]),
"should have persisted the first ENR to store"