Skip to content

Commit

Permalink
update: fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Nov 14, 2024
1 parent ac31c68 commit f24de0b
Showing 1 changed file with 104 additions and 38 deletions.
142 changes: 104 additions & 38 deletions crates/orchestrator/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ pub mod validate_params {
starknet_args: &StarknetSettlementCliArgs,
) -> Result<SettlementValidatedArgs, String> {
if ethereum_args.settle_on_ethereum {
if starknet_args.settle_on_starknet {
return Err("Cannot settle on both Ethereum and Starknet".to_string());
}
let l1_core_contract_address = Address::from_str(
&ethereum_args.l1_core_contract_address.clone().expect("L1 core contract address is required"),
)
Expand All @@ -464,6 +467,9 @@ pub mod validate_params {
};
Ok(SettlementValidatedArgs::Ethereum(ethereum_params))
} else if starknet_args.settle_on_starknet {
if ethereum_args.settle_on_ethereum {
return Err("Cannot settle on both Starknet and Ethereum".to_string());
}
let starknet_params = StarknetSettlementValidatedArgs {
starknet_rpc_url: starknet_args.starknet_rpc_url.clone().expect("Starknet RPC URL is required"),
starknet_private_key: starknet_args
Expand Down Expand Up @@ -567,88 +573,132 @@ pub mod validate_params {
};

#[rstest]
fn test_validate_provider_params() {
#[case(true)]
#[case(false)]
fn test_validate_provider_params(#[case] is_aws: bool) {
let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs {
aws: true,
aws: is_aws,
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_region: "".to_string(),
};

let provider_params = validate_provider_params(&aws_config_args);
assert!(provider_params.is_ok());
if is_aws {
assert!(provider_params.is_ok());
} else {
assert!(provider_params.is_err());
}
}

#[rstest]
fn test_validate_alert_params() {
#[case(true, true)]
#[case(true, false)]
#[case(false, true)]
#[case(false, false)]
fn test_validate_alert_params(#[case] is_aws: bool, #[case] is_sns: bool) {
let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs {
aws: true,
aws: is_aws,
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_region: "".to_string(),
};
let aws_sns_args: AWSSNSCliArgs = AWSSNSCliArgs { aws_sns: true, sns_arn: Some("".to_string()) };
let aws_sns_args: AWSSNSCliArgs = AWSSNSCliArgs { aws_sns: is_sns, sns_arn: Some("".to_string()) };

let alert_params = validate_alert_params(&aws_sns_args, &aws_config_args);
assert!(alert_params.is_ok());
if is_aws && is_sns {
assert!(alert_params.is_ok());
} else {
assert!(alert_params.is_err());
}
}

#[rstest]
fn test_validate_queue_params() {
let aws_sqs_args: AWSSQSCliArgs = AWSSQSCliArgs {
aws_sqs: true,
queue_base_url: Some("http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000".to_string()),
sqs_prefix: Some("".to_string()),
sqs_suffix: Some("".to_string()),
};
#[case(true, true)]
#[case(true, false)]
#[case(false, true)]
#[case(false, false)]
fn test_validate_queue_params(#[case] is_aws: bool, #[case] is_sqs: bool) {
let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs {
aws: true,
aws: is_aws,
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_region: "".to_string(),
};
let aws_sqs_args: AWSSQSCliArgs = AWSSQSCliArgs {
aws_sqs: is_sqs,
queue_base_url: Some("http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000".to_string()),
sqs_prefix: Some("".to_string()),
sqs_suffix: Some("".to_string()),
};
let queue_params = validate_queue_params(&aws_sqs_args, &aws_config_args);
assert!(queue_params.is_ok());
if is_aws && is_sqs {
assert!(queue_params.is_ok());
} else {
assert!(queue_params.is_err());
}
}

#[rstest]
fn test_validate_storage_params() {
let aws_s3_args: AWSS3CliArgs = AWSS3CliArgs { aws_s3: true, bucket_name: Some("".to_string()) };
#[case(true, true)]
#[case(true, false)]
#[case(false, true)]
#[case(false, false)]
fn test_validate_storage_params(#[case] is_aws: bool, #[case] is_s3: bool) {
let aws_s3_args: AWSS3CliArgs = AWSS3CliArgs { aws_s3: is_s3, bucket_name: Some("".to_string()) };
let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs {
aws: true,
aws: is_aws,
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_region: "".to_string(),
};
let storage_params = validate_storage_params(&aws_s3_args, &aws_config_args);
assert!(storage_params.is_ok());
if is_aws && is_s3 {
assert!(storage_params.is_ok());
} else {
assert!(storage_params.is_err());
}
}

#[rstest]
fn test_validate_database_params() {
#[case(true)]
#[case(false)]
fn test_validate_database_params(#[case] is_mongodb: bool) {
let mongodb_args: MongoDBCliArgs = MongoDBCliArgs {
mongodb: true,
mongodb: is_mongodb,
mongodb_connection_url: Some("mongodb://localhost:27017".to_string()),
mongodb_database_name: Some("orchestrator".to_string()),
};
let database_params = validate_database_params(&mongodb_args);
assert!(database_params.is_ok());
if is_mongodb {
assert!(database_params.is_ok());
} else {
assert!(database_params.is_err());
}
}

#[rstest]
fn test_validate_da_params() {
#[case(true)]
#[case(false)]
fn test_validate_da_params(#[case] is_ethereum: bool) {
let ethereum_da_args: EthereumDaCliArgs = EthereumDaCliArgs {
da_on_ethereum: true,
da_on_ethereum: is_ethereum,
ethereum_da_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()),
};
let da_params = validate_da_params(&ethereum_da_args);
assert!(da_params.is_ok());
if is_ethereum {
assert!(da_params.is_ok());
} else {
assert!(da_params.is_err());
}
}

#[rstest]
#[case(true)]
#[case(false)]
fn test_validate_settlement_params(#[case] is_ethereum: bool) {
#[case(true, false)]
#[case(false, true)]
#[case(false, false)]
#[case(true, true)]
fn test_validate_settlement_params(#[case] is_ethereum: bool, #[case] is_starknet: bool) {
let ethereum_args: EthereumSettlementCliArgs = EthereumSettlementCliArgs {
ethereum_rpc_url: Some(Url::parse("http://localhost:8545").unwrap()),
ethereum_private_key: Some("".to_string()),
Expand All @@ -662,16 +712,22 @@ pub mod validate_params {
starknet_account_address: Some("".to_string()),
starknet_cairo_core_contract_address: Some("".to_string()),
starknet_finality_retry_wait_in_secs: Some(0),
settle_on_starknet: !is_ethereum,
settle_on_starknet: is_starknet,
};
let settlement_params = validate_settlement_params(&ethereum_args, &starknet_args);
assert!(settlement_params.is_ok());
if is_ethereum ^ is_starknet {
assert!(settlement_params.is_ok());
} else {
assert!(settlement_params.is_err());
}
}

#[rstest]
fn test_validate_prover_params() {
#[case(true)]
#[case(false)]
fn test_validate_prover_params(#[case] is_sharp: bool) {
let sharp_args: SharpCliArgs = SharpCliArgs {
sharp: true,
sharp: is_sharp,
sharp_customer_id: Some("".to_string()),
sharp_url: Some(Url::parse("http://localhost:8545").unwrap()),
sharp_user_crt: Some("".to_string()),
Expand All @@ -682,25 +738,35 @@ pub mod validate_params {
sharp_server_crt: Some("".to_string()),
};
let prover_params = validate_prover_params(&sharp_args);
assert!(prover_params.is_ok());
if is_sharp {
assert!(prover_params.is_ok());
} else {
assert!(prover_params.is_err());
}
}

#[rstest]
fn test_validate_cron_params() {
#[case(true)]
#[case(false)]
fn test_validate_cron_params(#[case] is_aws: bool) {
let aws_event_bridge_args: AWSEventBridgeCliArgs = AWSEventBridgeCliArgs {
aws_event_bridge: true,
aws_event_bridge: is_aws,
target_queue_name: Some(String::from("test")),
cron_time: Some(String::from("12")),
trigger_rule_name: Some(String::from("test")),
};
let aws_config_args: AWSConfigCliArgs = AWSConfigCliArgs {
aws: true,
aws: is_aws,
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_region: "".to_string(),
};
let cron_params = validate_cron_params(&aws_event_bridge_args, &aws_config_args);
assert!(cron_params.is_ok());
if is_aws {
assert!(cron_params.is_ok());
} else {
assert!(cron_params.is_err());
}
}

#[rstest]
Expand Down

0 comments on commit f24de0b

Please sign in to comment.