Skip to content

Commit e876897

Browse files
committed
simulators/portal: refactor sims into 1 sim multi suite format
1 parent 30ef942 commit e876897

File tree

22 files changed

+187
-376
lines changed

22 files changed

+187
-376
lines changed

simulators/portal/beacon/rpc-compat/Dockerfile renamed to simulators/portal/beacon/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM rust:1.71.1 AS builder
1+
FROM rust:1.75.0 AS builder
22

33
# create a new empty shell project
4-
RUN USER=root cargo new --bin rpc-compat
5-
WORKDIR /rpc-compat
4+
RUN USER=root cargo new --bin beacon
5+
WORKDIR /beacon
66

77
RUN apt-get update && apt-get install clang -y
88

@@ -19,8 +19,8 @@ FROM ubuntu:22.04
1919
RUN apt update && apt install wget -y
2020

2121
# copy build artifacts from build stage
22-
COPY --from=builder /rpc-compat/target/release/rpc-compat .
22+
COPY --from=builder /beacon/target/release/beacon .
2323

2424
ENV RUST_LOG=debug
2525

26-
ENTRYPOINT ["./rpc-compat"]
26+
ENTRYPOINT ["./beacon"]

simulators/portal/beacon/rpc-compat/Cargo.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

simulators/portal/beacon/src/main.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
mod suites;
2+
3+
use hivesim::{Simulation, Suite, TestSpec};
4+
use suites::rpc_compat::run_rpc_compat_test_suite;
5+
6+
#[tokio::main]
7+
async fn main() {
8+
tracing_subscriber::fmt::init();
9+
let mut beacon_rpc_compat = Suite {
10+
name: "beacon-rpc-compat".to_string(),
11+
description: "The RPC-compatibility test suite runs a set of RPC related tests against a
12+
running node. It tests client implementations of the JSON-RPC API for
13+
conformance with the portal network API specification."
14+
.to_string(),
15+
tests: vec![],
16+
};
17+
18+
beacon_rpc_compat.add(TestSpec {
19+
name: "client launch".to_string(),
20+
description: "This test launches the client and collects its logs.".to_string(),
21+
always_run: false,
22+
run: run_rpc_compat_test_suite,
23+
client: None,
24+
});
25+
26+
let sim = Simulation::new();
27+
run_suite(sim, vec![beacon_rpc_compat]).await;
28+
}
29+
30+
async fn run_suite(host: Simulation, suites: Vec<Suite>) {
31+
for suite in suites {
32+
let name = suite.clone().name;
33+
let description = suite.clone().description;
34+
35+
let suite_id = host.start_suite(name, description, "".to_string()).await;
36+
37+
for test in &suite.tests {
38+
test.run_test(host.clone(), suite_id, suite.clone()).await;
39+
}
40+
41+
host.end_suite(suite_id).await;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
pub const HIVE_PORTAL_NETWORKS_SELECTED: &str = "HIVE_PORTAL_NETWORKS_SELECTED";
22
pub const BEACON_STRING: &str = "beacon";
3+
4+
// trin-bridge constants
5+
pub const TRIN_BRIDGE_CLIENT_TYPE: &str = "trin-bridge";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod constants;
2+
pub mod rpc_compat;

simulators/portal/beacon/rpc-compat/src/main.rs renamed to simulators/portal/beacon/src/suites/rpc_compat.rs

Lines changed: 8 additions & 43 deletions
Large diffs are not rendered by default.

simulators/portal/history/portal-interop/Dockerfile renamed to simulators/portal/history/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM rust:1.71.1 AS builder
1+
FROM rust:1.75.0 AS builder
22

33
# create a new empty shell project
4-
RUN USER=root cargo new --bin portal-interop
5-
WORKDIR /portal-interop
4+
RUN USER=root cargo new --bin history
5+
WORKDIR /history
66

77
# copy over manifests and source to build image
88
COPY Cargo.toml ./Cargo.toml
@@ -17,9 +17,9 @@ FROM ubuntu:22.04
1717
RUN apt update && apt install wget -y
1818

1919
# copy build artifacts from build stage
20-
COPY --from=builder /portal-interop/target/release/portal-interop .
20+
COPY --from=builder /history/target/release/history .
2121
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
2222

2323
ENV RUST_LOG=debug
2424

25-
ENTRYPOINT ["./portal-interop"]
25+
ENTRYPOINT ["./history"]

simulators/portal/history/portal-interop/Cargo.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

simulators/portal/history/portal-interop/src/constants.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

simulators/portal/history/portal-mesh/Cargo.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

simulators/portal/history/portal-mesh/Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

simulators/portal/history/rpc-compat/Cargo.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

simulators/portal/history/rpc-compat/Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

simulators/portal/history/src/main.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
pub mod suites;
2+
3+
use hivesim::{Simulation, Suite, TestSpec};
4+
use suites::interop::test_portal_interop;
5+
use suites::mesh::test_portal_scenarios;
6+
use suites::rpc_compat::run_rpc_compat_test_suite;
7+
use suites::trin_bridge::test_portal_bridge;
8+
9+
#[tokio::main]
10+
async fn main() {
11+
tracing_subscriber::fmt::init();
12+
let mut rpc_compat = Suite {
13+
name: "history-rpc-compat".to_string(),
14+
description: "The RPC-compatibility test suite runs a set of RPC related tests against a
15+
running node. It tests client implementations of the JSON-RPC API for
16+
conformance with the portal network API specification."
17+
.to_string(),
18+
tests: vec![],
19+
};
20+
21+
rpc_compat.add(TestSpec {
22+
name: "client launch".to_string(),
23+
description: "This test launches the client and collects its logs.".to_string(),
24+
always_run: false,
25+
run: run_rpc_compat_test_suite,
26+
client: None,
27+
});
28+
29+
let mut interop = Suite {
30+
name: "history-interop".to_string(),
31+
description:
32+
"The interop test suite runs a set of scenarios to test interoperability between
33+
portal network clients"
34+
.to_string(),
35+
tests: vec![],
36+
};
37+
38+
interop.add(TestSpec {
39+
name: "client launch".to_string(),
40+
description: "This test launches the client and collects its logs.".to_string(),
41+
always_run: false,
42+
run: test_portal_interop,
43+
client: None,
44+
});
45+
46+
let mut mesh = Suite {
47+
name: "history-mesh".to_string(),
48+
description: "The portal mesh test suite runs a set of scenarios to test 3 clients"
49+
.to_string(),
50+
tests: vec![],
51+
};
52+
53+
mesh.add(TestSpec {
54+
name: "client launch".to_string(),
55+
description: "This test launches the client and collects its logs.".to_string(),
56+
always_run: false,
57+
run: test_portal_scenarios,
58+
client: None,
59+
});
60+
61+
let mut trin_bridge = Suite {
62+
name: "history-trin-bridge".to_string(),
63+
description: "The portal bridge test suite".to_string(),
64+
tests: vec![],
65+
};
66+
67+
trin_bridge.add(TestSpec {
68+
name: "client launch".to_string(),
69+
description: "This test launches the client and collects its logs.".to_string(),
70+
always_run: false,
71+
run: test_portal_bridge,
72+
client: None,
73+
});
74+
75+
let sim = Simulation::new();
76+
run_suite(sim, vec![rpc_compat, interop, mesh, trin_bridge]).await;
77+
}
78+
79+
async fn run_suite(host: Simulation, suites: Vec<Suite>) {
80+
for suite in suites {
81+
let name = suite.clone().name;
82+
let description = suite.clone().description;
83+
84+
let suite_id = host.start_suite(name, description, "".to_string()).await;
85+
86+
for test in &suite.tests {
87+
test.run_test(host.clone(), suite_id, suite.clone()).await;
88+
}
89+
90+
host.end_suite(suite_id).await;
91+
}
92+
}

simulators/portal/history/trin-bridge/src/constants.rs renamed to simulators/portal/history/src/suites/constants.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
pub const TEST_DATA_FILE_PATH: &str = "./test-data/test_data_collection_of_forks_blocks.yaml";
2+
3+
// trin-bridge constants
14
pub const TRIN_BRIDGE_CLIENT_TYPE: &str = "trin-bridge";
25
pub const BOOTNODES_ENVIRONMENT_VARIABLE: &str = "HIVE_BOOTNODES";
36
pub const HIVE_CHECK_LIVE_PORT: &str = "HIVE_CHECK_LIVE_PORT";
4-
pub const TEST_DATA_FILE_PATH: &str = "./test-data/test_data_collection_of_forks_blocks.yaml";

simulators/portal/history/portal-interop/src/main.rs renamed to simulators/portal/history/src/suites/interop.rs

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
mod constants;
2-
3-
use crate::constants::TEST_DATA_FILE_PATH;
1+
use crate::suites::constants::{TEST_DATA_FILE_PATH, TRIN_BRIDGE_CLIENT_TYPE};
42
use ethportal_api::types::portal::ContentInfo;
53
use ethportal_api::utils::bytes::hex_encode;
64
use ethportal_api::{
75
ContentValue, Discv5ApiClient, HistoryContentKey, HistoryContentValue, HistoryNetworkApiClient,
86
OverlayContentKey, PossibleHistoryContentValue,
97
};
10-
use hivesim::{dyn_async, Client, NClientTestSpec, Simulation, Suite, Test, TestSpec};
8+
use hivesim::types::ClientDefinition;
9+
use hivesim::{dyn_async, Client, NClientTestSpec, Test};
1110
use itertools::Itertools;
1211
use portal_spec_test_utils_rs::get_flair;
1312
use serde_json::json;
@@ -21,44 +20,6 @@ const MAX_PORTAL_CONTENT_PAYLOAD_SIZE: usize = 1165;
2120
const HEADER_WITH_PROOF_KEY: &str =
2221
"0x00720704f3aa11c53cf344ea069db95cecb81ad7453c8f276b2a1062979611f09c";
2322

24-
#[tokio::main]
25-
async fn main() {
26-
tracing_subscriber::fmt::init();
27-
28-
let mut suite = Suite {
29-
name: "portal-interop".to_string(),
30-
description:
31-
"The portal interop test suite runs a set of scenarios to test interoperability between
32-
portal network clients"
33-
.to_string(),
34-
tests: vec![],
35-
};
36-
37-
suite.add(TestSpec {
38-
name: "Portal Network interop".to_string(),
39-
description: "".to_string(),
40-
always_run: false,
41-
run: test_portal_interop,
42-
client: None,
43-
});
44-
45-
let sim = Simulation::new();
46-
run_suite(sim, suite).await;
47-
}
48-
49-
async fn run_suite(host: Simulation, suite: Suite) {
50-
let name = suite.clone().name;
51-
let description = suite.clone().description;
52-
53-
let suite_id = host.start_suite(name, description, "".to_string()).await;
54-
55-
for test in &suite.tests {
56-
test.run_test(host.clone(), suite_id, suite.clone()).await;
57-
}
58-
59-
host.end_suite(suite_id).await;
60-
}
61-
6223
fn content_pair_to_string_pair(
6324
content_pair: (HistoryContentKey, HistoryContentValue),
6425
) -> (String, String) {
@@ -126,9 +87,11 @@ fn process_content(
12687
}
12788

12889
dyn_async! {
129-
async fn test_portal_interop<'a> (test: &'a mut Test, _client: Option<Client>) {
90+
pub async fn test_portal_interop<'a> (test: &'a mut Test, _client: Option<Client>) {
13091
// Get all available portal clients
13192
let clients = test.sim.client_types().await;
93+
// todo: remove this once we implement role in hivesim-rs
94+
let clients: Vec<ClientDefinition> = clients.into_iter().filter(|client| client.name != *TRIN_BRIDGE_CLIENT_TYPE).collect();
13295

13396
let values = std::fs::read_to_string(TEST_DATA_FILE_PATH)
13497
.expect("cannot find test asset");

0 commit comments

Comments
 (0)