From c08b09a5b216cbe7ab326acb9fd24ff601495599 Mon Sep 17 00:00:00 2001 From: thedevbirb Date: Thu, 10 Oct 2024 12:57:27 +0200 Subject: [PATCH] fix(sidecar): tests --- bolt-sidecar/src/config/signing.rs | 20 +++++--------------- bolt-sidecar/src/config/validator_indexes.rs | 15 +++++++++++---- bolt-sidecar/src/test_util.rs | 9 ++++++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bolt-sidecar/src/config/signing.rs b/bolt-sidecar/src/config/signing.rs index a6a641062..ba068e92f 100644 --- a/bolt-sidecar/src/config/signing.rs +++ b/bolt-sidecar/src/config/signing.rs @@ -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, /// 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, /// 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, /// 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, } diff --git a/bolt-sidecar/src/config/validator_indexes.rs b/bolt-sidecar/src/config/validator_indexes.rs index 2cfa72ac6..48e8cca0a 100644 --- a/bolt-sidecar/src/config/validator_indexes.rs +++ b/bolt-sidecar/src/config/validator_indexes.rs @@ -1,4 +1,7 @@ -use std::str::FromStr; +use std::{ + fmt::{self, Display}, + str::FromStr, +}; #[derive(Debug, Clone, Default)] pub struct ValidatorIndexes(Vec); @@ -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(".."); @@ -51,9 +58,9 @@ impl From> for ValidatorIndexes { } } -impl ToString for ValidatorIndexes { - fn to_string(&self) -> String { - self.0.iter().map(|index| index.to_string()).collect::>().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::>().join(",")) } } diff --git a/bolt-sidecar/src/test_util.rs b/bolt-sidecar/src/test_util.rs index 012fdb4f2..28b72a24d 100644 --- a/bolt-sidecar/src/test_util.rs +++ b/bolt-sidecar/src/test_util.rs @@ -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, @@ -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 { + 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 { @@ -98,7 +101,7 @@ pub(crate) async fn get_test_config() -> Option { 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) }