mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: add test_segment_config_backwards (#13394)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -9393,6 +9393,7 @@ dependencies = [
|
|||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"clap",
|
"clap",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
"reth-nippy-jar",
|
||||||
"serde",
|
"serde",
|
||||||
"strum",
|
"strum",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -19,5 +19,8 @@ derive_more.workspace = true
|
|||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
strum = { workspace = true, features = ["derive"] }
|
strum = { workspace = true, features = ["derive"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
reth-nippy-jar.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
clap = ["dep:clap"]
|
clap = ["dep:clap"]
|
||||||
|
|||||||
@ -353,6 +353,8 @@ impl From<SegmentRangeInclusive> for RangeInclusive<u64> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use alloy_primitives::hex;
|
||||||
|
use reth_nippy_jar::NippyJar;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -410,4 +412,49 @@ mod tests {
|
|||||||
assert_eq!(Some((segment, dummy_range)), StaticFileSegment::parse_filename(&filename));
|
assert_eq!(Some((segment, dummy_range)), StaticFileSegment::parse_filename(&filename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_segment_config_backwards() {
|
||||||
|
let headers = hex!("010000000000000000000000000000001fa10700000000000100000000000000001fa10700000000000000000000030000000000000020a107000000000001010000004a02000000000000");
|
||||||
|
let transactions = hex!("010000000000000000000000000000001fa10700000000000100000000000000001fa107000000000001000000000000000034a107000000000001000000010000000000000035a1070000000000004010000000000000");
|
||||||
|
let receipts = hex!("010000000000000000000000000000001fa10700000000000100000000000000000000000000000000000200000001000000000000000000000000000000000000000000000000");
|
||||||
|
|
||||||
|
{
|
||||||
|
let headers = NippyJar::<SegmentHeader>::load_from_reader(&headers[..]).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
&SegmentHeader {
|
||||||
|
expected_block_range: SegmentRangeInclusive::new(0, 499999),
|
||||||
|
block_range: Some(SegmentRangeInclusive::new(0, 499999)),
|
||||||
|
tx_range: None,
|
||||||
|
segment: StaticFileSegment::Headers,
|
||||||
|
},
|
||||||
|
headers.user_header()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let transactions =
|
||||||
|
NippyJar::<SegmentHeader>::load_from_reader(&transactions[..]).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
&SegmentHeader {
|
||||||
|
expected_block_range: SegmentRangeInclusive::new(0, 499999),
|
||||||
|
block_range: Some(SegmentRangeInclusive::new(0, 499999)),
|
||||||
|
tx_range: Some(SegmentRangeInclusive::new(0, 500020)),
|
||||||
|
segment: StaticFileSegment::Transactions,
|
||||||
|
},
|
||||||
|
transactions.user_header()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let receipts = NippyJar::<SegmentHeader>::load_from_reader(&receipts[..]).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
&SegmentHeader {
|
||||||
|
expected_block_range: SegmentRangeInclusive::new(0, 499999),
|
||||||
|
block_range: Some(SegmentRangeInclusive::new(0, 0)),
|
||||||
|
tx_range: None,
|
||||||
|
segment: StaticFileSegment::Receipts,
|
||||||
|
},
|
||||||
|
receipts.user_header()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::{
|
use std::{
|
||||||
error::Error as StdError,
|
error::Error as StdError,
|
||||||
fs::File,
|
fs::File,
|
||||||
|
io::Read,
|
||||||
ops::Range,
|
ops::Range,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
@ -201,11 +202,16 @@ impl<H: NippyJarHeader> NippyJar<H> {
|
|||||||
let config_file = File::open(&config_path)
|
let config_file = File::open(&config_path)
|
||||||
.map_err(|err| reth_fs_util::FsPathError::open(err, config_path))?;
|
.map_err(|err| reth_fs_util::FsPathError::open(err, config_path))?;
|
||||||
|
|
||||||
let mut obj: Self = bincode::deserialize_from(&config_file)?;
|
let mut obj = Self::load_from_reader(config_file)?;
|
||||||
obj.path = path.to_path_buf();
|
obj.path = path.to_path_buf();
|
||||||
Ok(obj)
|
Ok(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deserializes an instance of [`Self`] from a [`Read`] type.
|
||||||
|
pub fn load_from_reader<R: Read>(reader: R) -> Result<Self, NippyJarError> {
|
||||||
|
Ok(bincode::deserialize_from(reader)?)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the path for the data file
|
/// Returns the path for the data file
|
||||||
pub fn data_path(&self) -> &Path {
|
pub fn data_path(&self) -> &Path {
|
||||||
self.path.as_ref()
|
self.path.as_ref()
|
||||||
|
|||||||
Reference in New Issue
Block a user