Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : job handler tests #67

Merged
merged 52 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
726f1ed
feat : added tests for increasing coverage
ocdbytes Jul 23, 2024
b3a80b0
feat : added mongo db tests and fixtures and updated the ci for tests
ocdbytes Jul 24, 2024
5826d44
update : removed unwanted fixtures
ocdbytes Jul 24, 2024
0e70fff
update : removed unwanted fixtures
ocdbytes Jul 24, 2024
97f1f21
update : added mongo db runner in ci
ocdbytes Jul 24, 2024
a64613c
update : added mongo db runner in ci
ocdbytes Jul 24, 2024
db472d5
update : added mongo db runner in ci
ocdbytes Jul 24, 2024
15541ef
update : updated with new changes and ci
ocdbytes Jul 25, 2024
fc7d493
update : updated test cases for s3 client
ocdbytes Jul 26, 2024
9a101ba
update : added .env.test file in the commit
ocdbytes Jul 26, 2024
906a1eb
feat : added database necessary tests
ocdbytes Jul 26, 2024
65d66e6
feat : added database necessary tests
ocdbytes Jul 26, 2024
20d82c3
Revert "feat : added database necessary tests"
ocdbytes Jul 26, 2024
63bc846
Revert "feat : added database necessary tests"
ocdbytes Jul 26, 2024
f36b483
update: Replaced Build_Config Fixture with TestConfigBuilder
heemankv Jul 26, 2024
8b7e68f
update : config update
ocdbytes Jul 26, 2024
74fea52
update : test_put_and_get_data_s3 test
ocdbytes Jul 26, 2024
385974d
update: moved testconfigbuilder to tests/config.rs & added docs , dro…
heemankv Jul 29, 2024
eb43d49
feat : create job test case error returning
ocdbytes Jul 30, 2024
a79b633
mock job handler
apoorvsadana Jul 30, 2024
2209405
merge main
ocdbytes Jul 30, 2024
c01c990
Merge branch 'main' into feat/increasing-test-coverage
heemankv Jul 31, 2024
e026d8d
feat : added jobs test and modified worker tests
ocdbytes Jul 31, 2024
661adaf
feat : added queue checks to tests and revamped some tests
ocdbytes Aug 1, 2024
dc05623
Merge branch 'feat/increasing-test-coverage' into feat/job_tests_global
ocdbytes Aug 1, 2024
6ecef60
feat : updated tests and resolved comments
ocdbytes Aug 2, 2024
b31212c
feat : updated test config and added config type to aws s3 config
ocdbytes Aug 2, 2024
ad585f1
feat : updated tests and test names
ocdbytes Aug 2, 2024
57b21af
Merge branch 'feat/increasing-test-coverage' into feat/job_tests_global
ocdbytes Aug 2, 2024
b3de1a2
feat : lint fixes
ocdbytes Aug 3, 2024
cd5e9e8
Merge branch 'main' into feat/job_tests_global
ocdbytes Aug 3, 2024
763379e
feat : lint fixes
ocdbytes Aug 3, 2024
ec61d72
feat : lint fixes
ocdbytes Aug 3, 2024
ae2d4d9
chore: resolved pr comments
ocdbytes Aug 3, 2024
67141ba
Update crates/orchestrator/src/tests/database/mod.rs
ocdbytes Aug 3, 2024
6c9b68e
Merge branch 'main' into feat/increasing-test-coverage
ocdbytes Aug 3, 2024
26df776
chore : lint fixes
ocdbytes Aug 3, 2024
20a480e
feat : lint fix
ocdbytes Aug 3, 2024
7f01895
fix : coverage tests fix
ocdbytes Aug 5, 2024
44aecd7
fix : test fix
ocdbytes Aug 5, 2024
2de874d
fix : updated region in localstack .env.test
ocdbytes Aug 5, 2024
ea867ae
feat : updated region
ocdbytes Aug 5, 2024
0887de5
debug : added debug log to github ci
ocdbytes Aug 5, 2024
d6e31cb
feat : updated queue code for test fixes
ocdbytes Aug 5, 2024
a6d9255
fix : sqs region fix
ocdbytes Aug 5, 2024
fa91ccb
debug : added debug logs for ci debugging
ocdbytes Aug 5, 2024
2f6283e
feat : added override endpoint to queue url in producer and consumer
ocdbytes Aug 5, 2024
b1b9c9f
feat : added override endpoint to queue url in producer and consumer
ocdbytes Aug 5, 2024
4ab388f
fix : removed logs and refactored the code
ocdbytes Aug 5, 2024
c4aef5d
chore : refactor code
ocdbytes Aug 6, 2024
e27de07
Merge branch 'feat/increasing-test-coverage' into feat/job_tests_global
ocdbytes Aug 6, 2024
53e9213
Merge branch 'main' into feat/job_tests_global
ocdbytes Aug 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
##### AWS config #####

AWS_ACCESS_KEY_ID="AWS_ACCESS_KEY_ID"
AWS_SECRET_ACCESS_KEY="AWS_SECRET_ACCESS_KEY"
AWS_S3_BUCKET_NAME="madara-orchestrator-test-bucket"
AWS_S3_BUCKET_REGION="us-east-1"
AWS_ENDPOINT_URL="http://localhost.localstack.cloud:4566"

