fixup! Debug tests

This commit is contained in:
Emilia Hane 2023-01-22 01:27:59 +01:00
parent 7220f35ff6
commit 16cb9cfca2
No known key found for this signature in database
GPG Key ID: E73394F9C09206FA
5 changed files with 54 additions and 62 deletions

View File

@ -142,7 +142,6 @@ async fn produces_attestations() {
.add_head_block( .add_head_block(
block_root, block_root,
Arc::new(block.clone()).into(), Arc::new(block.clone()).into(),
None,
proto_block, proto_block,
&state, &state,
&chain.spec, &chain.spec,
@ -199,7 +198,6 @@ async fn early_attester_cache_old_request() {
.add_head_block( .add_head_block(
head.beacon_block_root, head.beacon_block_root,
head.beacon_block.clone().into(), head.beacon_block.clone().into(),
None,
head_proto_block, head_proto_block,
&head.beacon_state, &head.beacon_state,
&harness.chain.spec, &harness.chain.spec,

View File

@ -16,6 +16,7 @@ use state_processing::{
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use tempfile::tempdir; use tempfile::tempdir;
use types::signed_block_and_blobs::BlockWrapper;
use types::{test_utils::generate_deterministic_keypair, *}; use types::{test_utils::generate_deterministic_keypair, *};
type E = MainnetEthSpec; type E = MainnetEthSpec;
@ -137,7 +138,10 @@ fn update_parent_roots(snapshots: &mut [BeaconSnapshot<E>]) {
async fn chain_segment_full_segment() { async fn chain_segment_full_segment() {
let harness = get_harness(VALIDATOR_COUNT); let harness = get_harness(VALIDATOR_COUNT);
let chain_segment = get_chain_segment().await; let chain_segment = get_chain_segment().await;
let blocks = chain_segment_blocks(&chain_segment); let blocks: Vec<BlockWrapper<E>> = chain_segment_blocks(&chain_segment)
.into_iter()
.map(|block| block.into())
.collect();
harness harness
.chain .chain
@ -155,7 +159,7 @@ async fn chain_segment_full_segment() {
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(
blocks.clone().into(), blocks.clone(),
CountUnrealized::True, CountUnrealized::True,
NotifyExecutionLayer::Yes, NotifyExecutionLayer::Yes,
) )
@ -167,7 +171,7 @@ async fn chain_segment_full_segment() {
assert_eq!( assert_eq!(
harness.head_block_root(), harness.head_block_root(),
blocks.last().unwrap().canonical_root(), blocks.last().unwrap().block().canonical_root(),
"harness should have last block as head" "harness should have last block as head"
); );
} }
@ -177,7 +181,10 @@ async fn chain_segment_varying_chunk_size() {
for chunk_size in &[1, 2, 3, 5, 31, 32, 33, 42] { for chunk_size in &[1, 2, 3, 5, 31, 32, 33, 42] {
let harness = get_harness(VALIDATOR_COUNT); let harness = get_harness(VALIDATOR_COUNT);
let chain_segment = get_chain_segment().await; let chain_segment = get_chain_segment().await;
let blocks = chain_segment_blocks(&chain_segment); let blocks: Vec<BlockWrapper<E>> = chain_segment_blocks(&chain_segment)
.into_iter()
.map(|block| block.into())
.collect();
harness harness
.chain .chain
@ -188,7 +195,7 @@ async fn chain_segment_varying_chunk_size() {
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(
chunk.to_vec().into(), chunk.to_vec(),
CountUnrealized::True, CountUnrealized::True,
NotifyExecutionLayer::Yes, NotifyExecutionLayer::Yes,
) )
@ -201,7 +208,7 @@ async fn chain_segment_varying_chunk_size() {
assert_eq!( assert_eq!(
harness.head_block_root(), harness.head_block_root(),
blocks.last().unwrap().canonical_root(), blocks.last().unwrap().block().canonical_root(),
"harness should have last block as head" "harness should have last block as head"
); );
} }
@ -220,18 +227,17 @@ async fn chain_segment_non_linear_parent_roots() {
/* /*
* Test with a block removed. * Test with a block removed.
*/ */
let mut blocks = chain_segment_blocks(&chain_segment); let mut blocks: Vec<BlockWrapper<E>> = chain_segment_blocks(&chain_segment)
.into_iter()
.map(|block| block.into())
.collect();
blocks.remove(2); blocks.remove(2);
assert!( assert!(
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes)
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearParentRoots) Err(BlockError::NonLinearParentRoots)
@ -242,20 +248,19 @@ async fn chain_segment_non_linear_parent_roots() {
/* /*
* Test with a modified parent root. * Test with a modified parent root.
*/ */
let mut blocks = chain_segment_blocks(&chain_segment); let mut blocks: Vec<BlockWrapper<E>> = chain_segment_blocks(&chain_segment)
let (mut block, signature) = blocks[3].as_ref().clone().deconstruct(); .into_iter()
.map(|block| block.into())
.collect();
let (mut block, signature) = blocks[3].block().clone().deconstruct();
*block.parent_root_mut() = Hash256::zero(); *block.parent_root_mut() = Hash256::zero();
blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)); blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into();
assert!( assert!(
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes)
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearParentRoots) Err(BlockError::NonLinearParentRoots)
@ -277,20 +282,19 @@ async fn chain_segment_non_linear_slots() {
* Test where a child is lower than the parent. * Test where a child is lower than the parent.
*/ */
let mut blocks = chain_segment_blocks(&chain_segment); let mut blocks: Vec<BlockWrapper<E>> = chain_segment_blocks(&chain_segment)
let (mut block, signature) = blocks[3].as_ref().clone().deconstruct(); .into_iter()
.map(|block| block.into())
.collect();
let (mut block, signature) = blocks[3].block().clone().deconstruct();
*block.slot_mut() = Slot::new(0); *block.slot_mut() = Slot::new(0);
blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)); blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into();
assert!( assert!(
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes)
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearSlots) Err(BlockError::NonLinearSlots)
@ -302,20 +306,19 @@ async fn chain_segment_non_linear_slots() {
* Test where a child is equal to the parent. * Test where a child is equal to the parent.
*/ */
let mut blocks = chain_segment_blocks(&chain_segment); let mut blocks: Vec<BlockWrapper<E>> = chain_segment_blocks(&chain_segment)
let (mut block, signature) = blocks[3].as_ref().clone().deconstruct(); .into_iter()
.map(|block| block.into())
.collect();
let (mut block, signature) = blocks[3].block().clone().deconstruct();
*block.slot_mut() = blocks[2].slot(); *block.slot_mut() = blocks[2].slot();
blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)); blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into();
assert!( assert!(
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes)
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::NonLinearSlots) Err(BlockError::NonLinearSlots)
@ -331,7 +334,7 @@ async fn assert_invalid_signature(
snapshots: &[BeaconSnapshot<E>], snapshots: &[BeaconSnapshot<E>],
item: &str, item: &str,
) { ) {
let blocks = snapshots let blocks: Vec<BlockWrapper<E>> = snapshots
.iter() .iter()
.map(|snapshot| snapshot.beacon_block.clone().into()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect(); .collect();
@ -341,11 +344,7 @@ async fn assert_invalid_signature(
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes)
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::InvalidSignature) Err(BlockError::InvalidSignature)
@ -475,7 +474,7 @@ async fn invalid_signature_block_proposal() {
block.clone(), block.clone(),
junk_signature(), junk_signature(),
)); ));
let blocks = snapshots let blocks: Vec<BlockWrapper<E>> = snapshots
.iter() .iter()
.map(|snapshot| snapshot.beacon_block.clone().into()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -484,11 +483,7 @@ async fn invalid_signature_block_proposal() {
matches!( matches!(
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes)
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::InvalidSignature) Err(BlockError::InvalidSignature)
@ -678,7 +673,7 @@ async fn invalid_signature_deposit() {
Arc::new(SignedBeaconBlock::from_block(block, signature)); Arc::new(SignedBeaconBlock::from_block(block, signature));
update_parent_roots(&mut snapshots); update_parent_roots(&mut snapshots);
update_proposal_signatures(&mut snapshots, &harness); update_proposal_signatures(&mut snapshots, &harness);
let blocks = snapshots let blocks: Vec<BlockWrapper<E>> = snapshots
.iter() .iter()
.map(|snapshot| snapshot.beacon_block.clone().into()) .map(|snapshot| snapshot.beacon_block.clone().into())
.collect(); .collect();
@ -686,11 +681,7 @@ async fn invalid_signature_deposit() {
!matches!( !matches!(
harness harness
.chain .chain
.process_chain_segment( .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes)
blocks.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes
)
.await .await
.into_block_error(), .into_block_error(),
Err(BlockError::InvalidSignature) Err(BlockError::InvalidSignature)
@ -833,7 +824,7 @@ async fn block_gossip_verification() {
*block.slot_mut() = expected_finalized_slot; *block.slot_mut() = expected_finalized_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::WouldRevertFinalizedSlot { BlockError::WouldRevertFinalizedSlot {
block_slot, block_slot,
finalized_slot, finalized_slot,

View File

@ -282,10 +282,13 @@ impl<T: BeaconChainTypes> Worker<T> {
count_unrealized: CountUnrealized, count_unrealized: CountUnrealized,
notify_execution_layer: NotifyExecutionLayer, notify_execution_layer: NotifyExecutionLayer,
) -> (usize, Result<(), ChainSegmentFailed>) { ) -> (usize, Result<(), ChainSegmentFailed>) {
let blocks: Vec<_> = downloaded_blocks.cloned().collect(); let blocks: Vec<_> = downloaded_blocks
.cloned()
.map(|block| block.into())
.collect();
match self match self
.chain .chain
.process_chain_segment(blocks.into(), count_unrealized, notify_execution_layer) .process_chain_segment(blocks, count_unrealized, notify_execution_layer)
.await .await
{ {
ChainSegmentResult::Successful { imported_blocks } => { ChainSegmentResult::Successful { imported_blocks } => {

View File

@ -534,7 +534,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
/// Check whether a batch for this epoch (and only this epoch) should request just blocks or /// Check whether a batch for this epoch (and only this epoch) should request just blocks or
/// blocks and blobs. /// blocks and blobs.
pub fn batch_type(&self, epoch: types::Epoch) -> ByRangeRequestType { pub fn batch_type(&self, _epoch: types::Epoch) -> ByRangeRequestType {
const _: () = assert!( const _: () = assert!(
super::backfill_sync::BACKFILL_EPOCHS_PER_BATCH == 1 super::backfill_sync::BACKFILL_EPOCHS_PER_BATCH == 1
&& super::range_sync::EPOCHS_PER_BATCH == 1, && super::range_sync::EPOCHS_PER_BATCH == 1,
@ -548,7 +548,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
#[cfg(not(test))] #[cfg(not(test))]
{ {
if let Some(data_availability_boundary) = self.chain.data_availability_boundary() { if let Some(data_availability_boundary) = self.chain.data_availability_boundary() {
if epoch >= data_availability_boundary { if _epoch >= data_availability_boundary {
ByRangeRequestType::BlocksAndBlobs ByRangeRequestType::BlocksAndBlobs
} else { } else {
ByRangeRequestType::Blocks ByRangeRequestType::Blocks

View File

@ -602,7 +602,7 @@ mod tests {
) )
.unwrap(); .unwrap();
// Initialise a new beacon chain from the finalized checkpoint // Initialise a new beacon chain
let chain = Arc::new( let chain = Arc::new(
BeaconChainBuilder::new(E) BeaconChainBuilder::new(E)
.custom_spec(test_spec::<E>()) .custom_spec(test_spec::<E>())