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

refactor: convert header accumulator tests dependent on data input #53

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
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ fn create_test_reader(path: &str) -> BufReader<File> {
BufReader::new(File::open(path).unwrap())
}

#[test]
fn test_era_validate() -> Result<(), EraValidateError> {
fn main() -> Result<(), EraValidateError> {
let mut headers: Vec<ExtHeaderRecord> = Vec::new();

for number in (0..=8200).step_by(100) {
let file_name = format!("tests/ethereum_firehose_first_8200/{:010}.dbin", number);
let file_name = format!(
"your-test-assets/ethereum_firehose_first_8200/{:010}.dbin",
number
);
let reader = create_test_reader(&file_name);
let blocks = read_blocks_from_reader(reader, Compression::None).unwrap();
let successful_headers = blocks
Expand All @@ -23,19 +26,21 @@ fn test_era_validate() -> Result<(), EraValidateError> {
.collect::<Result<Vec<_>, _>>()?;
headers.extend(successful_headers);
}

assert_eq!(headers.len(), 8300);
assert_eq!(headers[0].block_number, 0);

let premerge_accumulator: EraValidator = PreMergeAccumulator::default().into();
let epoch: Epoch = headers.try_into().unwrap();

let result = premerge_accumulator.validate_era(&epoch)?;

let expected = Hash256::new([
94, 193, 255, 184, 195, 177, 70, 244, 38, 6, 199, 76, 237, 151, 61, 193, 110, 197, 161, 7,
192, 52, 88, 88, 195, 67, 252, 148, 120, 11, 66, 24,
]);
assert_eq!(result, expected);

println!("Era validated successfully!");

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ fn create_test_reader(path: &str) -> BufReader<File> {
BufReader::new(File::open(path).unwrap())
}

#[test]
fn test_inclusion_proof() -> Result<(), EraValidateError> {
fn main() -> Result<(), EraValidateError> {
let mut headers: Vec<ExtHeaderRecord> = Vec::new();
let mut all_blocks: Vec<Block> = Vec::new(); // Vector to hold all blocks
let mut all_blocks: Vec<Block> = Vec::new();

for flat_file_number in (0..=8200).step_by(100) {
let file = format!(
"tests/ethereum_firehose_first_8200/{:010}.dbin",
"your-test-assets/ethereum_firehose_first_8200/{:010}.dbin",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should have some repo to hold test assets anyway, just because they aid a lot on implementations.

Like this for example: https://github.com/ethereum/portal-network-specs/blob/master/portal-wire-test-vectors.md

Nonetheless, it is cool to get rid of them, they are heavy.

flat_file_number
);
match read_blocks_from_reader(create_test_reader(&file), Compression::None) {
Expand All @@ -28,7 +27,7 @@ fn test_inclusion_proof() -> Result<(), EraValidateError> {
.map(|block| ExtHeaderRecord::try_from(block).unwrap())
.collect::<Vec<ExtHeaderRecord>>(),
);
all_blocks.extend(blocks); // Extend the all_blocks vector with the decoded blocks
all_blocks.extend(blocks);
}
Err(e) => {
eprintln!("error: {:?}", e);
Expand All @@ -42,8 +41,7 @@ fn test_inclusion_proof() -> Result<(), EraValidateError> {
let inclusion_proof =
generate_inclusion_proof(headers, start_block, end_block).unwrap_or_else(|e| {
println!("Error occurred: {}", e);
// Handle the error, e.g., by exiting the program or returning a default value
std::process::exit(1); // Exiting the program, for example
std::process::exit(1);
});
assert_eq!(
inclusion_proof.len() as usize,
Expand All @@ -54,9 +52,11 @@ fn test_inclusion_proof() -> Result<(), EraValidateError> {
let proof_blocks: Vec<Block> = all_blocks[start_block as usize..=end_block as usize].to_vec();
assert!(verify_inclusion_proof(proof_blocks, None, inclusion_proof.clone()).is_ok());

// verify if inclusion proof fails on not proven blocks
// Verify if inclusion proof fails on not proven blocks
let proof_blocks: Vec<Block> = all_blocks[302..=403].to_vec();
assert!(verify_inclusion_proof(proof_blocks, None, inclusion_proof.clone()).is_err());

println!("Inclusion proof verified successfully!");

Ok(())
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading