diff --git a/crates/net/eth-wire-types/Cargo.toml b/crates/net/eth-wire-types/Cargo.toml index 8020ed9fd0..5bb6f315e9 100644 --- a/crates/net/eth-wire-types/Cargo.toml +++ b/crates/net/eth-wire-types/Cargo.toml @@ -37,7 +37,10 @@ proptest = { workspace = true, optional = true } proptest-arbitrary-interop = { workspace = true, optional = true } [dev-dependencies] +reth-ethereum-primitives = { workspace = true, features = ["arbitrary"] } alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } +alloy-consensus = { workspace = true, features = ["arbitrary"] } +alloy-eips = { workspace = true, features = ["arbitrary"] } alloy-genesis.workspace = true alloy-chains = { workspace = true, features = ["arbitrary"] } arbitrary = { workspace = true, features = ["derive"] } diff --git a/crates/net/eth-wire-types/src/message.rs b/crates/net/eth-wire-types/src/message.rs index d3c6e5d064..2dbcbf8c26 100644 --- a/crates/net/eth-wire-types/src/message.rs +++ b/crates/net/eth-wire-types/src/message.rs @@ -513,6 +513,7 @@ mod tests { }; use alloy_primitives::hex; use alloy_rlp::{Decodable, Encodable, Error}; + use reth_ethereum_primitives::BlockBody; fn encode(value: T) -> Vec { let mut buf = vec![]; @@ -605,4 +606,34 @@ mod tests { ProtocolMessage::decode_message(EthVersion::Eth68, &mut buf.as_slice()).unwrap(); assert_eq!(empty_block_bodies, decoded); } + + #[test] + fn empty_block_body_protocol() { + let empty_block_bodies = + ProtocolMessage::from(EthMessage::::BlockBodies(RequestPair { + request_id: 0, + message: vec![BlockBody { + transactions: vec![], + ommers: vec![], + withdrawals: Some(Default::default()), + }] + .into(), + })); + let mut buf = Vec::new(); + empty_block_bodies.encode(&mut buf); + let decoded = + ProtocolMessage::decode_message(EthVersion::Eth68, &mut buf.as_slice()).unwrap(); + assert_eq!(empty_block_bodies, decoded); + } + + #[test] + fn decode_block_bodies_message() { + let buf = hex!("06c48199c1c0"); + let msg = ProtocolMessage::::decode_message( + EthVersion::Eth68, + &mut &buf[..], + ) + .unwrap_err(); + assert!(matches!(msg, MessageError::RlpError(alloy_rlp::Error::InputTooShort))); + } }