Skip to content

Commit 12a534a

Browse files
authored
chore: add more tests (#243)
1 parent adf548b commit 12a534a

15 files changed

+966
-359
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cb-config.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chain = "Holesky"
2+
3+
[pbs]
4+
port = 18550
5+
6+
[[relays]]
7+
url = "https://0xaa58208899c6105603b74396734a6263cc7d947f444f396a90f7b7d3e65d102aec7e5e5291b27e08d02c50a050825c2f@holesky.titanrelay.xyz"

tests/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ tracing-subscriber.workspace = true
2323

2424
tree_hash.workspace = true
2525
eyre.workspace = true
26+
27+
url.workspace = true

tests/data/configs/pbs.happy.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
chain = "Holesky"
2+
3+
[pbs]
4+
docker_image = "ghcr.io/commit-boost/pbs:latest"
5+
with_signer = false
6+
host = "127.0.0.1"
7+
port = 18550
8+
relay_check = true
9+
wait_all_registrations = true
10+
timeout_get_header_ms = 950
11+
timeout_get_payload_ms = 4000
12+
timeout_register_validator_ms = 3000
13+
skip_sigverify = false
14+
min_bid_eth = 0.5
15+
relay_monitors = []
16+
late_in_slot_time_ms = 2000
17+
extra_validation_enabled = false
18+
rpc_url = "https://ethereum-holesky-rpc.publicnode.com"
19+
20+
[[relays]]
21+
id = "example-relay"
22+
url = "http://0xa1cec75a3f0661e99299274182938151e8433c61a19222347ea1313d839229cb4ce4e3e5aa2bdeb71c8fcf1b084963c2@abc.xyz"
23+
headers = { X-MyCustomHeader = "MyCustomHeader" }
24+
enable_timing_games = false
25+
target_first_request_ms = 200
26+
frequency_get_header_ms = 300

tests/src/mock_relay.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ impl MockRelayState {
6262
pub fn received_submit_block(&self) -> u64 {
6363
self.received_submit_block.load(Ordering::Relaxed)
6464
}
65+
pub fn large_body(&self) -> bool {
66+
self.large_body
67+
}
6568
}
6669

6770
impl MockRelayState {
@@ -108,7 +111,7 @@ async fn handle_get_header(
108111

109112
let object_root = response.data.message.tree_hash_root().0;
110113
response.data.signature = sign_builder_root(state.chain, &state.signer, object_root);
111-
(StatusCode::OK, axum::Json(response)).into_response()
114+
(StatusCode::OK, Json(response)).into_response()
112115
}
113116

114117
async fn handle_get_status(State(state): State<Arc<MockRelayState>>) -> impl IntoResponse {
@@ -125,14 +128,12 @@ async fn handle_register_validator(
125128
StatusCode::OK
126129
}
127130

128-
async fn handle_submit_block(State(state): State<Arc<MockRelayState>>) -> impl IntoResponse {
131+
async fn handle_submit_block(State(state): State<Arc<MockRelayState>>) -> Response {
129132
state.received_submit_block.fetch_add(1, Ordering::Relaxed);
130-
131-
let response = if state.large_body {
132-
vec![1u8; 1 + MAX_SIZE_SUBMIT_BLOCK]
133+
if state.large_body() {
134+
(StatusCode::OK, Json(vec![1u8; 1 + MAX_SIZE_SUBMIT_BLOCK])).into_response()
133135
} else {
134-
serde_json::to_vec(&SubmitBlindedBlockResponse::default()).unwrap()
135-
};
136-
137-
(StatusCode::OK, Json(response)).into_response()
136+
let response = SubmitBlindedBlockResponse::default();
137+
(StatusCode::OK, Json(response)).into_response()
138+
}
138139
}

tests/src/mock_validator.rs

+20-32
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,55 @@ use alloy::{
22
primitives::B256,
33
rpc::types::beacon::{relay::ValidatorRegistration, BlsPublicKey},
44
};
5-
use cb_common::pbs::{GetHeaderResponse, RelayClient, SignedBlindedBeaconBlock};
6-
use reqwest::Error;
5+
use cb_common::pbs::{RelayClient, SignedBlindedBeaconBlock};
6+
use reqwest::Response;
77

88
use crate::utils::generate_mock_relay;
99

1010
pub struct MockValidator {
11-
comm_boost: RelayClient,
11+
pub comm_boost: RelayClient,
1212
}
1313

1414
impl MockValidator {
1515
pub fn new(port: u16) -> eyre::Result<Self> {
1616
Ok(Self { comm_boost: generate_mock_relay(port, BlsPublicKey::default())? })
1717
}
1818

19-
pub async fn do_get_header(&self, pubkey: Option<BlsPublicKey>) -> Result<(), Error> {
20-
let url = self
21-
.comm_boost
22-
.get_header_url(0, B256::ZERO, pubkey.unwrap_or(BlsPublicKey::ZERO))
23-
.unwrap();
24-
let res = self.comm_boost.client.get(url).send().await?.bytes().await?;
25-
assert!(serde_json::from_slice::<GetHeaderResponse>(&res).is_ok());
26-
27-
Ok(())
19+
pub async fn do_get_header(&self, pubkey: Option<BlsPublicKey>) -> eyre::Result<Response> {
20+
let url = self.comm_boost.get_header_url(0, B256::ZERO, pubkey.unwrap_or_default())?;
21+
Ok(self.comm_boost.client.get(url).send().await?)
2822
}
2923

30-
pub async fn do_get_status(&self) -> Result<(), Error> {
31-
let url = self.comm_boost.get_status_url().unwrap();
32-
let _res = self.comm_boost.client.get(url).send().await?;
33-
// assert!(res.status().is_success());
34-
35-
Ok(())
24+
pub async fn do_get_status(&self) -> eyre::Result<Response> {
25+
let url = self.comm_boost.get_status_url()?;
26+
Ok(self.comm_boost.client.get(url).send().await?)
3627
}
3728

38-
pub async fn do_register_validator(&self) -> Result<(), Error> {
29+
pub async fn do_register_validator(&self) -> eyre::Result<Response> {
3930
self.do_register_custom_validators(vec![]).await
4031
}
4132

4233
pub async fn do_register_custom_validators(
4334
&self,
4435
registrations: Vec<ValidatorRegistration>,
45-
) -> Result<(), Error> {
36+
) -> eyre::Result<Response> {
4637
let url = self.comm_boost.register_validator_url().unwrap();
4738

48-
self.comm_boost.client.post(url).json(&registrations).send().await?.error_for_status()?;
49-
50-
Ok(())
39+
Ok(self.comm_boost.client.post(url).json(&registrations).send().await?)
5140
}
5241

53-
pub async fn do_submit_block(&self) -> Result<(), Error> {
42+
pub async fn do_submit_block(
43+
&self,
44+
signed_blinded_block: Option<SignedBlindedBeaconBlock>,
45+
) -> eyre::Result<Response> {
5446
let url = self.comm_boost.submit_block_url().unwrap();
5547

56-
let signed_blinded_block = SignedBlindedBeaconBlock::default();
57-
58-
self.comm_boost
48+
Ok(self
49+
.comm_boost
5950
.client
6051
.post(url)
61-
.json(&signed_blinded_block)
52+
.json(&signed_blinded_block.unwrap_or_default())
6253
.send()
63-
.await?
64-
.error_for_status()?;
65-
66-
Ok(())
54+
.await?)
6755
}
6856
}

tests/src/utils.rs

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
use std::sync::Once;
1+
use std::{
2+
net::{Ipv4Addr, SocketAddr},
3+
sync::{Arc, Once},
4+
};
25

3-
use alloy::rpc::types::beacon::BlsPublicKey;
6+
use alloy::{primitives::U256, rpc::types::beacon::BlsPublicKey};
47
use cb_common::{
5-
config::RelayConfig,
8+
config::{PbsConfig, PbsModuleConfig, RelayConfig},
69
pbs::{RelayClient, RelayEntry},
10+
types::Chain,
711
};
812
use eyre::Result;
913

@@ -51,3 +55,38 @@ pub fn generate_mock_relay_with_batch_size(
5155
};
5256
RelayClient::new(config)
5357
}
58+
59+
pub fn get_pbs_static_config(port: u16) -> PbsConfig {
60+
PbsConfig {
61+
host: Ipv4Addr::UNSPECIFIED,
62+
port,
63+
wait_all_registrations: true,
64+
relay_check: true,
65+
timeout_get_header_ms: u64::MAX,
66+
timeout_get_payload_ms: u64::MAX,
67+
timeout_register_validator_ms: u64::MAX,
68+
skip_sigverify: false,
69+
min_bid_wei: U256::ZERO,
70+
late_in_slot_time_ms: u64::MAX,
71+
relay_monitors: vec![],
72+
extra_validation_enabled: false,
73+
rpc_url: None,
74+
}
75+
}
76+
77+
pub fn to_pbs_config(
78+
chain: Chain,
79+
pbs_config: PbsConfig,
80+
relays: Vec<RelayClient>,
81+
) -> PbsModuleConfig {
82+
PbsModuleConfig {
83+
chain,
84+
endpoint: SocketAddr::new(pbs_config.host.into(), pbs_config.port),
85+
pbs_config: Arc::new(pbs_config),
86+
signer_client: None,
87+
event_publisher: None,
88+
all_relays: relays.clone(),
89+
relays,
90+
muxes: None,
91+
}
92+
}

0 commit comments

Comments
 (0)