diff --git a/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs b/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs index 915572fd12a..6d59859315c 100644 --- a/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs +++ b/beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs @@ -615,7 +615,11 @@ mod tests { type Spec = types::MainnetEthSpec; fn fork_context() -> ForkContext { - ForkContext::new::(types::Slot::new(0), Hash256::zero(), &Spec::default_spec()) + let mut chain_spec = Spec::default_spec(); + // Set fork_epoch to `Some` to ensure that the `ForkContext` object + // includes altair in the list of forks + chain_spec.altair_fork_epoch = Some(types::Epoch::new(42)); + ForkContext::new::(types::Slot::new(0), Hash256::zero(), &chain_spec) } fn base_block() -> SignedBeaconBlock { diff --git a/beacon_node/eth2_libp2p/tests/common/mod.rs b/beacon_node/eth2_libp2p/tests/common/mod.rs index 8c28512d045..1023bbacd40 100644 --- a/beacon_node/eth2_libp2p/tests/common/mod.rs +++ b/beacon_node/eth2_libp2p/tests/common/mod.rs @@ -11,14 +11,18 @@ use std::sync::Arc; use std::sync::Weak; use std::time::Duration; use tokio::runtime::Runtime; -use types::{ChainSpec, EnrForkId, ForkContext, Hash256, MinimalEthSpec}; +use types::{ChainSpec, EnrForkId, EthSpec, ForkContext, Hash256, MinimalEthSpec}; type E = MinimalEthSpec; use tempfile::Builder as TempBuilder; /// Returns a dummy fork context fn fork_context() -> ForkContext { - ForkContext::new::(types::Slot::new(0), Hash256::zero(), &ChainSpec::minimal()) + let mut chain_spec = E::default_spec(); + // Set fork_epoch to `Some` to ensure that the `ForkContext` object + // includes altair in the list of forks + chain_spec.altair_fork_epoch = Some(types::Epoch::new(42)); + ForkContext::new::(types::Slot::new(0), Hash256::zero(), &chain_spec) } pub struct Libp2pInstance(LibP2PService, exit_future::Signal); diff --git a/beacon_node/eth2_libp2p/tests/rpc_tests.rs b/beacon_node/eth2_libp2p/tests/rpc_tests.rs index 9d1faf748cf..1e5f1e4e1c3 100644 --- a/beacon_node/eth2_libp2p/tests/rpc_tests.rs +++ b/beacon_node/eth2_libp2p/tests/rpc_tests.rs @@ -138,11 +138,16 @@ fn test_blocks_by_range_chunked_rpc() { step: 0, }); - // BlocksByRange Response let spec = E::default_spec(); - let empty_block = BeaconBlock::empty(&spec); - let empty_signed = SignedBeaconBlock::from_block(empty_block, Signature::empty()); - let rpc_response = Response::BlocksByRange(Some(Box::new(empty_signed))); + + // BlocksByRange Response + let full_block = BeaconBlock::Base(BeaconBlockBase::::full(&spec)); + let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty()); + let rpc_response_base = Response::BlocksByRange(Some(Box::new(signed_full_block))); + + let full_block = BeaconBlock::Altair(BeaconBlockAltair::::full(&spec)); + let signed_full_block = SignedBeaconBlock::from_block(full_block, Signature::empty()); + let rpc_response_altair = Response::BlocksByRange(Some(Box::new(signed_full_block))); // keep count of the number of messages received let mut messages_received = 0; @@ -167,7 +172,11 @@ fn test_blocks_by_range_chunked_rpc() { warn!(log, "Sender received a response"); match response { Response::BlocksByRange(Some(_)) => { - assert_eq!(response, rpc_response.clone()); + if messages_received < 5 { + assert_eq!(response, rpc_response_base.clone()); + } else { + assert_eq!(response, rpc_response_altair.clone()); + } messages_received += 1; warn!(log, "Chunk received"); } @@ -197,7 +206,14 @@ fn test_blocks_by_range_chunked_rpc() { if request == rpc_request { // send the response warn!(log, "Receiver got request"); - for _ in 1..=messages_to_send { + for i in 0..messages_to_send { + // Send first half of responses as base blocks and + // second half as altair blocks. + let rpc_response = if i < 5 { + rpc_response_base.clone() + } else { + rpc_response_altair.clone() + }; receiver.swarm.behaviour_mut().send_successful_response( peer_id, id, @@ -481,7 +497,7 @@ fn test_blocks_by_root_chunked_rpc() { let log_level = Level::Debug; let enable_logging = false; - let messages_to_send = 3; + let messages_to_send = 10; let log = common::build_log(log_level, enable_logging); let spec = E::default_spec(); @@ -497,6 +513,13 @@ fn test_blocks_by_root_chunked_rpc() { Hash256::from_low_u64_be(0), Hash256::from_low_u64_be(0), Hash256::from_low_u64_be(0), + Hash256::from_low_u64_be(0), + Hash256::from_low_u64_be(0), + Hash256::from_low_u64_be(0), + Hash256::from_low_u64_be(0), + Hash256::from_low_u64_be(0), + Hash256::from_low_u64_be(0), + Hash256::from_low_u64_be(0), ]), });