Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvsadana committed May 24, 2024
1 parent 267fff6 commit 602eb9a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 44 deletions.
29 changes: 3 additions & 26 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::database::mongodb::config::MongoDbConfig;
use crate::database::mongodb::MongoDb;
use crate::database::{Database, DatabaseConfig, MockDatabase};
use crate::database::{Database, DatabaseConfig};
use crate::queue::sqs::SqsQueue;
use crate::queue::{MockQueueProvider, QueueProvider};
use crate::queue::{QueueProvider};
use crate::utils::env_utils::get_env_var_or_panic;
use color_eyre::Result;
use da_client_interface::{DaClient};
use da_client_interface::DaConfig;
use da_client_interface::{DaClient, MockDaClient};
use dotenvy::dotenv;
use ethereum_da_client::config::EthereumDaConfig;
use ethereum_da_client::EthereumDaClient;
Expand Down Expand Up @@ -46,28 +45,6 @@ pub async fn init_config() -> Config {
Config { starknet_client: Arc::new(provider), da_client: build_da_client(), database, queue }
}

/// Initializes mock app config
#[cfg(test)]
pub async fn init_config_with_mocks(
mock_database: MockDatabase,
mock_queue_provider: MockQueueProvider,
mock_da_client: MockDaClient,
starknet_rpc_url: String,
) {
dotenv().ok();

// init starknet client
let provider =
JsonRpcClient::new(HttpTransport::new(Url::parse(starknet_rpc_url.as_str()).expect("Failed to parse URL")));

let database = Box::new(mock_database);
let queue = Box::new(mock_queue_provider);
let da_client = Box::new(mock_da_client);

let config = Config { starknet_client: Arc::new(provider), da_client, database, queue };
assert!(CONFIG.set(config).is_ok());
}

impl Config {
/// Returns the starknet client
pub fn starknet_client(&self) -> &Arc<JsonRpcClient<HttpTransport>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mod tests {
let state_update_path = "test-utils/stateUpdate.json".to_owned();
let contents = read_to_string(state_update_path).expect("Couldn't find or load that file.");

let v: Result<StateUpdate, Error> = serde_json::from_str(&contents.as_str());
let v: Result<StateUpdate, Error> = serde_json::from_str(contents.as_str());

let state_update: StateUpdate = match v {
Ok(state_update) => state_update,
Expand Down
4 changes: 1 addition & 3 deletions crates/orchestrator/src/tests/common/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
pub const MADARA_RPC_URL: &str = "http://localhost:9944";
pub const MONGODB_CONNECTION_STRING: &str = "mongodb+srv://admin:[email protected]/";
pub const DA_LAYER: &str = "ethereum";
pub const MADARA_RPC_URL: &str = "http://localhost:9944";
12 changes: 6 additions & 6 deletions crates/orchestrator/src/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod constants;

use constants::*;
use rstest::*;
use std::env;


use std::collections::HashMap;
use std::sync::Arc;
Expand All @@ -12,14 +12,14 @@ use crate::{
jobs::types::{ExternalId, JobItem, JobStatus::Created, JobType::DataSubmission},
};

use crate::config::config;

use crate::database::MockDatabase;
use crate::queue::MockQueueProvider;
use ::uuid::Uuid;
use da_client_interface::MockDaClient;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
use tracing_subscriber::fmt::writer::EitherWriter::B;

use url::Url;

pub async fn init_config(
Expand All @@ -31,9 +31,9 @@ pub async fn init_config(
let _ = tracing_subscriber::fmt().with_max_level(tracing::Level::INFO).with_target(false).try_init();

let rpc_url = rpc_url.unwrap_or(MADARA_RPC_URL.to_string());
let database = database.unwrap_or(MockDatabase::new());
let queue = queue.unwrap_or(MockQueueProvider::new());
let da_client = da_client.unwrap_or(MockDaClient::new());
let database = database.unwrap_or_default();
let queue = queue.unwrap_or_default();
let da_client = da_client.unwrap_or_default();

// init starknet client
let provider = JsonRpcClient::new(HttpTransport::new(Url::parse(rpc_url.as_str()).expect("Failed to parse URL")));
Expand Down
4 changes: 2 additions & 2 deletions crates/orchestrator/src/tests/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::common::init_config;
use crate::config::Config;


use rstest::*;

#[rstest]
Expand Down
9 changes: 4 additions & 5 deletions crates/orchestrator/src/tests/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use rstest::*;
use starknet::core::types::StateUpdate;
use std::any::Any;

use std::collections::HashMap;
use std::env;


use httpmock::prelude::*;
use serde_json::{json, Error};
use serde_json::{json};

use super::super::common::{default_job_item, init_config};
use starknet_core::types::{FieldElement, MaybePendingStateUpdate, StateDiff};
use uuid::Uuid;

use crate::config::config;

use crate::jobs::types::ExternalId;
use crate::{
config::Config,
jobs::{
da_job::DaJob,
types::{JobItem, JobStatus, JobType},
Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/tests/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hyper::{body::Buf, Body, Request};

use rstest::*;

use crate::{config::Config, queue::init_consumers, routes::app_router, utils::env_utils::get_env_var_or_default};
use crate::{queue::init_consumers, routes::app_router, utils::env_utils::get_env_var_or_default};

use super::common::init_config;

Expand Down

0 comments on commit 602eb9a

Please sign in to comment.