##### On chain config #####

MADARA_RPC_URL="http://localhost:3000"
ETHEREUM_RPC_URL="http://localhost:3001"
MEMORY_PAGES_CONTRACT_ADDRESS="0x000000000000000000000000000000000001dead"
PRIVATE_KEY="0xdead"
ETHEREUM_PRIVATE_KEY="0x000000000000000000000000000000000000000000000000000000000000beef"
STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS="0x000000000000000000000000000000000002dead"

##### Config URLs #####

DA_LAYER="ethereum"
PROVER_SERVICE="sharp"
SETTLEMENT_LAYER="ethereum"
DATA_STORAGE="s3"
MONGODB_CONNECTION_STRING="mongodb://localhost:27017"
15 changes: 15 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ jobs:
# sadly, for now we have to "rebuild" for the coverage
runs-on: ubuntu-latest

services:
localstack:
image: localstack/localstack
env:
SERVICES: s3, sqs
DEFAULT_REGION: us-east-1
AWS_ACCESS_KEY_ID: "AWS_ACCESS_KEY_ID"
AWS_SECRET_ACCESS_KEY: "AWS_SECRET_ACCESS_KEY"
ports:
- 4566:4566
mongodb:
image: mongo:latest
ports:
- 27017:27017

steps:
- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Function to calculate the kzg proof of x_0.
- Tests for updating the state.
- Function to update the state and publish blob on ethereum in state update job.
- Added basic rust-toolchain support.
- Tests for job handlers in orchestrator/src/jobs/mod.rs.

## Changed

Expand Down
55 changes: 47 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ utils = { path = "crates/utils" }
prover-client-interface = { path = "crates/prover-services/prover-client-interface" }
gps-fact-checker = { path = "crates/prover-services/gps-fact-checker" }
sharp-service = { path = "crates/prover-services/sharp-service" }
orchestrator = { path = "crates/orchestrator" }
orchestrator = { path = "crates/orchestrator" }
4 changes: 3 additions & 1 deletion crates/da-clients/ethereum/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::str::FromStr;

