|
1 | 1 | use alloy_primitives::Bytes;
|
| 2 | +use anyhow::bail; |
2 | 3 | use ethportal_api::{ContentValue, HistoryContentKey, HistoryContentValue};
|
3 | 4 | use serde_yaml::Value;
|
4 | 5 | use std::str::FromStr;
|
5 | 6 |
|
6 |
| -pub const TEST_DATA_FILE_PATH: &str = "./test-data/test_data_collection_of_forks_blocks.yaml"; |
7 |
| - |
8 | 7 | // trin-bridge constants
|
9 | 8 | pub const TRIN_BRIDGE_CLIENT_TYPE: &str = "trin-bridge";
|
10 | 9 |
|
| 10 | +pub const TEST_DATA_FILE_PATH: &str = "./portal-spec-tests/tests/mainnet/history/hive/success"; |
| 11 | + |
11 | 12 | pub fn get_test_data() -> anyhow::Result<Vec<(HistoryContentKey, HistoryContentValue)>> {
|
12 |
| - let values = std::fs::read_to_string(TEST_DATA_FILE_PATH)?; |
13 |
| - let values: Value = serde_yaml::from_str(&values)?; |
14 |
| - values |
15 |
| - .as_sequence() |
16 |
| - .expect("unable to convert test data to sequence") |
17 |
| - .iter() |
18 |
| - .map(|value| { |
19 |
| - let content_key: HistoryContentKey = |
20 |
| - serde_yaml::from_value(value["content_key"].clone())?; |
21 |
| - let raw_content_value = Bytes::from_str( |
22 |
| - value["content_value"] |
23 |
| - .as_str() |
24 |
| - .expect("to find content value"), |
25 |
| - )?; |
26 |
| - let content_value = |
27 |
| - HistoryContentValue::decode(&content_key, raw_content_value.as_ref())?; |
28 |
| - Ok((content_key, content_value)) |
29 |
| - }) |
30 |
| - .collect() |
| 13 | + let mut content = vec![]; |
| 14 | + |
| 15 | + for entry in std::fs::read_dir(TEST_DATA_FILE_PATH)? { |
| 16 | + let entry = entry?; |
| 17 | + let test_path = entry.path(); |
| 18 | + if !test_path.is_file() { |
| 19 | + bail!("Expected a file, but found a directory: {test_path:?}"); |
| 20 | + } |
| 21 | + |
| 22 | + let values = std::fs::read_to_string(test_path)?; |
| 23 | + let values: Value = serde_yaml::from_str(&values)?; |
| 24 | + let test_case = values |
| 25 | + .as_sequence() |
| 26 | + .expect("unable to convert test data to sequence") |
| 27 | + .iter() |
| 28 | + .map(|value| { |
| 29 | + let content_key: HistoryContentKey = |
| 30 | + serde_yaml::from_value(value["content_key"].clone()) |
| 31 | + .expect("to find content key"); |
| 32 | + let raw_content_value = Bytes::from_str( |
| 33 | + value["content_value"] |
| 34 | + .as_str() |
| 35 | + .expect("to find content value"), |
| 36 | + ) |
| 37 | + .expect("unable to convert content value to bytes"); |
| 38 | + let content_value = |
| 39 | + HistoryContentValue::decode(&content_key, raw_content_value.as_ref()) |
| 40 | + .expect("unable to decode content value"); |
| 41 | + (content_key, content_value) |
| 42 | + }) |
| 43 | + .collect::<Vec<_>>(); |
| 44 | + |
| 45 | + content.extend(test_case); |
| 46 | + } |
| 47 | + |
| 48 | + Ok(content) |
31 | 49 | }
|
32 | 50 |
|
33 | 51 | lazy_static::lazy_static! {
|
|
0 commit comments