Skip to content

Commit

Permalink
update: testcase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Nov 14, 2024
1 parent ec4ad85 commit 982aed9
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 561 deletions.
1 change: 0 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ AWS_DEFAULT_REGION=localhost

#### ALERTS ####

MADARA_ORCHESTRATOR_AWS_SNS_ARN_NAME=madara-orchestrator-arn
MADARA_ORCHESTRATOR_AWS_SNS_ARN=arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn


Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/cli/alert/aws_sns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pub struct AWSSNSCliArgs {
pub aws_sns: bool,

/// The name of the S3 bucket.
#[arg(env = "MADARA_ORCHESTRATOR_AWS_SNS_ARN", long, default_value = Some("madara-orchestrator-arn"))]
#[arg(env = "MADARA_ORCHESTRATOR_AWS_SNS_ARN", long, default_value = Some("arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn"))]
pub sns_arn: Option<String>,
}
888 changes: 508 additions & 380 deletions crates/orchestrator/src/cli/mod.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions crates/orchestrator/src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ pub enum SetupConfig {
}

// TODO : move this to main.rs after moving to clap.
pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> {
pub async fn setup_cloud(setup_cmd: &SetupCmd) -> color_eyre::Result<()> {
println!("Setting up cloud. ⏳");
// AWS
let provider_params = run_cmd.validate_provider_params().expect("Failed to validate provider params");
let provider_params = setup_cmd.validate_provider_params().expect("Failed to validate provider params");
let provider_config = build_provider_config(&provider_params).await;

// Data Storage
println!("Setting up data storage. ⏳");
let data_storage_params = run_cmd.validate_storage_params().expect("Failed to validate storage params");
let data_storage_params = setup_cmd.validate_storage_params().expect("Failed to validate storage params");
let aws_config = provider_config.get_aws_client_or_panic();

match data_storage_params {
Expand All @@ -44,7 +44,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> {

// Queues
println!("Setting up queues. ⏳");
let queue_params = run_cmd.validate_queue_params().expect("Failed to validate queue params");
let queue_params = setup_cmd.validate_queue_params().expect("Failed to validate queue params");
match queue_params {
QueueValidatedArgs::AWSSQS(aws_sqs_params) => {
let sqs = Box::new(SqsQueue::new_with_args(aws_sqs_params, aws_config));
Expand All @@ -55,7 +55,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> {

// Cron
println!("Setting up cron. ⏳");
let cron_params = run_cmd.validate_cron_params().expect("Failed to validate cron params");
let cron_params = setup_cmd.validate_cron_params().expect("Failed to validate cron params");
match cron_params {
CronValidatedArgs::AWSEventBridge(aws_event_bridge_params) => {
let aws_config = provider_config.get_aws_client_or_panic();
Expand All @@ -67,7 +67,7 @@ pub async fn setup_cloud(run_cmd: &SetupCmd) -> color_eyre::Result<()> {

// Alerts
println!("Setting up alerts. ⏳");
let alert_params = run_cmd.validate_alert_params().expect("Failed to validate alert params");
let alert_params = setup_cmd.validate_alert_params().expect("Failed to validate alert params");
match alert_params {
AlertValidatedArgs::AWSSNS(aws_sns_params) => {
let aws_config = provider_config.get_aws_client_or_panic();
Expand Down
3 changes: 2 additions & 1 deletion crates/orchestrator/src/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ pub async fn create_sns_arn(
alert_params: &AlertValidatedArgs,
) -> Result<(), SdkError<CreateTopicError>> {
let AlertValidatedArgs::AWSSNS(aws_sns_params) = alert_params;
let topic_name = aws_sns_params.topic_arn.split(":").last().unwrap();
let sns_client = get_sns_client(provider_config.get_aws_client_or_panic()).await;
sns_client.create_topic().name(aws_sns_params.topic_arn.clone()).send().await?;
sns_client.create_topic().name(topic_name).send().await?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ fn get_env_params() -> EnvParams {
});

let alert_params = AlertValidatedArgs::AWSSNS(AWSSNSValidatedArgs {
topic_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN_NAME"),
topic_arn: get_env_var_or_panic("MADARA_ORCHESTRATOR_AWS_SNS_ARN"),
});

let settlement_params = SettlementValidatedArgs::Ethereum(EthereumSettlementValidatedArgs {
Expand Down
2 changes: 1 addition & 1 deletion crates/settlement-clients/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version.workspace = true
edition.workspace = true

[dependencies]
alloy-primitives = { version = "0.7.7", default-features = false }
alloy = { workspace = true, features = ["full", "node-bindings"] }
alloy-primitives = { version = "0.7.7", default-features = false }
async-trait = { workspace = true }
bytes = "1.7.2"
c-kzg = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/settlement-clients/starknet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version.workspace = true
edition.workspace = true

[dependencies]
alloy-primitives = { version = "0.7.7", default-features = false }
alloy = { workspace = true, features = ["full", "node-bindings"] }
alloy-primitives = { version = "0.7.7", default-features = false }
appchain-core-contract-client = { workspace = true }
async-trait = { workspace = true }
c-kzg = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions crates/settlement-clients/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub mod tests;

use std::sync::Arc;

use alloy_primitives::Address;
use appchain_core_contract_client::clients::StarknetCoreContractClient;
use appchain_core_contract_client::interfaces::core_contract::CoreContract;
use async_trait::async_trait;
Expand Down Expand Up @@ -45,8 +44,8 @@ use url::Url;
pub struct StarknetSettlementValidatedArgs {
pub starknet_rpc_url: Url,
pub starknet_private_key: String,
pub starknet_account_address: Address,
pub starknet_cairo_core_contract_address: Address,
pub starknet_account_address: String,
pub starknet_cairo_core_contract_address: String,
pub starknet_finality_retry_wait_in_secs: u64,
}

Expand Down
25 changes: 7 additions & 18 deletions crates/settlement-clients/starknet/src/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::env;
use std::path::Path;
use std::str::FromStr as _;
use std::sync::Arc;
use std::time::Duration;

use alloy_primitives::Address;
use color_eyre::eyre::eyre;
use rstest::{fixture, rstest};
use settlement_client_interface::SettlementClient;
Expand Down Expand Up @@ -84,14 +82,10 @@ async fn setup(#[future] spin_up_madara: MadaraCmd) -> (LocalWalletSignerMiddlew
let starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs {
starknet_rpc_url: Url::parse(madara_process.rpc_url.as_ref()).unwrap(),
starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"),
starknet_account_address: Address::from_str(&get_env_var_or_panic(
"MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS",
))
.unwrap(),
starknet_cairo_core_contract_address: Address::from_str(&get_env_var_or_panic(
starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"),
starknet_cairo_core_contract_address: get_env_var_or_panic(
"MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS",
))
.unwrap(),
),
starknet_finality_retry_wait_in_secs: get_env_var_or_panic(
"MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS",
)
Expand Down Expand Up @@ -126,14 +120,10 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd))
let mut starknet_settlement_params: StarknetSettlementValidatedArgs = StarknetSettlementValidatedArgs {
starknet_rpc_url: madara_process.rpc_url.clone(),
starknet_private_key: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_PRIVATE_KEY"),
starknet_account_address: Address::from_str(&get_env_var_or_panic(
"MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS",
))
.unwrap(),
starknet_cairo_core_contract_address: Address::from_str(&get_env_var_or_panic(
starknet_account_address: get_env_var_or_panic("MADARA_ORCHESTRATOR_STARKNET_ACCOUNT_ADDRESS"),
starknet_cairo_core_contract_address: get_env_var_or_panic(
"MADARA_ORCHESTRATOR_STARKNET_CAIRO_CORE_CONTRACT_ADDRESS",
))
.unwrap(),
),
starknet_finality_retry_wait_in_secs: get_env_var_or_panic(
"MADARA_ORCHESTRATOR_STARKNET_FINALITY_RETRY_WAIT_IN_SECS",
)
Expand Down Expand Up @@ -170,8 +160,7 @@ async fn test_settle(#[future] setup: (LocalWalletSignerMiddleware, MadaraCmd))
let deployed_address = deploy_v1.deployed_address();

// env::set_var("STARKNET_CAIRO_CORE_CONTRACT_ADDRESS", deployed_address.to_hex_string());
starknet_settlement_params.starknet_cairo_core_contract_address =
Address::from_str(&deployed_address.to_hex_string()).unwrap();
starknet_settlement_params.starknet_cairo_core_contract_address = deployed_address.to_hex_string();

let InvokeTransactionResult { transaction_hash: deploy_tx_hash } =
deploy_v1.send().await.expect("Unable to deploy contract");
Expand Down
30 changes: 10 additions & 20 deletions e2e-tests/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum OrchestratorMode {
impl Orchestrator {
pub fn new(mode: OrchestratorMode, mut envs: Vec<(String, String)>) -> Option<Self> {
let repository_root = &get_repository_root();
let mut address = String::new();
std::env::set_current_dir(repository_root).expect("Failed to change working directory");

let is_run_mode = mode == OrchestratorMode::Run;
Expand Down Expand Up @@ -65,34 +66,24 @@ impl Orchestrator {
command.arg("--da-on-ethereum");
command.arg("--sharp");
command.arg("--mongodb");

} else {
command.arg("--aws-event-bridge");
}

// Configure run-specific settings
let address = if is_run_mode {
let port = get_free_port();
let addr = format!("127.0.0.1:{}", port);
envs.push(("MADARA_ORCHESTRATOR_PORT".to_string(), port.to_string()));
addr
} else {
String::new()
};
address = addr;

command.current_dir(repository_root).envs(envs);

// Handle stdout/stderr differently based on mode
if is_run_mode {
command.stdout(Stdio::piped()).stderr(Stdio::piped());
} else {
command.arg("--aws-event-bridge");

// For setup mode, inherit the stdio to show output directly
command.stdout(Stdio::inherit()).stderr(Stdio::inherit());
}

command.current_dir(repository_root).envs(envs);

let mut process = command.spawn().expect("Failed to start process");

// Set up stdout and stderr handling only for run mode
if is_run_mode {
let stdout = process.stdout.take().expect("Failed to capture stdout");
thread::spawn(move || {
Expand All @@ -113,9 +104,8 @@ impl Orchestrator {
}
});
});
}

if is_run_mode { Some(Self { process, address }) } else {
Some(Self { process, address })
} else {
// Wait for the process to complete and get its exit status
let status = process.wait().expect("Failed to wait for process");
if status.success() {
Expand All @@ -129,9 +119,9 @@ impl Orchestrator {
}
}
None
}
}
}

pub fn endpoint(&self) -> Url {
Url::parse(&format!("http://{}", self.address)).unwrap()
}
Expand Down
Loading

0 comments on commit 982aed9

Please sign in to comment.