tests: misc p2p blockbody roundtrip tests (#13925)

This commit is contained in:
Matthias Seitz
2025-01-22 17:21:05 +01:00
committed by GitHub
parent 926ad2a639
commit 56f2c43582
2 changed files with 34 additions and 0 deletions

View File

@@ -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"] }

View File

@@ -513,6 +513,7 @@ mod tests {
};
use alloy_primitives::hex;
use alloy_rlp::{Decodable, Encodable, Error};
use reth_ethereum_primitives::BlockBody;
fn encode<T: Encodable>(value: T) -> Vec<u8> {
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::<EthNetworkPrimitives>::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::<EthNetworkPrimitives>::decode_message(
EthVersion::Eth68,
&mut &buf[..],
)
.unwrap_err();
assert!(matches!(msg, MessageError::RlpError(alloy_rlp::Error::InputTooShort)));
}
}