Skip to content

Commit

Permalink
fix(sidecar): tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Oct 10, 2024
1 parent cdad85b commit c08b09a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
20 changes: 5 additions & 15 deletions bolt-sidecar/src/config/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,21 @@ use rand::{Rng, RngCore};
#[derive(Args)]
#[clap(
group = ArgGroup::new("signing-opts").required(true)
.args(&["private_key", "commit_boost_url", "commit_boost_jwt_hex", "keystore_password"])
.args(&["private_key", "commit_boost_address", "commit_boost_jwt_hex", "keystore_password"])
)]
pub struct SigningOpts {
/// Private key to use for signing preconfirmation requests
#[clap(long, env = "BOLT_SIDECAR_PRIVATE_KEY", group = "signing-opts")]
#[clap(long, env = "BOLT_SIDECAR_PRIVATE_KEY")]
pub private_key: Option<BlsSecretKey>,
/// Socket address for the commit-boost sidecar
#[clap(
long,
env = "BOLT_SIDECAR_CB_SIGNER_URL",
group = "signing-opts",
requires("commit_boost_jwt_hex")
)]
#[clap(long, env = "BOLT_SIDECAR_CB_SIGNER_URL", requires("commit_boost_jwt_hex"))]
pub commit_boost_address: Option<SocketAddr>,
/// JWT in hexadecimal format for authenticating with the commit-boost service
#[clap(
long,
env = "BOLT_SIDECAR_CB_JWT_HEX",
group = "signing-opts",
requires("commit_boost_url")
)]
#[clap(long, env = "BOLT_SIDECAR_CB_JWT_HEX", requires("commit_boost_address"))]
pub commit_boost_jwt_hex: Option<JwtSecretConfig>,
/// The password for the ERC-2335 keystore.
/// Reference: https://eips.ethereum.org/EIPS/eip-2335
#[clap(long, env = "BOLT_SIDECAR_KEYSTORE_PASSWORD", group = "signing-opts")]
#[clap(long, env = "BOLT_SIDECAR_KEYSTORE_PASSWORD")]
pub keystore_password: Option<ZeroizeString>,
}

Expand Down
15 changes: 11 additions & 4 deletions bolt-sidecar/src/config/validator_indexes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::str::FromStr;
use std::{
fmt::{self, Display},
str::FromStr,
};

#[derive(Debug, Clone, Default)]
pub struct ValidatorIndexes(Vec<u64>);
Expand All @@ -24,6 +27,10 @@ impl FromStr for ValidatorIndexes {
let s = s.trim();
let mut vec = Vec::new();

if s.is_empty() {
return Ok(Self(vec));
}

for comma_separated_part in s.split(',') {
if comma_separated_part.contains("..") {
let mut parts = comma_separated_part.split("..");
Expand Down Expand Up @@ -51,9 +58,9 @@ impl From<Vec<u64>> for ValidatorIndexes {
}
}

impl ToString for ValidatorIndexes {
fn to_string(&self) -> String {
self.0.iter().map(|index| index.to_string()).collect::<Vec<_>>().join(",")
impl Display for ValidatorIndexes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0.iter().map(|index| index.to_string()).collect::<Vec<_>>().join(","))
}
}

Expand Down
9 changes: 6 additions & 3 deletions bolt-sidecar/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use secp256k1::Message;
use tracing::warn;

use crate::{
config::signing::BlsSecretKey,
config::signing::{BlsSecretKey, JwtSecretConfig},
crypto::{ecdsa::SignableECDSA, SignableBLS},
primitives::{
CommitmentRequest, ConstraintsMessage, DelegationMessage, FullTransaction,
Expand Down Expand Up @@ -79,9 +79,12 @@ pub(crate) async fn try_get_beacon_api_url() -> Option<&'static str> {
///
/// If any of the above values can't be found, the function will return `None`.
pub(crate) async fn get_test_config() -> Option<Opts> {
let sk = BlsSecretKey::random_bls_secret().to_string();
println!("sk: {}", sk);
std::env::set_var("BOLT_SIDECAR_PRIVATE_KEY", BlsSecretKey::random_bls_secret().to_string());

let _ = dotenvy::dotenv();

std::env::set_var("BOLT_SIDECAR_PRIVATE_KEY", BlsSecretKey::random_bls_secret().to_string());
let mut opts = Opts::parse();

let Some(jwt) = std::env::var("ENGINE_JWT").ok() else {
Expand All @@ -98,7 +101,7 @@ pub(crate) async fn get_test_config() -> Option<Opts> {
if let Some(url) = try_get_engine_api_url().await {
opts.engine_api_url = url.parse().expect("valid URL");
}
opts.jwt_hex = jwt;
opts.jwt_hex = JwtSecretConfig(jwt);

Some(opts)
}
Expand Down

0 comments on commit c08b09a

Please sign in to comment.