Debug tests

This commit is contained in:
Emilia Hane 2023-01-22 00:51:58 +01:00
parent 995b2715f2
commit 7220f35ff6
No known key found for this signature in database
GPG Key ID: E73394F9C09206FA
7 changed files with 113 additions and 47 deletions

View File

@ -141,7 +141,7 @@ async fn produces_attestations() {
.early_attester_cache .early_attester_cache
.add_head_block( .add_head_block(
block_root, block_root,
Arc::new(block.clone()), Arc::new(block.clone()).into(),
None, None,
proto_block, proto_block,
&state, &state,
@ -198,7 +198,7 @@ async fn early_attester_cache_old_request() {
.early_attester_cache .early_attester_cache
.add_head_block( .add_head_block(
head.beacon_block_root, head.beacon_block_root,
head.beacon_block.clone(), head.beacon_block.clone().into(),
None, None,
head_proto_block, head_proto_block,
&head.beacon_state, &head.beacon_state,

View File

@ -80,7 +80,7 @@ fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessTyp
fn chain_segment_blocks(chain_segment: &[BeaconSnapshot<E>]) -> Vec<Arc<SignedBeaconBlock<E>>> { fn chain_segment_blocks(chain_segment: &[BeaconSnapshot<E>]) -> Vec<Arc<SignedBeaconBlock<E>>> {
chain_segment chain_segment
.iter() .iter()
.map(|snapshot| snapshot.beacon_block.clone()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect() .collect()
} }
@ -155,7 +155,7 @@ async fn chain_segment_full_segment() {
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(
blocks.clone(), blocks.clone().into(),
CountUnrealized::True, CountUnrealized::True,
NotifyExecutionLayer::Yes, NotifyExecutionLayer::Yes,
) )
@ -188,7 +188,7 @@ async fn chain_segment_varying_chunk_size() {
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(
chunk.to_vec(), chunk.to_vec().into(),
CountUnrealized::True, CountUnrealized::True,
NotifyExecutionLayer::Yes, NotifyExecutionLayer::Yes,
) )
@ -227,7 +227,11 @@ async fn chain_segment_non_linear_parent_roots() {
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) .process_chain_segment(
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearParentRoots) Err(BlockError::NonLinearParentRoots)
@ -247,7 +251,11 @@ async fn chain_segment_non_linear_parent_roots() {
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) .process_chain_segment(
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearParentRoots) Err(BlockError::NonLinearParentRoots)
@ -278,7 +286,11 @@ async fn chain_segment_non_linear_slots() {
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) .process_chain_segment(
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearSlots) Err(BlockError::NonLinearSlots)
@ -299,7 +311,11 @@ async fn chain_segment_non_linear_slots() {
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) .process_chain_segment(
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearSlots) Err(BlockError::NonLinearSlots)
@ -317,7 +333,7 @@ async fn assert_invalid_signature(
) { ) {
let blocks = snapshots let blocks = snapshots
.iter() .iter()
.map(|snapshot| snapshot.beacon_block.clone()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect(); .collect();
// Ensure the block will be rejected if imported in a chain segment. // Ensure the block will be rejected if imported in a chain segment.
@ -325,7 +341,11 @@ async fn assert_invalid_signature(
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) .process_chain_segment(
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::InvalidSignature) Err(BlockError::InvalidSignature)
@ -341,7 +361,7 @@ async fn assert_invalid_signature(
let ancestor_blocks = chain_segment let ancestor_blocks = chain_segment
.iter() .iter()
.take(block_index) .take(block_index)
.map(|snapshot| snapshot.beacon_block.clone()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect(); .collect();
// We don't care if this fails, we just call this to ensure that all prior blocks have been // We don't care if this fails, we just call this to ensure that all prior blocks have been
// imported prior to this test. // imported prior to this test.
@ -409,7 +429,7 @@ async fn invalid_signature_gossip_block() {
let ancestor_blocks = chain_segment let ancestor_blocks = chain_segment
.iter() .iter()
.take(block_index) .take(block_index)
.map(|snapshot| snapshot.beacon_block.clone()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect(); .collect();
harness harness
.chain .chain
@ -457,14 +477,18 @@ async fn invalid_signature_block_proposal() {
)); ));
let blocks = snapshots let blocks = snapshots
.iter() .iter()
.map(|snapshot| snapshot.beacon_block.clone()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// Ensure the block will be rejected if imported in a chain segment. // Ensure the block will be rejected if imported in a chain segment.
assert!( assert!(
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) .process_chain_segment(
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::InvalidSignature) Err(BlockError::InvalidSignature)
@ -656,13 +680,17 @@ async fn invalid_signature_deposit() {
update_proposal_signatures(&mut snapshots, &harness); update_proposal_signatures(&mut snapshots, &harness);
let blocks = snapshots let blocks = snapshots
.iter() .iter()
.map(|snapshot| snapshot.beacon_block.clone()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect(); .collect();
assert!( assert!(
!matches!( !matches!(
harness harness
.chain .chain
.process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) .process_chain_segment(
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::InvalidSignature) Err(BlockError::InvalidSignature)
@ -733,7 +761,7 @@ async fn block_gossip_verification() {
for snapshot in &chain_segment[0..block_index] { for snapshot in &chain_segment[0..block_index] {
let gossip_verified = harness let gossip_verified = harness
.chain .chain
.verify_block_for_gossip(snapshot.beacon_block.clone()) .verify_block_for_gossip(snapshot.beacon_block.clone().into())
.await .await
.expect("should obtain gossip verified block"); .expect("should obtain gossip verified block");
@ -771,7 +799,7 @@ async fn block_gossip_verification() {
*block.slot_mut() = expected_block_slot; *block.slot_mut() = expected_block_slot;
assert!( assert!(
matches!( matches!(
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await), unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)).into()).await),
BlockError::FutureSlot { BlockError::FutureSlot {
present_slot, present_slot,
block_slot, block_slot,
@ -835,10 +863,9 @@ async fn block_gossip_verification() {
unwrap_err( unwrap_err(
harness harness
.chain .chain
.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block( .verify_block_for_gossip(
block, Arc::new(SignedBeaconBlock::from_block(block, junk_signature())).into()
junk_signature() )
)))
.await .await
), ),
BlockError::ProposalSignatureInvalid BlockError::ProposalSignatureInvalid
@ -863,7 +890,7 @@ async fn block_gossip_verification() {
*block.parent_root_mut() = parent_root; *block.parent_root_mut() = parent_root;
assert!( assert!(
matches!( matches!(
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await), unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)).into()).await),
BlockError::ParentUnknown(block) BlockError::ParentUnknown(block)
if block.parent_root() == parent_root if block.parent_root() == parent_root
), ),
@ -889,7 +916,7 @@ async fn block_gossip_verification() {
*block.parent_root_mut() = parent_root; *block.parent_root_mut() = parent_root;
assert!( assert!(
matches!( matches!(
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await), unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)).into()).await),
BlockError::NotFinalizedDescendant { block_parent_root } BlockError::NotFinalizedDescendant { block_parent_root }
if block_parent_root == parent_root if block_parent_root == parent_root
), ),
@ -927,7 +954,7 @@ async fn block_gossip_verification() {
); );
assert!( assert!(
matches!( matches!(
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone())).await), unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone()).into()).await),
BlockError::IncorrectBlockProposer { BlockError::IncorrectBlockProposer {
block, block,
local_shuffling, local_shuffling,
@ -939,7 +966,7 @@ async fn block_gossip_verification() {
// Check to ensure that we registered this is a valid block from this proposer. // Check to ensure that we registered this is a valid block from this proposer.
assert!( assert!(
matches!( matches!(
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone())).await), unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone()).into()).await),
BlockError::RepeatProposal { BlockError::RepeatProposal {
proposer, proposer,
slot, slot,
@ -951,7 +978,11 @@ async fn block_gossip_verification() {
let block = chain_segment[block_index].beacon_block.clone(); let block = chain_segment[block_index].beacon_block.clone();
assert!( assert!(
harness.chain.verify_block_for_gossip(block).await.is_ok(), harness
.chain
.verify_block_for_gossip(block.into())
.await
.is_ok(),
"the valid block should be processed" "the valid block should be processed"
); );
@ -969,7 +1000,7 @@ async fn block_gossip_verification() {
matches!( matches!(
harness harness
.chain .chain
.verify_block_for_gossip(block.clone()) .verify_block_for_gossip(block.clone().into())
.await .await
.err() .err()
.expect("should error when processing known block"), .expect("should error when processing known block"),
@ -1006,7 +1037,7 @@ async fn verify_block_for_gossip_slashing_detection() {
let verified_block = harness let verified_block = harness
.chain .chain
.verify_block_for_gossip(Arc::new(block1)) .verify_block_for_gossip(Arc::new(block1).into())
.await .await
.unwrap(); .unwrap();
harness harness
@ -1022,7 +1053,7 @@ async fn verify_block_for_gossip_slashing_detection() {
unwrap_err( unwrap_err(
harness harness
.chain .chain
.verify_block_for_gossip(Arc::new(block2)) .verify_block_for_gossip(Arc::new(block2).into())
.await, .await,
); );
@ -1045,7 +1076,7 @@ async fn verify_block_for_gossip_doppelganger_detection() {
let verified_block = harness let verified_block = harness
.chain .chain
.verify_block_for_gossip(Arc::new(block)) .verify_block_for_gossip(Arc::new(block).into())
.await .await
.unwrap(); .unwrap();
let attestations = verified_block.block.message().body().attestations().clone(); let attestations = verified_block.block.message().body().attestations().clone();
@ -1184,7 +1215,7 @@ async fn add_base_block_to_altair_chain() {
assert!(matches!( assert!(matches!(
harness harness
.chain .chain
.verify_block_for_gossip(Arc::new(base_block.clone())) .verify_block_for_gossip(Arc::new(base_block.clone()).into())
.await .await
.err() .err()
.expect("should error when processing base block"), .expect("should error when processing base block"),
@ -1218,7 +1249,7 @@ async fn add_base_block_to_altair_chain() {
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(
vec![Arc::new(base_block)], vec![Arc::new(base_block).into()],
CountUnrealized::True, CountUnrealized::True,
NotifyExecutionLayer::Yes, NotifyExecutionLayer::Yes,
) )
@ -1322,7 +1353,7 @@ async fn add_altair_block_to_base_chain() {
assert!(matches!( assert!(matches!(
harness harness
.chain .chain
.verify_block_for_gossip(Arc::new(altair_block.clone())) .verify_block_for_gossip(Arc::new(altair_block.clone()).into())
.await .await
.err() .err()
.expect("should error when processing altair block"), .expect("should error when processing altair block"),
@ -1356,7 +1387,7 @@ async fn add_altair_block_to_base_chain() {
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(
vec![Arc::new(altair_block)], vec![Arc::new(altair_block).into()],
CountUnrealized::True, CountUnrealized::True,
NotifyExecutionLayer::Yes NotifyExecutionLayer::Yes
) )

View File

@ -1040,7 +1040,7 @@ async fn invalid_parent() {
// Ensure the block built atop an invalid payload is invalid for gossip. // Ensure the block built atop an invalid payload is invalid for gossip.
assert!(matches!( assert!(matches!(
rig.harness.chain.clone().verify_block_for_gossip(block.clone()).await, rig.harness.chain.clone().verify_block_for_gossip(block.clone().into()).await,
Err(BlockError::ParentExecutionPayloadInvalid { parent_root: invalid_root }) Err(BlockError::ParentExecutionPayloadInvalid { parent_root: invalid_root })
if invalid_root == parent_root if invalid_root == parent_root
)); ));

View File

@ -726,7 +726,7 @@ impl<T: BeaconChainTypes> Worker<T> {
let verification_result = self let verification_result = self
.chain .chain
.clone() .clone()
.verify_block_for_gossip(block.clone()) .verify_block_for_gossip(block.clone().into())
.await; .await;
let block_root = if let Ok(verified_block) = &verification_result { let block_root = if let Ok(verified_block) = &verification_result {

View File

@ -285,7 +285,7 @@ impl<T: BeaconChainTypes> Worker<T> {
let blocks: Vec<_> = downloaded_blocks.cloned().collect(); let blocks: Vec<_> = downloaded_blocks.cloned().collect();
match self match self
.chain .chain
.process_chain_segment(blocks, count_unrealized, notify_execution_layer) .process_chain_segment(blocks.into(), count_unrealized, notify_execution_layer)
.await .await
{ {
ChainSegmentResult::Successful { imported_blocks } => { ChainSegmentResult::Successful { imported_blocks } => {

View File

@ -38,9 +38,11 @@ impl TestRig {
fn test_setup(log_level: Option<Level>) -> (BlockLookups<T>, SyncNetworkContext<T>, Self) { fn test_setup(log_level: Option<Level>) -> (BlockLookups<T>, SyncNetworkContext<T>, Self) {
let builder = NullLoggerBuilder; let builder = NullLoggerBuilder;
let log = builder.build().expect("should build logger"); let log = builder.build().expect("should build logger");
let store = store::HotColdDB::open_ephemeral(store::StoreConfig::default(), E::default_spec(), log).unwrap(); let store =
store::HotColdDB::open_ephemeral(store::StoreConfig::default(), E::default_spec(), log)
.unwrap();
// Initialise a new beacon chain from the finalized checkpoint // Initialise a new beacon chain
let chain = BeaconChainBuilder::new(E) let chain = BeaconChainBuilder::new(E)
.custom_spec(test_spec::<E>()) .custom_spec(test_spec::<E>())
.store(Arc::new(store)) .store(Arc::new(store))

View File

@ -377,6 +377,7 @@ mod tests {
use crate::beacon_processor::WorkEvent as BeaconWorkEvent; use crate::beacon_processor::WorkEvent as BeaconWorkEvent;
use crate::service::RequestId; use crate::service::RequestId;
use crate::NetworkMessage; use crate::NetworkMessage;
use beacon_chain::{builder::BeaconChainBuilder, test_utils::test_spec};
use beacon_chain::{ use beacon_chain::{
builder::Witness, eth1_chain::CachingEth1Backend, parking_lot::RwLock, EngineState, builder::Witness, eth1_chain::CachingEth1Backend, parking_lot::RwLock, EngineState,
}; };
@ -385,7 +386,9 @@ mod tests {
NetworkGlobals, Request, NetworkGlobals, Request,
}; };
use slog::{o, Drain}; use slog::{o, Drain};
use slot_clock::SystemTimeSlotClock; use sloggers::{null::NullLoggerBuilder, Build};
use slot_clock::{SlotClock, SystemTimeSlotClock};
use std::time::{Duration, SystemTime};
use std::{collections::HashSet, sync::Arc}; use std::{collections::HashSet, sync::Arc};
use store::MemoryStore; use store::MemoryStore;
use tokio::sync::mpsc; use tokio::sync::mpsc;
@ -590,11 +593,41 @@ mod tests {
} }
fn range(log_enabled: bool) -> (TestRig, RangeSync<TestBeaconChainType, FakeStorage>) { fn range(log_enabled: bool) -> (TestRig, RangeSync<TestBeaconChainType, FakeStorage>) {
let chain = Arc::new(FakeStorage::default()); let builder = NullLoggerBuilder;
let db_log = builder.build().expect("should build logger");
let store = store::HotColdDB::open_ephemeral(
store::StoreConfig::default(),
E::default_spec(),
db_log,
)
.unwrap();
// Initialise a new beacon chain from the finalized checkpoint
let chain = Arc::new(
BeaconChainBuilder::new(E)
.custom_spec(test_spec::<E>())
.store(Arc::new(store))
.dummy_eth1_backend()
.expect("should build dummy backend")
.slot_clock(SystemTimeSlotClock::new(
types::Slot::new(0),
Duration::from_secs(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs(),
),
Duration::from_millis(400),
))
.build()
.expect("should build"),
);
let log = build_log(slog::Level::Trace, log_enabled); let log = build_log(slog::Level::Trace, log_enabled);
let fake_store = Arc::new(FakeStorage::default());
let (beacon_processor_tx, beacon_processor_rx) = mpsc::channel(10); let (beacon_processor_tx, beacon_processor_rx) = mpsc::channel(10);
let range_sync = RangeSync::<TestBeaconChainType, FakeStorage>::new( let range_sync = RangeSync::<TestBeaconChainType, FakeStorage>::new(
chain.clone(), fake_store.clone(),
log.new(o!("component" => "range")), log.new(o!("component" => "range")),
); );
let (network_tx, network_rx) = mpsc::unbounded_channel(); let (network_tx, network_rx) = mpsc::unbounded_channel();
@ -609,7 +642,7 @@ mod tests {
let test_rig = TestRig { let test_rig = TestRig {
log, log,
beacon_processor_rx, beacon_processor_rx,
chain, chain: fake_store,
cx, cx,
network_rx, network_rx,
globals, globals,
@ -684,7 +717,7 @@ mod tests {
range.add_peer(&mut rig.cx, local_info, peer1, head_info); range.add_peer(&mut rig.cx, local_info, peer1, head_info);
let ((chain1, batch1), id1) = match rig.grab_request(&peer1).0 { let ((chain1, batch1), id1) = match rig.grab_request(&peer1).0 {
RequestId::Sync(crate::sync::manager::RequestId::RangeBlocks { id }) => { RequestId::Sync(crate::sync::manager::RequestId::RangeBlocks { id }) => {
(rig.cx.range_sync_response(id, true).unwrap(), id) (rig.cx.range_sync_block_response(id, true).unwrap(), id)
} }
other => panic!("unexpected request {:?}", other), other => panic!("unexpected request {:?}", other),
}; };
@ -703,7 +736,7 @@ mod tests {
range.add_peer(&mut rig.cx, local_info, peer2, finalized_info); range.add_peer(&mut rig.cx, local_info, peer2, finalized_info);
let ((chain2, batch2), id2) = match rig.grab_request(&peer2).0 { let ((chain2, batch2), id2) = match rig.grab_request(&peer2).0 {
RequestId::Sync(crate::sync::manager::RequestId::RangeBlocks { id }) => { RequestId::Sync(crate::sync::manager::RequestId::RangeBlocks { id }) => {
(rig.cx.range_sync_response(id, true).unwrap(), id) (rig.cx.range_sync_block_response(id, true).unwrap(), id)
} }
other => panic!("unexpected request {:?}", other), other => panic!("unexpected request {:?}", other),
}; };