mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-11 07:25:09 -05:00
tests: misc p2p blockbody roundtrip tests (#13925)
This commit is contained in:
@@ -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"] }
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user