use alloy::{network::Ethereum, providers::ProviderBuilder, rpc::client::RpcClient};
use alloy::network::Ethereum;
use alloy::providers::ProviderBuilder;
use alloy::rpc::client::RpcClient;
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved
use async_trait::async_trait;
use da_client_interface::DaConfig;
use url::Url;
Expand Down
4 changes: 2 additions & 2 deletions crates/da-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct EthereumDaClient {
#[async_trait]
impl DaClient for EthereumDaClient {
async fn publish_state_diff(&self, _state_diff: Vec<Vec<u8>>, _to: &[u8; 32]) -> Result<String> {
// Here in case of ethereum we are not publishing the state diff because we are doing it all together in update_state job.
// So we don't need to send the blob here.
// Here in case of ethereum we are not publishing the state diff because we are doing it all
// together in update_state job. So we don't need to send the blob here.
Ok("NA".to_string())
}

Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ lazy_static = { workspace = true }
log = "0.4.21"
majin-blob-core = { git = "https://github.com/AbdelStark/majin-blob", branch = "main" }
majin-blob-types = { git = "https://github.com/AbdelStark/majin-blob", branch = "main" }
mockall = "0.12.1"
mockall = { version = "0.13.0", features = ["nightly"] }
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved
mockall_double = "0.3.1"
mongodb = { workspace = true, features = ["bson-uuid-1"], optional = true }
num = { workspace = true }
num-bigint = { workspace = true }
Expand Down
16 changes: 9 additions & 7 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::sync::Arc;

use crate::data_storage::aws_s3::config::AWSS3Config;
use crate::data_storage::aws_s3::AWSS3;
use crate::data_storage::{DataStorage, DataStorageConfig};
use arc_swap::{ArcSwap, Guard};
use da_client_interface::{DaClient, DaConfig};
use dotenvy::dotenv;
Expand All @@ -19,6 +16,9 @@ use utils::env_utils::get_env_var_or_panic;
use utils::settings::default::DefaultSettingsProvider;
use utils::settings::SettingsProvider;

use crate::data_storage::aws_s3::config::AWSS3Config;
use crate::data_storage::aws_s3::AWSS3;
use crate::data_storage::{DataStorage, DataStorageConfig};
use crate::database::mongodb::config::MongoDbConfig;
use crate::database::mongodb::MongoDb;
use crate::database::{Database, DatabaseConfig};
Expand Down Expand Up @@ -148,7 +148,7 @@ pub async fn config_force_init(config: Config) {
}

/// Builds the DA client based on the environment variable DA_LAYER
async fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
pub async fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
match get_env_var_or_panic("DA_LAYER").as_str() {
"ethereum" => {
let config = EthereumDaConfig::new_from_env();
Expand All @@ -159,23 +159,25 @@ async fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
}

/// Builds the prover service based on the environment variable PROVER_SERVICE
fn build_prover_service(settings_provider: &impl SettingsProvider) -> Box<dyn ProverClient> {
pub fn build_prover_service(settings_provider: &impl SettingsProvider) -> Box<dyn ProverClient> {
match get_env_var_or_panic("PROVER_SERVICE").as_str() {
"sharp" => Box::new(SharpProverService::with_settings(settings_provider)),
_ => panic!("Unsupported prover service"),
}
}

/// Builds the settlement client depending on the env variable SETTLEMENT_LAYER
async fn build_settlement_client(settings_provider: &impl SettingsProvider) -> Box<dyn SettlementClient + Send + Sync> {
pub async fn build_settlement_client(
settings_provider: &impl SettingsProvider,
) -> Box<dyn SettlementClient + Send + Sync> {
match get_env_var_or_panic("SETTLEMENT_LAYER").as_str() {
"ethereum" => Box::new(EthereumSettlementClient::with_settings(settings_provider)),
"starknet" => Box::new(StarknetSettlementClient::with_settings(settings_provider).await),
_ => panic!("Unsupported Settlement layer"),
}
}

async fn build_storage_client() -> Box<dyn DataStorage + Send + Sync> {
pub async fn build_storage_client() -> Box<dyn DataStorage + Send + Sync> {
match get_env_var_or_panic("DATA_STORAGE").as_str() {
"s3" => Box::new(AWSS3::new(AWSS3Config::new_from_env()).await),
_ => panic!("Unsupported Storage Client"),
Expand Down
24 changes: 0 additions & 24 deletions crates/orchestrator/src/controllers/jobs_controller.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/orchestrator/src/controllers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
/// Errors
mod errors;

/// Job controllers
pub mod jobs_controller;
5 changes: 5 additions & 0 deletions crates/orchestrator/src/data_storage/aws_s3/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub struct AWSS3Config {
pub s3_bucket_name: String,
/// S3 Bucket region
pub s3_bucket_region: String,
/// Endpoint url
#[cfg(test)]
pub endpoint_url: String,
}

/// Implementation of `DataStorageConfig` for `AWSS3Config`
Expand All @@ -23,6 +26,8 @@ impl DataStorageConfig for AWSS3Config {
s3_key_secret: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"),
s3_bucket_name: get_env_var_or_panic("AWS_S3_BUCKET_NAME"),
s3_bucket_region: get_env_var_or_panic("AWS_S3_BUCKET_REGION"),
#[cfg(test)]
endpoint_url: get_env_var_or_panic("AWS_ENDPOINT_URL"),
}
}
}
22 changes: 18 additions & 4 deletions crates/orchestrator/src/data_storage/aws_s3/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::data_storage::aws_s3::config::AWSS3Config;
use crate::data_storage::DataStorage;
use async_trait::async_trait;
use aws_sdk_s3::config::{Builder, Credentials, Region};
use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_s3::Client;
use bytes::Bytes;
use color_eyre::Result;

use crate::data_storage::aws_s3::config::AWSS3Config;
use crate::data_storage::DataStorage;

/// Module for AWS S3 config structs and implementations
pub mod config;

Expand All @@ -22,7 +23,6 @@ pub struct AWSS3 {
impl AWSS3 {
/// Initializes a new AWS S3 client by passing the config
/// and returning it.
#[allow(dead_code)]
pub async fn new(config: AWSS3Config) -> Self {
// AWS cred building
let credentials = Credentials::new(
Expand All @@ -33,7 +33,15 @@ impl AWSS3 {
"loaded_from_custom_env",
);
let region = Region::new(config.s3_bucket_region.clone().to_string());
let conf_builder = Builder::new().region(region).credentials_provider(credentials);

#[allow(unused_mut)]
let mut conf_builder = Builder::new().region(region).credentials_provider(credentials).force_path_style(true);

#[cfg(test)]
{
conf_builder = conf_builder.endpoint_url(config.endpoint_url.clone().to_string());
}

let conf = conf_builder.build();

// Building AWS S3 config
Expand Down Expand Up @@ -69,4 +77,10 @@ impl DataStorage for AWSS3 {

Ok(())
}

#[cfg(test)]
async fn build_test_bucket(&self, bucket_name: &str) -> Result<()> {
self.client.create_bucket().bucket(bucket_name).send().await?;
Ok(())
}
}
2 changes: 2 additions & 0 deletions crates/orchestrator/src/data_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use mockall::automock;
pub trait DataStorage: Send + Sync {
async fn get_data(&self, key: &str) -> Result<Bytes>;
async fn put_data(&self, data: Bytes, key: &str) -> Result<()>;
#[cfg(test)]
async fn build_test_bucket(&self, bucket_name: &str) -> Result<()>;
}

/// **DataStorageConfig** : Trait method to represent the config struct needed for
Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/data_storage/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use cairo_vm::Felt252;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// This struct represents the contract changes that will be in `StarknetOsOutput`
/// as a vector.
Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ::mongodb::bson::doc;
use std::collections::HashMap;

use ::mongodb::bson::doc;
use async_trait::async_trait;
use color_eyre::Result;
use mockall::automock;
Expand Down
Loading
Loading