Skip to content

Commit

Permalink
write job tests, create new fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
AryanGodara authored and Tranduy1dol committed Aug 1, 2024
1 parent 32be758 commit 36266ee
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 32 deletions.
2 changes: 1 addition & 1 deletion crates/orchestrator/src/jobs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn unwrap_external_id_failed(expected: &str, got: &ExternalId) -> color_eyre::ey
eyre!("wrong ExternalId type: expected {}, got {:?}", expected, got)
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum JobType {
/// Submitting DA data to the DA layer
DataSubmission,
Expand Down
26 changes: 25 additions & 1 deletion crates/orchestrator/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ use rstest::*;
use constants::*;
use std::env;

use orchestrator::config::{config, Config};
use std::collections::HashMap;

use orchestrator::{
config::{config, Config},
jobs::types::{
JobItem,
JobType::DataSubmission,
JobStatus::Created,
ExternalId,
},
};

use ::uuid::Uuid;

#[fixture]
pub async fn get_or_init_config(
Expand All @@ -20,3 +32,15 @@ pub async fn get_or_init_config(

config().await
}

#[fixture]
pub fn default_job_item() -> JobItem {
JobItem {
id: Uuid::new_v4(),
internal_id: String::from("0"),
job_type: DataSubmission,status: Created,
external_id: ExternalId::Number(0),
metadata: HashMap::new(),
version: 0,
}
}
24 changes: 8 additions & 16 deletions crates/orchestrator/tests/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use crate::common::default_job_item;

use super::common::{
get_or_init_config,
Expand All @@ -7,18 +7,16 @@ use super::common::{
}
};

use orchestrator::config::Config;
use orchestrator::jobs::types::{
JobItem,
JobType::DataSubmission,
JobStatus::Created,
ExternalId,
use orchestrator::{
config::Config,
jobs::types::JobItem,
};

use rstest::*;
use starknet::providers::Provider;

use starknet::core::types::FieldElement;
use ::uuid::Uuid;


#[fixture]
fn vec_of_field_elements() -> Vec<FieldElement> {
Expand Down Expand Up @@ -96,16 +94,10 @@ async fn test_config_da_client(
#[tokio::test]
async fn test_config_database(
#[future] get_or_init_config: &Config,
default_job_item: JobItem,
) {
let config = get_or_init_config.await;
let job = JobItem {
id: Uuid::new_v4(),
internal_id: String::from("0"),
job_type: DataSubmission,status: Created,
external_id: ExternalId::Number(0),
metadata: HashMap::new(),
version: 0,
};
let job = default_job_item;
let result = config.database().create_job(job).await;
assert!(result.is_err());
}
43 changes: 43 additions & 0 deletions crates/orchestrator/tests/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use rstest::*;

use crate::common::{
get_or_init_config,
default_job_item,
};

use orchestrator::{
config::Config,
jobs::{
da_job::DaJob,
types::{JobItem, JobType},
Job
},
};

#[rstest]
#[tokio::test]
async fn test_create_job(
#[future] get_or_init_config: &Config
) {
let config = get_or_init_config.await;
let job = DaJob.create_job(&config, String::from("0")).await;
assert!(job.is_ok());

let job = job.unwrap();

let job_type = job.job_type;
assert_eq!(job_type, JobType::DataSubmission);
assert_eq!(job.metadata.values().len(), 0, "metadata should be empty");
assert_eq!(job.external_id.unwrap_string().unwrap(), String::new(), "external_id should be empty string");
}

#[rstest]
// #[should_panic]
#[tokio::test]
async fn test_verify_job(
#[future] #[from(get_or_init_config)] config: &Config,
default_job_item: JobItem,
) {
let config = config.await;
assert!(DaJob.verify_job(config, &default_job_item).await.is_err());
}
16 changes: 2 additions & 14 deletions crates/orchestrator/tests/jobs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
use super::common::get_or_init_config;
use orchestrator::config::Config;
use rstest::*;

#[rstest]
#[tokio::test]
async fn test_abc(
#[future]
#[with( String::from("http://localhost:9944") )]
get_or_init_config: &Config
) {
get_or_init_config.await;
todo!("setting up the structure before writing the tests");
}
#[cfg(test)]
pub mod da_job;

0 comments on commit 36266ee

Please sign in to comment.