mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: integrate Test trait for sealed types (#13746)
This commit is contained in:
@ -93,12 +93,35 @@ where
|
||||
///
|
||||
/// This allows for modifying the block's header and body for testing purposes.
|
||||
#[cfg(any(test, feature = "test-utils"))]
|
||||
pub trait TestBlock: Block {
|
||||
pub trait TestBlock: Block<Header: crate::test_utils::TestHeader> {
|
||||
/// Returns mutable reference to block body.
|
||||
fn body_mut(&mut self) -> &mut Self::Body;
|
||||
|
||||
/// Returns mutable reference to block header.
|
||||
fn header_mut(&mut self) -> &mut Self::Header;
|
||||
|
||||
/// Updates the block header.
|
||||
fn set_header(&mut self, header: Self::Header);
|
||||
|
||||
/// Updates the parent block hash.
|
||||
fn set_parent_hash(&mut self, hash: alloy_primitives::BlockHash) {
|
||||
crate::header::test_utils::TestHeader::set_parent_hash(self.header_mut(), hash);
|
||||
}
|
||||
|
||||
/// Updates the block number.
|
||||
fn set_block_number(&mut self, number: alloy_primitives::BlockNumber) {
|
||||
crate::header::test_utils::TestHeader::set_block_number(self.header_mut(), number);
|
||||
}
|
||||
|
||||
/// Updates the block state root.
|
||||
fn set_state_root(&mut self, state_root: alloy_primitives::B256) {
|
||||
crate::header::test_utils::TestHeader::set_state_root(self.header_mut(), state_root);
|
||||
}
|
||||
|
||||
/// Updates the block difficulty.
|
||||
fn set_difficulty(&mut self, difficulty: alloy_primitives::U256) {
|
||||
crate::header::test_utils::TestHeader::set_difficulty(self.header_mut(), difficulty);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-utils"))]
|
||||
@ -113,4 +136,8 @@ where
|
||||
fn header_mut(&mut self) -> &mut Self::Header {
|
||||
&mut self.header
|
||||
}
|
||||
|
||||
fn set_header(&mut self, header: Self::Header) {
|
||||
self.header = header
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,9 +138,9 @@ where
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-utils"))]
|
||||
impl SealedHeader {
|
||||
impl<H: crate::test_utils::TestHeader> SealedHeader<H> {
|
||||
/// Updates the block header.
|
||||
pub fn set_header(&mut self, header: Header) {
|
||||
pub fn set_header(&mut self, header: H) {
|
||||
self.header = header
|
||||
}
|
||||
|
||||
@ -149,24 +149,29 @@ impl SealedHeader {
|
||||
self.hash = hash
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the header.
|
||||
pub fn header_mut(&mut self) -> &mut H {
|
||||
&mut self.header
|
||||
}
|
||||
|
||||
/// Updates the parent block hash.
|
||||
pub fn set_parent_hash(&mut self, hash: BlockHash) {
|
||||
self.header.parent_hash = hash
|
||||
self.header.set_parent_hash(hash);
|
||||
}
|
||||
|
||||
/// Updates the block number.
|
||||
pub fn set_block_number(&mut self, number: alloy_primitives::BlockNumber) {
|
||||
self.header.number = number;
|
||||
self.header.set_block_number(number);
|
||||
}
|
||||
|
||||
/// Updates the block state root.
|
||||
pub fn set_state_root(&mut self, state_root: alloy_primitives::B256) {
|
||||
self.header.state_root = state_root;
|
||||
self.header.set_state_root(state_root);
|
||||
}
|
||||
|
||||
/// Updates the block difficulty.
|
||||
pub fn set_difficulty(&mut self, difficulty: alloy_primitives::U256) {
|
||||
self.header.difficulty = difficulty;
|
||||
self.header.set_difficulty(difficulty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user