Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: tests for empty block bodies #12013

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/net/eth-wire-types/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,13 @@ mod tests {
let result = RequestPair::decode(&mut &data[..]).unwrap();
assert_eq!(result, expected);
}

#[test]
fn empty_block_bodies_rlp() {
let body = BlockBodies::default();
let mut buf = Vec::new();
body.encode(&mut buf);
let decoded = BlockBodies::decode(&mut buf.as_slice()).unwrap();
assert_eq!(body, decoded);
}
}
16 changes: 15 additions & 1 deletion crates/net/eth-wire-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ where
mod tests {
use super::MessageError;
use crate::{
message::RequestPair, EthMessage, EthMessageID, GetNodeData, NodeData, ProtocolMessage,
message::RequestPair, EthMessage, EthMessageID, EthVersion, GetNodeData, NodeData,
ProtocolMessage,
};
use alloy_primitives::hex;
use alloy_rlp::{Decodable, Encodable, Error};
Expand Down Expand Up @@ -566,4 +567,17 @@ mod tests {
let result = RequestPair::<Vec<u8>>::decode(&mut &*raw_pair);
assert!(matches!(result, Err(Error::UnexpectedLength)));
}

#[test]
fn empty_block_bodies_protocol() {
let empty_block_bodies = ProtocolMessage::from(EthMessage::BlockBodies(RequestPair {
request_id: 0,
message: Default::default(),
}));
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);
}
}
9 changes: 9 additions & 0 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,4 +1090,13 @@ mod tests {
let block = block.seal_slow();
assert_eq!(sealed, block.hash());
}

#[test]
fn empty_block_rlp() {
let body = BlockBody::default();
let mut buf = Vec::new();
body.encode(&mut buf);
let decoded = BlockBody::decode(&mut buf.as_slice()).unwrap();
assert_eq!(body, decoded);
}
}
Loading