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

View File

@ -1040,7 +1040,7 @@ async fn invalid_parent() {
// Ensure the block built atop an invalid payload is invalid for gossip.
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 })
if invalid_root == parent_root
));

View File

@ -726,7 +726,7 @@ impl<T: BeaconChainTypes> Worker<T> {
let verification_result = self
.chain
.clone()
.verify_block_for_gossip(block.clone())
.verify_block_for_gossip(block.clone().into())
.await;
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();
match self
.chain
.process_chain_segment(blocks, count_unrealized, notify_execution_layer)
.process_chain_segment(blocks.into(), count_unrealized, notify_execution_layer)
.await
{
ChainSegmentResult::Successful { imported_blocks } => {

View File

@ -38,9 +38,11 @@ impl TestRig {
fn test_setup(log_level: Option<Level>) -> (BlockLookups<T>, SyncNetworkContext<T>, Self) {
let builder = NullLoggerBuilder;
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)
.custom_spec(test_spec::<E>())
.store(Arc::new(store))

View File

@ -377,6 +377,7 @@ mod tests {
use crate::beacon_processor::WorkEvent as BeaconWorkEvent;
use crate::service::RequestId;
use crate::NetworkMessage;
use beacon_chain::{builder::BeaconChainBuilder, test_utils::test_spec};
use beacon_chain::{
builder::Witness, eth1_chain::CachingEth1Backend, parking_lot::RwLock, EngineState,
};
@ -385,7 +386,9 @@ mod tests {
NetworkGlobals, Request,
};
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 store::MemoryStore;
use tokio::sync::mpsc;
@ -590,11 +593,41 @@ mod tests {
}
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 fake_store = Arc::new(FakeStorage::default());
let (beacon_processor_tx, beacon_processor_rx) = mpsc::channel(10);
let range_sync = RangeSync::<TestBeaconChainType, FakeStorage>::new(
chain.clone(),
fake_store.clone(),
log.new(o!("component" => "range")),
);
let (network_tx, network_rx) = mpsc::unbounded_channel();
@ -609,7 +642,7 @@ mod tests {
let test_rig = TestRig {
log,
beacon_processor_rx,
chain,
chain: fake_store,
cx,
network_rx,
globals,
@ -684,7 +717,7 @@ mod tests {
range.add_peer(&mut rig.cx, local_info, peer1, head_info);
let ((chain1, batch1), id1) = match rig.grab_request(&peer1).0 {
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),
};
@ -703,7 +736,7 @@ mod tests {
range.add_peer(&mut rig.cx, local_info, peer2, finalized_info);
let ((chain2, batch2), id2) = match rig.grab_request(&peer2).0 {
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),
};