From 98a5bc0bc654926d29bca0a9e15d03c7ac6041a7 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Fri, 8 Nov 2024 18:19:41 +0530 Subject: [PATCH] update: clean up --- crates/orchestrator/src/alerts/aws_sns/mod.rs | 4 +- crates/orchestrator/src/cli/aws_config.rs | 15 +-- crates/orchestrator/src/cli/mod.rs | 102 ++++++++++-------- crates/orchestrator/src/config.rs | 63 ++++------- .../src/data_storage/aws_s3/mod.rs | 2 +- .../orchestrator/src/database/mongodb/mod.rs | 2 +- crates/orchestrator/src/main.rs | 2 - crates/orchestrator/src/tests/common/mod.rs | 4 +- crates/orchestrator/src/tests/config.rs | 21 ++-- .../sharp-service/src/client.rs | 2 +- .../prover-services/sharp-service/src/lib.rs | 8 +- .../sharp-service/tests/lib.rs | 4 +- crates/settlement-clients/ethereum/src/lib.rs | 6 +- .../ethereum/src/tests/mod.rs | 6 +- crates/settlement-clients/starknet/src/lib.rs | 2 +- .../starknet/src/tests/test.rs | 2 +- e2e-tests/src/localstack.rs | 2 +- e2e-tests/tests.rs | 4 +- 18 files changed, 118 insertions(+), 133 deletions(-) diff --git a/crates/orchestrator/src/alerts/aws_sns/mod.rs b/crates/orchestrator/src/alerts/aws_sns/mod.rs index 66643535..45cd1902 100644 --- a/crates/orchestrator/src/alerts/aws_sns/mod.rs +++ b/crates/orchestrator/src/alerts/aws_sns/mod.rs @@ -8,6 +8,8 @@ use crate::config::ProviderConfig; #[derive(Debug, Clone)] pub struct AWSSNSParams { + // TODO: convert to ARN type, and validate it + // NOTE: aws is using str to represent ARN : https://docs.aws.amazon.com/sdk-for-rust/latest/dg/rust_sns_code_examples.html pub sns_arn: String, } @@ -23,7 +25,7 @@ pub struct AWSSNS { } impl AWSSNS { - pub async fn new_with_settings(aws_sns_params: &AWSSNSParams, provider_config: Arc) -> Self { + pub async fn new_with_params(aws_sns_params: &AWSSNSParams, provider_config: Arc) -> Self { let config = provider_config.get_aws_client_or_panic(); Self { client: Client::new(config), topic_arn: aws_sns_params.sns_arn.clone() } } diff --git a/crates/orchestrator/src/cli/aws_config.rs b/crates/orchestrator/src/cli/aws_config.rs index 6e0aae2c..d65b5bee 100644 --- a/crates/orchestrator/src/cli/aws_config.rs +++ b/crates/orchestrator/src/cli/aws_config.rs @@ -1,10 +1,11 @@ use clap::Args; use serde::Serialize; +use url::Url; /// Parameters used to config AWS. #[derive(Debug, Clone, Args, Serialize)] #[group(requires_all = ["aws_access_key_id", "aws_secret_access_key", "aws_region"])] -pub struct AWSConfigParams { +pub struct AWSConfigCliArgs { /// The access key ID. #[arg(env = "AWS_ACCESS_KEY_ID", long)] pub aws_access_key_id: String, @@ -16,12 +17,12 @@ pub struct AWSConfigParams { /// The region. #[arg(env = "AWS_REGION", long)] pub aws_region: String, +} - /// The endpoint URL. - #[arg(env = "AWS_ENDPOINT_URL", long, default_value = "http://localhost.localstack.cloud:4566")] - pub aws_endpoint_url: String, - - /// The default region. - #[arg(env = "AWS_DEFAULT_REGION", long, default_value = "localhost")] +pub struct AWSConfigParams { + pub aws_access_key_id: String, + pub aws_secret_access_key: String, + pub aws_region: String, + pub aws_endpoint_url: Url, pub aws_default_region: String, } diff --git a/crates/orchestrator/src/cli/mod.rs b/crates/orchestrator/src/cli/mod.rs index ad3dfe73..4a3aaeb5 100644 --- a/crates/orchestrator/src/cli/mod.rs +++ b/crates/orchestrator/src/cli/mod.rs @@ -1,5 +1,5 @@ use alert::AlertParams; -use aws_config::AWSConfigParams; +use aws_config::{AWSConfigCliArgs, AWSConfigParams}; use clap::{ArgGroup, Parser}; use da::DaParams; use database::DatabaseParams; @@ -78,7 +78,7 @@ pub mod storage; pub struct RunCmd { // AWS Config #[clap(flatten)] - pub aws_config_args: AWSConfigParams, + pub aws_config_args: AWSConfigCliArgs, // Settlement Layer #[command(flatten)] @@ -129,52 +129,27 @@ pub struct RunCmd { } impl RunCmd { - pub fn validate_settlement_params(&self) -> Result { - match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { - (true, false) => { - // TODO: Ensure Starknet params are not provided + pub fn validate_aws_config_params(&self) -> Result { + let aws_endpoint_url = Url::parse("http://localhost.localstack.cloud:4566").unwrap(); + let aws_default_region = "localhost".to_string(); - // Get Ethereum params or error if none provided - // Either all the values are provided or panic - let ethereum_params = EthereumSettlementParams { - ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().unwrap(), - ethereum_private_key: self.ethereum_args.ethereum_private_key.clone().unwrap(), - l1_core_contract_address: self.ethereum_args.l1_core_contract_address.clone().unwrap(), - starknet_operator_address: self.ethereum_args.starknet_operator_address.clone().unwrap(), - }; - Ok(SettlementParams::Ethereum(ethereum_params)) - } - (false, true) => { - // TODO: Ensure Ethereum params are not provided + tracing::warn!("Setting AWS_ENDPOINT_URL to {} for AWS SDK to use", aws_endpoint_url); + tracing::warn!("Setting AWS_DEFAULT_REGION to {} for Omniqueue to use", aws_default_region); - // Get Starknet params or error if none provided - // Either all the values are provided or panic - let starknet_params = StarknetSettlementParams { - starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().unwrap(), - starknet_private_key: self.starknet_args.starknet_private_key.clone().unwrap(), - starknet_account_address: self.starknet_args.starknet_account_address.clone().unwrap(), - starknet_cairo_core_contract_address: self - .starknet_args - .starknet_cairo_core_contract_address - .clone() - .unwrap(), - starknet_finality_retry_wait_in_secs: self - .starknet_args - .starknet_finality_retry_wait_in_secs - .unwrap(), - madara_binary_path: self.starknet_args.madara_binary_path.clone().unwrap(), - }; - Ok(SettlementParams::Starknet(starknet_params)) - } - (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), - } + Ok(AWSConfigParams { + aws_access_key_id: self.aws_config_args.aws_access_key_id.clone(), + aws_secret_access_key: self.aws_config_args.aws_secret_access_key.clone(), + aws_region: self.aws_config_args.aws_region.clone(), + aws_endpoint_url, + aws_default_region, + }) } - pub fn validate_storage_params(&self) -> Result { - if self.aws_s3_args.aws_s3 { - Ok(StorageParams::AWSS3(AWSS3Params { bucket_name: self.aws_s3_args.bucket_name.clone().unwrap() })) + pub fn validate_alert_params(&self) -> Result { + if self.aws_sns_args.aws_sns { + Ok(AlertParams::AWSSNS(AWSSNSParams { sns_arn: self.aws_sns_args.sns_arn.clone().unwrap() })) } else { - Err("Only AWS S3 is supported as of now".to_string()) + Err("Only AWS SNS is supported as of now".to_string()) } } @@ -190,11 +165,11 @@ impl RunCmd { } } - pub fn validate_alert_params(&self) -> Result { - if self.aws_sns_args.aws_sns { - Ok(AlertParams::AWSSNS(AWSSNSParams { sns_arn: self.aws_sns_args.sns_arn.clone().unwrap() })) + pub fn validate_storage_params(&self) -> Result { + if self.aws_s3_args.aws_s3 { + Ok(StorageParams::AWSS3(AWSS3Params { bucket_name: self.aws_s3_args.bucket_name.clone().unwrap() })) } else { - Err("Only AWS SNS is supported as of now".to_string()) + Err("Only AWS S3 is supported as of now".to_string()) } } @@ -219,6 +194,39 @@ impl RunCmd { } } + pub fn validate_settlement_params(&self) -> Result { + match (self.ethereum_args.settle_on_ethereum, self.starknet_args.settle_on_starknet) { + (true, false) => { + let ethereum_params = EthereumSettlementParams { + ethereum_rpc_url: self.ethereum_args.ethereum_rpc_url.clone().unwrap(), + ethereum_private_key: self.ethereum_args.ethereum_private_key.clone().unwrap(), + l1_core_contract_address: self.ethereum_args.l1_core_contract_address.clone().unwrap(), + starknet_operator_address: self.ethereum_args.starknet_operator_address.clone().unwrap(), + }; + Ok(SettlementParams::Ethereum(ethereum_params)) + } + (false, true) => { + let starknet_params = StarknetSettlementParams { + starknet_rpc_url: self.starknet_args.starknet_rpc_url.clone().unwrap(), + starknet_private_key: self.starknet_args.starknet_private_key.clone().unwrap(), + starknet_account_address: self.starknet_args.starknet_account_address.clone().unwrap(), + starknet_cairo_core_contract_address: self + .starknet_args + .starknet_cairo_core_contract_address + .clone() + .unwrap(), + starknet_finality_retry_wait_in_secs: self + .starknet_args + .starknet_finality_retry_wait_in_secs + .unwrap(), + madara_binary_path: self.starknet_args.madara_binary_path.clone().unwrap(), + }; + Ok(SettlementParams::Starknet(starknet_params)) + } + (true, true) | (false, false) => Err("Exactly one settlement layer must be selected".to_string()), + } + } + pub fn validate_prover_params(&self) -> Result { if self.sharp_args.sharp { Ok(ProverParams::Sharp(SharpParams { diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 1f43ae12..1d8cf511 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -45,7 +45,7 @@ use crate::routes::ServerParams; /// by calling `config` function. pub struct Config { /// The orchestrator config - orchestrator_config: OrchestratorConfig, + orchestrator_params: OrchestratorParams, /// The starknet client to get data from the node starknet_client: Arc>, /// The DA client to interact with the DA layer @@ -70,7 +70,7 @@ pub struct ServiceParams { pub min_block_to_process: Option, } -pub struct OrchestratorConfig { +pub struct OrchestratorParams { pub madara_rpc_url: Url, pub snos_config: SNOSParams, pub service_config: ServiceParams, @@ -108,17 +108,17 @@ pub async fn get_aws_config(aws_config: &AWSConfigParams) -> SdkConfig { pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { dotenv().ok(); - let aws_config = &run_cmd.aws_config_args; + let aws_config = &run_cmd.validate_aws_config_params().expect("Failed to validate AWS config params"); let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(aws_config).await))); - let orchestrator_config = OrchestratorConfig { + let orchestrator_params = OrchestratorParams { madara_rpc_url: run_cmd.madara_rpc_url.clone(), snos_config: run_cmd.validate_snos_params().expect("Failed to validate SNOS params"), service_config: run_cmd.validate_service_params().expect("Failed to validate service params"), server_config: run_cmd.validate_server_params().expect("Failed to validate server params"), }; - let provider = JsonRpcClient::new(HttpTransport::new(orchestrator_config.madara_rpc_url.clone())); + let provider = JsonRpcClient::new(HttpTransport::new(orchestrator_params.madara_rpc_url.clone())); // init database let database_params = @@ -156,7 +156,7 @@ pub async fn init_config(run_cmd: &RunCmd) -> color_eyre::Result> { let queue = build_queue_client(&queue_params); Ok(Arc::new(Config::new( - orchestrator_config, + orchestrator_params, Arc::new(provider), da_client, prover_client, @@ -172,7 +172,7 @@ impl Config { /// Create a new config #[allow(clippy::too_many_arguments)] pub fn new( - orchestrator_config: OrchestratorConfig, + orchestrator_params: OrchestratorParams, starknet_client: Arc>, da_client: Box, prover_client: Box, @@ -183,7 +183,7 @@ impl Config { alerts: Box, ) -> Self { Self { - orchestrator_config, + orchestrator_params, starknet_client, da_client, prover_client, @@ -197,22 +197,22 @@ impl Config { /// Returns the starknet rpc url pub fn starknet_rpc_url(&self) -> &Url { - &self.orchestrator_config.madara_rpc_url + &self.orchestrator_params.madara_rpc_url } /// Returns the server config pub fn server_config(&self) -> &ServerParams { - &self.orchestrator_config.server_config + &self.orchestrator_params.server_config } /// Returns the snos rpc url pub fn snos_config(&self) -> &SNOSParams { - &self.orchestrator_config.snos_config + &self.orchestrator_params.snos_config } /// Returns the service config pub fn service_config(&self) -> &ServiceParams { - &self.orchestrator_config.service_config + &self.orchestrator_params.service_config } /// Returns the starknet client @@ -270,7 +270,7 @@ pub async fn build_da_client(da_params: &DaParams) -> Box Box { match prover_params { - ProverParams::Sharp(sharp_params) => Box::new(SharpProverService::new_with_settings(sharp_params)), + ProverParams::Sharp(sharp_params) => Box::new(SharpProverService::new_with_params(sharp_params)), } } @@ -282,11 +282,11 @@ pub async fn build_settlement_client( SettlementParams::Ethereum(ethereum_settlement_params) => { #[cfg(not(feature = "testing"))] { - Ok(Box::new(EthereumSettlementClient::new_with_settings(ethereum_settlement_params))) + Ok(Box::new(EthereumSettlementClient::new_with_params(ethereum_settlement_params))) } #[cfg(feature = "testing")] { - Ok(Box::new(EthereumSettlementClient::with_test_settings( + Ok(Box::new(EthereumSettlementClient::with_test_params( RootProvider::new_http(ethereum_settlement_params.ethereum_rpc_url.clone()), Address::from_str(ðereum_settlement_params.l1_core_contract_address)?, ethereum_settlement_params.ethereum_rpc_url.clone(), @@ -295,34 +295,9 @@ pub async fn build_settlement_client( } } SettlementParams::Starknet(starknet_settlement_params) => { - Ok(Box::new(StarknetSettlementClient::new_with_settings(starknet_settlement_params).await)) + Ok(Box::new(StarknetSettlementClient::new_with_params(starknet_settlement_params).await)) } } - - // match settlement_params { - // "ethereum" => { - // #[cfg(not(feature = "testing"))] - // { - // Ok(Box::new(EthereumSettlementClient::new_with_settings(settings_provider))) - // } - // #[cfg(feature = "testing")] - // { - // Ok(Box::new(EthereumSettlementClient::with_test_settings( - // - // RootProvider::new_http(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL" - // ).as_str().parse()?), - // Address::from_str(&get_env_var_or_panic("MADARA_ORCHESTRATOR_L1_CORE_CONTRACT_ADDRESS"))?, - // - // Url::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_ETHEREUM_SETTLEMENT_RPC_URL"). - // as_str())?, - // - // Some(Address::from_str(get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"). - // as_str())?), ))) - // } - // } - // "starknet" => - // Ok(Box::new(StarknetSettlementClient::new_with_settings(settings_provider).await)), _ - // => panic!("Unsupported Settlement layer"), } } pub async fn build_storage_client( @@ -330,7 +305,7 @@ pub async fn build_storage_client( provider_config: Arc, ) -> Box { match data_storage_params { - StorageParams::AWSS3(aws_s3_params) => Box::new(AWSS3::new_with_settings(aws_s3_params, provider_config).await), + StorageParams::AWSS3(aws_s3_params) => Box::new(AWSS3::new_with_params(aws_s3_params, provider_config).await), } } @@ -341,7 +316,7 @@ pub async fn build_alert_client( match alert_params { AlertParams::AWSSNS(aws_sns_params) => { println!("Building alert client {}", aws_sns_params.sns_arn); - Box::new(AWSSNS::new_with_settings(aws_sns_params, provider_config).await) + Box::new(AWSSNS::new_with_params(aws_sns_params, provider_config).await) } } } @@ -354,6 +329,6 @@ pub fn build_queue_client(queue_params: &QueueParams) -> Box Box { match database_params { - DatabaseParams::MongoDB(mongodb_params) => Box::new(MongoDb::new_with_settings(mongodb_params).await), + DatabaseParams::MongoDB(mongodb_params) => Box::new(MongoDb::new_with_params(mongodb_params).await), } } diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index 51489e6d..92dc818a 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -26,7 +26,7 @@ pub struct AWSS3 { /// - initializing a new AWS S3 client impl AWSS3 { /// To init the struct with main settings - pub async fn new_with_settings(s3_config: &AWSS3Params, provider_config: Arc) -> Self { + pub async fn new_with_params(s3_config: &AWSS3Params, provider_config: Arc) -> Self { let aws_config = provider_config.get_aws_client_or_panic(); // Building AWS S3 config let mut s3_config_builder = aws_sdk_s3::config::Builder::from(aws_config); diff --git a/crates/orchestrator/src/database/mongodb/mod.rs b/crates/orchestrator/src/database/mongodb/mod.rs index 0c377b53..a8154f4f 100644 --- a/crates/orchestrator/src/database/mongodb/mod.rs +++ b/crates/orchestrator/src/database/mongodb/mod.rs @@ -27,7 +27,7 @@ pub struct MongoDb { } impl MongoDb { - pub async fn new_with_settings(mongodb_params: &MongoDBParams) -> Self { + pub async fn new_with_params(mongodb_params: &MongoDBParams) -> Self { let mut client_options = ClientOptions::parse(mongodb_params.connection_url.clone()).await.expect("Failed to parse MongoDB Url"); // Set the server_api field of the client_options object to set the version of the Stable API on the diff --git a/crates/orchestrator/src/main.rs b/crates/orchestrator/src/main.rs index 6ff63ff9..2a143f2c 100644 --- a/crates/orchestrator/src/main.rs +++ b/crates/orchestrator/src/main.rs @@ -16,8 +16,6 @@ async fn main() { // TODO: could this be an ARC ? let run_cmd: RunCmd = RunCmd::parse(); - println!("{:?}", run_cmd.aws_sqs_args.queue_base_url); - // Analytics Setup let instrumentation_params = run_cmd.validate_instrumentation_params().expect("Invalid instrumentation params"); let meter_provider = setup_analytics(&instrumentation_params); diff --git a/crates/orchestrator/src/tests/common/mod.rs b/crates/orchestrator/src/tests/common/mod.rs index 8164bead..e7948d50 100644 --- a/crates/orchestrator/src/tests/common/mod.rs +++ b/crates/orchestrator/src/tests/common/mod.rs @@ -65,7 +65,7 @@ pub async fn get_sns_client(aws_config: &SdkConfig) -> aws_sdk_sns::client::Clie pub async fn drop_database(database_params: &DatabaseParams) -> color_eyre::Result<()> { match database_params { DatabaseParams::MongoDB(mongodb_params) => { - let db_client: Client = MongoDb::new_with_settings(mongodb_params).await.client(); + let db_client: Client = MongoDb::new_with_params(mongodb_params).await.client(); // dropping all the collection. // use .collection::("") // if only particular collection is to be dropped @@ -117,5 +117,5 @@ pub async fn get_storage_client( storage_cfg: &AWSS3Params, provider_config: Arc, ) -> Box { - Box::new(AWSS3::new_with_settings(storage_cfg, provider_config).await) + Box::new(AWSS3::new_with_params(storage_cfg, provider_config).await) } diff --git a/crates/orchestrator/src/tests/config.rs b/crates/orchestrator/src/tests/config.rs index 097c89a6..69b58201 100644 --- a/crates/orchestrator/src/tests/config.rs +++ b/crates/orchestrator/src/tests/config.rs @@ -27,7 +27,7 @@ use crate::cli::queue::QueueParams; use crate::cli::settlement::SettlementParams; use crate::cli::snos::SNOSParams; use crate::cli::storage::StorageParams; -use crate::config::{get_aws_config, Config, OrchestratorConfig, ProviderConfig, ServiceParams}; +use crate::config::{get_aws_config, Config, OrchestratorParams, ProviderConfig, ServiceParams}; use crate::data_storage::aws_s3::config::AWSS3Params; use crate::data_storage::{DataStorage, MockDataStorage}; use crate::database::mongodb::config::MongoDBParams; @@ -201,7 +201,7 @@ impl TestConfigBuilder { let params = get_env_params(); - let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(¶ms.aws_config).await))); + let provider_config = Arc::new(ProviderConfig::AWS(Box::new(get_aws_config(¶ms.aws_params).await))); let TestConfigBuilder { starknet_rpc_url_type, @@ -247,7 +247,7 @@ impl TestConfigBuilder { create_sns_arn(provider_config.clone(), ¶ms.alert_params).await.expect("Unable to create the sns arn"); let config = Arc::new(Config::new( - params.orchestrator_config, + params.orchestrator_params, starknet_client, da_client, prover_client, @@ -457,7 +457,7 @@ pub mod implement_client { } struct EnvParams { - aws_config: AWSConfigParams, + aws_params: AWSConfigParams, alert_params: AlertParams, queue_params: QueueParams, storage_params: StorageParams, @@ -465,7 +465,7 @@ struct EnvParams { da_params: DaParams, settlement_params: SettlementParams, prover_params: ProverParams, - orchestrator_config: OrchestratorConfig, + orchestrator_params: OrchestratorParams, #[allow(dead_code)] instrumentation_params: InstrumentationParams, } @@ -486,11 +486,12 @@ fn get_env_params() -> EnvParams { sqs_suffix: get_env_var_or_panic("MADARA_ORCHESTRATOR_SQS_SUFFIX"), }); - let aws_config = AWSConfigParams { + let aws_params = AWSConfigParams { aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), aws_region: get_env_var_or_panic("AWS_REGION"), - aws_endpoint_url: get_env_var_or_panic("AWS_ENDPOINT_URL"), + aws_endpoint_url: Url::parse(&get_env_var_or_panic("AWS_ENDPOINT_URL")) + .expect("Failed to parse AWS_ENDPOINT_URL"), aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), }; @@ -530,7 +531,7 @@ fn get_env_params() -> EnvParams { .expect("Failed to parse MADARA_ORCHESTRATOR_PORT"), }; - let orchestrator_config = OrchestratorConfig { + let orchestrator_params = OrchestratorParams { madara_rpc_url: Url::parse(&get_env_var_or_panic("MADARA_ORCHESTRATOR_MADARA_RPC_URL")) .expect("Failed to parse MADARA_ORCHESTRATOR_MADARA_RPC_URL"), snos_config, @@ -560,7 +561,7 @@ fn get_env_params() -> EnvParams { }); EnvParams { - aws_config, + aws_params, alert_params, queue_params, storage_params, @@ -569,6 +570,6 @@ fn get_env_params() -> EnvParams { settlement_params, prover_params, instrumentation_params, - orchestrator_config, + orchestrator_params, } } diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index 09f38457..ff061862 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -28,7 +28,7 @@ impl SharpClient { /// and then copy it and paste it into .env file : /// /// `cat | base64` - pub fn new_with_settings(url: Url, sharp_params: &SharpParams) -> Self { + pub fn new_with_params(url: Url, sharp_params: &SharpParams) -> Self { // Getting the cert files from the .env and then decoding it from base64 let cert = general_purpose::STANDARD diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index b26a9ecf..51512fcf 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -133,8 +133,8 @@ impl SharpProverService { Self { sharp_client, fact_checker } } - pub fn new_with_settings(sharp_params: &SharpParams) -> Self { - let sharp_client = SharpClient::new_with_settings(sharp_params.sharp_url.clone(), sharp_params); + pub fn new_with_params(sharp_params: &SharpParams) -> Self { + let sharp_client = SharpClient::new_with_params(sharp_params.sharp_url.clone(), sharp_params); let fact_checker = FactChecker::new( sharp_params.sharp_rpc_node_url.clone(), sharp_params.gps_verifier_contract_address.clone(), @@ -142,8 +142,8 @@ impl SharpProverService { Self::new(sharp_client, fact_checker) } - pub fn with_test_settings(port: u16, sharp_params: &SharpParams) -> Self { - let sharp_client = SharpClient::new_with_settings( + pub fn with_test_params(port: u16, sharp_params: &SharpParams) -> Self { + let sharp_client = SharpClient::new_with_params( format!("http://127.0.0.1:{}", port).parse().expect("Failed to create sharp client with the given params"), sharp_params, ); diff --git a/crates/prover-services/sharp-service/tests/lib.rs b/crates/prover-services/sharp-service/tests/lib.rs index e117202b..23633c81 100644 --- a/crates/prover-services/sharp-service/tests/lib.rs +++ b/crates/prover-services/sharp-service/tests/lib.rs @@ -33,7 +33,7 @@ async fn prover_client_submit_task_works() { }; let server = MockServer::start(); - let sharp_service = SharpProverService::with_test_settings(server.port(), &sharp_params); + let sharp_service = SharpProverService::with_test_params(server.port(), &sharp_params); let cairo_pie_path = env!("CARGO_MANIFEST_DIR").to_string() + CAIRO_PIE_PATH; let cairo_pie = CairoPie::read_zip_file(cairo_pie_path.as_ref()).unwrap(); @@ -78,7 +78,7 @@ async fn prover_client_get_task_status_works(#[case] cairo_job_status: CairoJobS }; let server = MockServer::start(); - let sharp_service = SharpProverService::with_test_settings(server.port(), &sharp_params); + let sharp_service = SharpProverService::with_test_params(server.port(), &sharp_params); let customer_id = get_env_var_or_panic("MADARA_ORCHESTRATOR_SHARP_CUSTOMER_ID"); let sharp_add_job_call = server.mock(|when, then| { diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 655dac5a..3c9c5515 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -74,9 +74,7 @@ pub struct EthereumSettlementClient { } impl EthereumSettlementClient { - pub fn new_with_settings(settlement_cfg: &EthereumSettlementParams) -> Self { - // let settlement_cfg = EthereumSettlementConfig::new_with_settings(settings);3 - // TODO: can pass the actual struct here no ned for reference + pub fn new_with_params(settlement_cfg: &EthereumSettlementParams) -> Self { let private_key = settlement_cfg.ethereum_private_key.clone(); let signer: PrivateKeySigner = private_key.parse().expect("Failed to parse private key"); let wallet_address = signer.address(); @@ -105,7 +103,7 @@ impl EthereumSettlementClient { } #[cfg(feature = "testing")] - pub fn with_test_settings( + pub fn with_test_params( provider: RootProvider>, core_contract_address: Address, rpc_url: Url, diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 5fe895f6..430bc291 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -167,7 +167,7 @@ mod settlement_client_tests { // Deploying a dummy contract let contract = DummyCoreContract::deploy(&setup.provider).await.expect("Unable to deploy address"); - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), *contract.address(), ethereum_settlement_params.ethereum_rpc_url, @@ -237,7 +237,7 @@ mod settlement_client_tests { starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), ethereum_settlement_params.ethereum_rpc_url, @@ -303,7 +303,7 @@ mod settlement_client_tests { starknet_operator_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_OPERATOR_ADDRESS"), }; - let ethereum_settlement_client = EthereumSettlementClient::with_test_settings( + let ethereum_settlement_client = EthereumSettlementClient::with_test_params( setup.provider.clone(), Address::from_str(ðereum_settlement_params.l1_core_contract_address).unwrap(), ethereum_settlement_params.ethereum_rpc_url, diff --git a/crates/settlement-clients/starknet/src/lib.rs b/crates/settlement-clients/starknet/src/lib.rs index 4f3d56b9..646bb59e 100644 --- a/crates/settlement-clients/starknet/src/lib.rs +++ b/crates/settlement-clients/starknet/src/lib.rs @@ -44,7 +44,7 @@ const MAX_RETRIES_VERIFY_TX_FINALITY: usize = 10; // https://github.com/keep-starknet-strange/piltover impl StarknetSettlementClient { - pub async fn new_with_settings(settlement_cfg: &StarknetSettlementParams) -> Self { + pub async fn new_with_params(settlement_cfg: &StarknetSettlementParams) -> Self { let provider: Arc> = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_cfg.starknet_rpc_url.clone()))); diff --git a/crates/settlement-clients/starknet/src/tests/test.rs b/crates/settlement-clients/starknet/src/tests/test.rs index 66631f99..6938b52b 100644 --- a/crates/settlement-clients/starknet/src/tests/test.rs +++ b/crates/settlement-clients/starknet/src/tests/test.rs @@ -171,7 +171,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd)) let is_success = wait_for_tx(&account, deploy_tx_hash, Duration::from_secs(2)).await; assert!(is_success, "Deploy trasaction failed"); - let settlement_client = StarknetSettlementClient::new_with_settings(&starknet_settlement_params).await; + let settlement_client = StarknetSettlementClient::new_with_params(&starknet_settlement_params).await; let onchain_data_hash = [1; 32]; let mut program_output = Vec::with_capacity(32); program_output.fill(onchain_data_hash); diff --git a/e2e-tests/src/localstack.rs b/e2e-tests/src/localstack.rs index 3148e256..78d4afdc 100644 --- a/e2e-tests/src/localstack.rs +++ b/e2e-tests/src/localstack.rs @@ -33,7 +33,7 @@ impl LocalStack { Self { sqs_client: aws_sdk_sqs::Client::new(&config), - s3_client: Box::new(AWSS3::new_with_settings(s3_config, provider_config).await), + s3_client: Box::new(AWSS3::new_with_params(s3_config, provider_config).await), event_bridge_client: aws_sdk_eventbridge::Client::new(&config), } } diff --git a/e2e-tests/tests.rs b/e2e-tests/tests.rs index 7ea53872..700623d3 100644 --- a/e2e-tests/tests.rs +++ b/e2e-tests/tests.rs @@ -27,6 +27,7 @@ use rstest::rstest; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::{Felt, MaybePendingStateUpdate}; +use url::Url; use utils::env_utils::get_env_var_or_panic; use uuid::Uuid; @@ -72,7 +73,8 @@ impl Setup { aws_access_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), aws_secret_access_key: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), aws_region: get_env_var_or_panic("AWS_REGION"), - aws_endpoint_url: get_env_var_or_panic("AWS_ENDPOINT_URL"), + aws_endpoint_url: Url::parse(&get_env_var_or_panic("AWS_ENDPOINT_URL")) + .expect("Failed to parse AWS_ENDPOINT_URL"), aws_default_region: get_env_var_or_panic("AWS_DEFAULT_REGION"), };