-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathmock_validator.rs
More file actions
68 lines (53 loc) · 1.97 KB
/
mock_validator.rs
File metadata and controls
68 lines (53 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use alloy::{
primitives::B256,
rpc::types::beacon::{relay::ValidatorRegistration, BlsPublicKey},
};
use cb_common::pbs::{GetHeaderResponse, RelayClient, SignedBlindedBeaconBlock};
use reqwest::Error;
use crate::utils::generate_mock_relay;
pub struct MockValidator {
comm_boost: RelayClient,
}
impl MockValidator {
pub fn new(port: u16) -> eyre::Result<Self> {
Ok(Self { comm_boost: generate_mock_relay(port, BlsPublicKey::default())? })
}
pub async fn do_get_header(&self, pubkey: Option<BlsPublicKey>) -> Result<(), Error> {
let url = self
.comm_boost
.get_header_url(0, B256::ZERO, pubkey.unwrap_or(BlsPublicKey::ZERO))
.unwrap();
let res = self.comm_boost.client.get(url).send().await?.bytes().await?;
assert!(serde_json::from_slice::<GetHeaderResponse>(&res).is_ok());
Ok(())
}
pub async fn do_get_status(&self) -> Result<(), Error> {
let url = self.comm_boost.get_status_url().unwrap();
let _res = self.comm_boost.client.get(url).send().await?;
// assert!(res.status().is_success());
Ok(())
}
pub async fn do_register_validator(&self) -> Result<(), Error> {
self.do_register_custom_validators(vec![]).await
}
pub async fn do_register_custom_validators(
&self,
registrations: Vec<ValidatorRegistration>,
) -> Result<(), Error> {
let url = self.comm_boost.register_validator_url().unwrap();
self.comm_boost.client.post(url).json(®istrations).send().await?.error_for_status()?;
Ok(())
}
pub async fn do_submit_block(&self) -> Result<(), Error> {
let url = self.comm_boost.submit_block_url().unwrap();
let signed_blinded_block = SignedBlindedBeaconBlock::default();
self.comm_boost
.client
.post(url)
.json(&signed_blinded_block)
.send()
.await?
.error_for_status()?;
Ok(())
}
}