Skip to content

Commit

Permalink
feat : updated madara spwan process in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdbytes committed Dec 4, 2024
1 parent ecb6a42 commit f8bb6d4
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 224 deletions.
15 changes: 1 addition & 14 deletions .github/workflows/test-bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ jobs:
ref: "d188aa91efa78bcc54f92aa1035295fd50e068d2"
path: madara

- name: Move Madara Devnet config
working-directory: madara
run: |
ls
mv configs/presets/devnet.yaml ../bin/devnet.yaml
- name: Build Madara
working-directory: madara
run: |
cargo build
mv target/debug/madara ../bin/madara
cd ..
- name: Run anvil
run: |
anvil &
Expand All @@ -105,7 +92,7 @@ jobs:
run: |
git submodule update --init --recursive
make artifacts-linux
RUST_BACKTRACE=1 RUST_LOG=debug cargo test -- deposit_tests_both_bridges --nocapture
cargo llvm-cov nextest --release --lcov --output-path lcov.info
- name: Coveralls
uses: coverallsapp/github-action@v2
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ addresses.json
/bin/madara
/bin/devnet.yaml
.cairo
/artifacts
/artifacts
madara-dbs
madara/
8 changes: 0 additions & 8 deletions src/setup_scripts/account_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ pub async fn account_init<'a>(clients: &'a Clients, arg_config: &'a ConfigFile)

log::info!("Waiting for block to be mined [/]");
sleep(Duration::from_secs(10)).await;
println!(">>> wait done");

let account_address_temp =
deploy_account_using_priv_key(TEMP_ACCOUNT_PRIV_KEY.to_string(), clients.provider_l2(), oz_account_class_hash)
.await;
println!(">>> account address temp deployed");
sleep(Duration::from_secs(10)).await;
println!(">>> wait done");

let user_account_temp = build_single_owner_account(
clients.provider_l2(),
Expand All @@ -42,18 +39,15 @@ pub async fn account_init<'a>(clients: &'a Clients, arg_config: &'a ConfigFile)
false,
)
.await;
println!(">>> temp account built");
let oz_account_caio_1_class_hash = declare_contract(DeclarationInput::DeclarationInputs(
String::from(OZ_ACCOUNT_SIERRA_PATH),
String::from(OZ_ACCOUNT_CASM_PATH),
user_account_temp.clone(),
))
.await;
println!(">>> oz_account_caio_1_class_hash declared");
save_to_json("oz_account_caio_1_class_hash", &JsonValueType::StringType(oz_account_caio_1_class_hash.to_string()))
.unwrap();
sleep(Duration::from_secs(10)).await;
println!(">>> wait done");
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

// Using Account Cairo 1 contract
Expand All @@ -64,9 +58,7 @@ pub async fn account_init<'a>(clients: &'a Clients, arg_config: &'a ConfigFile)
oz_account_caio_1_class_hash,
)
.await;
println!(">>> cairo 1 account declared");
save_to_json("account_address", &JsonValueType::StringType(account_address.to_string())).unwrap();
println!(">>> account init done.");
build_single_owner_account(
clients.provider_l2(),
&arg_config.rollup_priv_key,
Expand Down
2 changes: 1 addition & 1 deletion src/setup_scripts/braavos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> BraavosSetup<'a> {
.account
.invoke_contract(
self.udc_address,
"deploy_contract",
"deployContract",
vec![braavos_aggregator_class_hash, Felt::ZERO, Felt::ZERO, Felt::ZERO],
None,
)
Expand Down
172 changes: 0 additions & 172 deletions src/tests/madara.rs

This file was deleted.

87 changes: 59 additions & 28 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
pub mod constants;
mod erc20_bridge;
mod eth_bridge;
mod madara;

use std::process::Command;
use std::time::Duration;
use std::{env, fs};

use rstest::rstest;
use tokio::time::sleep;

use crate::contract_clients::config::Clients;
use crate::tests::erc20_bridge::erc20_bridge_test_helper;
use crate::tests::eth_bridge::eth_bridge_test_helper;
use crate::tests::madara::MadaraCmdBuilder;
use crate::{bootstrap, setup_core_contract, setup_l2, BootstrapperOutput, ConfigFile};

async fn test_setup(args: &ConfigFile, clients: &Clients) -> BootstrapperOutput {
Expand All @@ -26,35 +26,46 @@ async fn test_setup(args: &ConfigFile, clients: &Clients) -> BootstrapperOutput
config.core_contract_address = Some(format!("{:?}", core_contract_address));
config.core_contract_implementation_address = Some(format!("{:?}", core_contract_implementation_address));

let mut node = MadaraCmdBuilder::new()
.args([
"--no-sync-polling",
"--l1-endpoint",
"http://localhost:8545",
"--chain-config-path=./bin/devnet.yaml",
"--rpc-cors",
"*",
"--rpc-external",
"--sequencer",
"--feeder-gateway-enable",
"--gateway-enable",
"--gateway-external",
"--rpc-methods",
"unsafe",
"--gas-price",
"0",
"--blob-gas-price",
"0",
"--strk-gas-price",
"0",
"--strk-blob-gas-price",
"0",
])
.run();
node.wait_for_ready().await;
env::set_current_dir("madara").expect("madara folder doesn't exist.");
fs::create_dir_all("../madara-dbs").expect("unable to create folders");
env::set_var("RUST_LOG", "info");

// Running madara
Command::new("cargo")
.arg("+1.81")
.arg("run")
.arg("--release")
.arg("--")
.arg("--name")
.arg("madara")
.arg("--base-path")
.arg("../madara-dbs/madara_pathfinder_test_11")
.arg("--rpc-port")
.arg("19944")
.arg("--rpc-cors")
.arg("*")
.arg("--rpc-external")
.arg("--sequencer")
.arg("--chain-config-path")
.arg("configs/presets/devnet.yaml")
.arg("--feeder-gateway-enable")
.arg("--gateway-enable")
.arg("--gateway-external")
.arg("--gas-price")
.arg("0")
.arg("--blob-gas-price")
.arg("0")
.arg("--rpc-methods")
.arg("unsafe")
.arg("--l1-endpoint")
.arg("http://localhost:8545")
.spawn()
.unwrap();

sleep(Duration::from_secs(5)).await;

env::set_current_dir("../").expect("Navigate back failed.");

// Setup L2 with the updated config
let l2_output = setup_l2(&config, clients).await;

Expand Down Expand Up @@ -126,6 +137,10 @@ async fn deposit_and_withdraw_erc20_bridge() -> Result<(), anyhow::Error> {
async fn deposit_tests_both_bridges() -> Result<(), anyhow::Error> {
env_logger::init();
let config = get_test_config_file();

// This will kill the madara when this test fails/passes
let _port_killer = PortKiller;

let clients = Clients::init_from_config(&config).await;
let out = test_setup(&config, &clients).await;

Expand Down Expand Up @@ -153,6 +168,22 @@ async fn deposit_tests_both_bridges() -> Result<(), anyhow::Error> {
Ok(())
}

// Create a struct that will kill the process on port when dropped
struct PortKiller;
impl Drop for PortKiller {
fn drop(&mut self) {
kill_process_on_port(19944);
}
}

fn kill_process_on_port(port: u16) {
Command::new("sh")
.arg("-c")
.arg(format!("lsof -i :{} | grep LISTEN | awk '{{print $2}}' | xargs kill -9", port))
.output()
.expect("Failed to execute command");
}

fn get_test_config_file() -> ConfigFile {
ConfigFile::default()
}

0 comments on commit f8bb6d4

Please sign in to comment.