Skip to content

Commit bd98353

Browse files
authored
simulators/portal: update history tests to use new test data format (#1283)
1 parent aa46f75 commit bd98353

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

simulators/portal/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ ARG PORTAL_CONSENSUS_AUTH
3434
ENV PORTAL_CONSENSUS_URL=$PORTAL_CONSENSUS_URL
3535
ENV PORTAL_CONSENSUS_AUTH=$PORTAL_CONSENSUS_AUTH
3636

37-
RUN apt-get update && apt-get install -y wget
37+
RUN apt-get update && apt-get install -y wget git ca-certificates
3838

3939
# copy build artifacts from build stage
4040
COPY --from=builder /portal/target/release/portal .
41-
ADD https://raw.githubusercontent.com/ethereum/portal-spec-tests/master/tests/mainnet/history/hive/test_data_collection_of_forks_blocks.yaml ./test-data/test_data_collection_of_forks_blocks.yaml
42-
ADD https://raw.githubusercontent.com/ethereum/portal-spec-tests/master/tests/mainnet/state/hive/test_data.yaml ./test-data/state_test_data.yaml
43-
ADD https://raw.githubusercontent.com/ethereum/portal-spec-tests/master/tests/mainnet/beacon_chain/hive/test_data.yaml ./test-data/beacon_test_data.yaml
41+
42+
# clone portal-spec-tests repo. The add command is used to reset docker's cache so new data is pulled
43+
ADD "https://api.github.com/repos/ethereum/portal-spec-tests/commits?per_page=1" latest_commit
44+
RUN git clone https://github.com/ethereum/portal-spec-tests.git ./portal-spec-tests
4445

4546
ENV RUST_LOG=debug,hyper_util=info,hyper=info,reqwest=info
4647

simulators/portal/src/suites/beacon/constants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use ethportal_api::{BeaconContentKey, BeaconContentValue, ContentValue};
33
use serde_yaml::Value;
44
use std::str::FromStr;
55

6-
pub const TEST_DATA_FILE_PATH: &str = "./test-data/beacon_test_data.yaml";
6+
pub const TEST_DATA_FILE_PATH: &str =
7+
"./portal-spec-tests/tests/mainnet/beacon_chain/hive/test_data.yaml";
78

89
pub fn get_test_data() -> anyhow::Result<Vec<(BeaconContentKey, BeaconContentValue)>> {
910
let values = std::fs::read_to_string(TEST_DATA_FILE_PATH)?;

simulators/portal/src/suites/history/constants.rs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
11
use alloy_primitives::Bytes;
2+
use anyhow::bail;
23
use ethportal_api::{ContentValue, HistoryContentKey, HistoryContentValue};
34
use serde_yaml::Value;
45
use std::str::FromStr;
56

6-
pub const TEST_DATA_FILE_PATH: &str = "./test-data/test_data_collection_of_forks_blocks.yaml";
7-
87
// trin-bridge constants
98
pub const TRIN_BRIDGE_CLIENT_TYPE: &str = "trin-bridge";
109

10+
pub const TEST_DATA_FILE_PATH: &str = "./portal-spec-tests/tests/mainnet/history/hive/success";
11+
1112
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)
3149
}
3250

3351
lazy_static::lazy_static! {

simulators/portal/src/suites/state/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloy_primitives::Bytes;
22
use ethportal_api::StateContentKey;
33
use std::str::FromStr;
44

5-
pub const TEST_DATA_FILE_PATH: &str = "./test-data/state_test_data.yaml";
5+
pub const TEST_DATA_FILE_PATH: &str = "./portal-spec-tests/tests/mainnet/state/hive/test_data.yaml";
66

77
// trin-bridge constants
88
pub const TRIN_BRIDGE_CLIENT_TYPE: &str = "trin-bridge";

0 commit comments

Comments
 (0)