Skip to content

Commit

Permalink
refactor(decoder): move test assets to workspace location
Browse files Browse the repository at this point in the history
  • Loading branch information
suchapalaver committed Nov 1, 2024
1 parent f9c5e8f commit 629e6b0
Show file tree
Hide file tree
Showing 31 changed files with 25 additions and 12 deletions.
17 changes: 11 additions & 6 deletions crates/flat-files-decoder/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,11 @@ mod tests {

use super::*;

const TEST_ASSET_PATH: &str = "../../test-assets";

#[test]
fn test_handle_file() {
let path = PathBuf::from("example0017686312.dbin");
let path = PathBuf::from(format!("{TEST_ASSET_PATH}/example0017686312.dbin"));

let result = handle_file(&path, None, None, Decompression::None);

Expand All @@ -446,7 +448,7 @@ mod tests {

#[test]
fn test_handle_file_zstd() {
let path = PathBuf::from("./tests/0000000000.dbin.zst");
let path = PathBuf::from(format!("{TEST_ASSET_PATH}/0000000000.dbin.zst"));

let result = handle_file(&path, None, None, Decompression::Zstd);

Expand All @@ -457,7 +459,7 @@ mod tests {

#[test]
fn test_check_valid_root_fail() {
let path = PathBuf::from("example0017686312.dbin");
let path = PathBuf::from(format!("{TEST_ASSET_PATH}/example0017686312.dbin"));
let mut file = BufReader::new(File::open(path).expect("Failed to open file"));
let dbin_file: DbinFile =
DbinFile::try_from_read(&mut file).expect("Failed to parse dbin file");
Expand All @@ -479,7 +481,10 @@ mod tests {
fn test_block_stream() {
let mut buffer = Vec::new();
let cursor: Cursor<&mut Vec<u8>> = Cursor::new(&mut buffer);
let inputs = vec!["example-create-17686085.dbin", "example0017686312.dbin"];
let inputs = vec![
format!("{TEST_ASSET_PATH}/example-create-17686085.dbin"),
format!("{TEST_ASSET_PATH}/example0017686312.dbin"),
];
{
let mut writer = BufWriter::new(cursor);
for i in inputs {
Expand All @@ -504,7 +509,7 @@ mod tests {

#[test]
fn test_handle_buff() {
let path = PathBuf::from("example0017686312.dbin");
let path = PathBuf::from(format!("{TEST_ASSET_PATH}/example0017686312.dbin"));
let file = BufReader::new(File::open(path).expect("Failed to open file"));
let mut reader = BufReader::new(file);

Expand All @@ -523,7 +528,7 @@ mod tests {

#[test]
fn test_handle_buff_decompress() {
let path = PathBuf::from("tests/0000000000.dbin.zst");
let path = PathBuf::from(format!("{TEST_ASSET_PATH}/0000000000.dbin.zst"));
let file = BufReader::new(File::open(path).expect("Failed to open file"));
let mut reader = BufReader::new(file);

Expand Down
8 changes: 5 additions & 3 deletions crates/flat-files-decoder/tests/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ use flat_files_decoder::{decoder::decode_flat_files, decompression::Decompressio

const BLOCK_NUMBER: usize = 0;

const TEST_ASSET_PATH: &str = "../../test-assets";

#[test]
fn test_decode_decompressed() {
let file_name = format!("tests/{:010}.dbin", BLOCK_NUMBER);
let file_name = format!("{TEST_ASSET_PATH}/{:010}.dbin", BLOCK_NUMBER);
let blocks = decode_flat_files(file_name, None, None, Decompression::None).unwrap();
assert_eq!(blocks.len(), 100);
}

#[test]
fn test_decode_compressed() {
let file_name = format!("tests/{:010}.dbin.zst", BLOCK_NUMBER);
let file_name = format!("{TEST_ASSET_PATH}/{:010}.dbin.zst", BLOCK_NUMBER);
let blocks_compressed = decode_flat_files(file_name, None, None, Decompression::Zstd).unwrap();
assert_eq!(blocks_compressed.len(), 100);

let file_name = format!("tests/{:010}.dbin", BLOCK_NUMBER);
let file_name = format!("{TEST_ASSET_PATH}/{:010}.dbin", BLOCK_NUMBER);
let blocks_decompressed =
decode_flat_files(file_name, None, None, Decompression::None).unwrap();
assert_eq!(blocks_compressed.len(), blocks_decompressed.len());
Expand Down
12 changes: 9 additions & 3 deletions crates/flat-files-decoder/tests/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ use reth_primitives::TransactionSigned;
use reth_primitives::TxType;
use std::{fs::File, io::BufReader, str::FromStr};

const TEST_ASSET_PATH: &str = "../../test-assets";

#[test]
fn example_file_first_tx() {
let mut input_file = BufReader::new(File::open("example0017686312.dbin").unwrap());
let mut input_file =
BufReader::new(File::open(format!("{TEST_ASSET_PATH}/example0017686312.dbin")).unwrap());

let dbin_file = DbinFile::try_from_read(&mut input_file).unwrap();

Expand Down Expand Up @@ -75,7 +78,8 @@ fn example_file_first_tx() {

#[test]
fn legacy_tx() {
let mut input_file = BufReader::new(File::open("example0017686312.dbin").unwrap());
let mut input_file =
BufReader::new(File::open(format!("{TEST_ASSET_PATH}/example0017686312.dbin")).unwrap());

let dbin_file = DbinFile::try_from_read(&mut input_file).unwrap();

Expand Down Expand Up @@ -120,7 +124,9 @@ fn legacy_tx() {

#[test]
fn create_tx() {
let mut input_file = BufReader::new(File::open("example-create-17686085.dbin").unwrap());
let mut input_file = BufReader::new(
File::open(format!("{TEST_ASSET_PATH}/example-create-17686085.dbin")).unwrap(),
);

let dbin_file = DbinFile::try_from_read(&mut input_file).unwrap();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 629e6b0

Please sign in to comment.