From c78c98ba170ad4ce6dddf04b5098082994850f46 Mon Sep 17 00:00:00 2001 From: Charpa Date: Fri, 10 Jan 2025 14:00:28 +0100 Subject: [PATCH 1/3] chore(ci): minor fixes to improve CI workflow --- .github/workflows/coverage.yml | 4 +- .github/workflows/db-version.yml | 10 +++-- .github/workflows/pull-request.yml | 8 ++-- Cargo.lock | 41 ------------------ Cargo.toml | 1 - crates/madara/client/eth/Cargo.toml | 1 - crates/madara/client/eth/src/client.rs | 44 ++++++++++++++------ crates/madara/client/eth/src/l1_gas_price.rs | 7 ---- scripts/e2e-coverage.sh | 6 ++- scripts/e2e-tests.sh | 9 +++- scripts/update-db-version.sh | 6 +-- 11 files changed, 59 insertions(+), 78 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 418fb07d3..74b5cfbaa 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -22,7 +22,7 @@ jobs: with: toolchain: 1.81 - - uses: Swatinem/rust-cache@v2 # use a different cache key as coverae uses custom rustc args + - uses: Swatinem/rust-cache@v2 # use a different cache key as coverage uses custom rustc args with: cache-provider: buildjet key: "coverage" @@ -49,7 +49,7 @@ jobs: cargo build --bin madara --profile dev export COVERAGE_BIN=$(realpath target/debug/madara) rm -f target/madara-* lcov.info - cargo test --profile dev --workspace -- --test-threads=1 + cargo test --profile dev --workspace - name: Generate coverage info run: | diff --git a/.github/workflows/db-version.yml b/.github/workflows/db-version.yml index b2d2b9554..158b287c7 100644 --- a/.github/workflows/db-version.yml +++ b/.github/workflows/db-version.yml @@ -9,11 +9,15 @@ jobs: update-db-version: runs-on: ubuntu-latest if: contains(github.event.pull_request.labels.*.name, 'db-migration') + permissions: + contents: write steps: - uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref || github.ref_name }} - name: Install yq - run: sudo apt-get install -y yq + uses: mikefarah/yq@master - name: Check if PR already bumped id: check_bump @@ -40,7 +44,7 @@ jobs: if: steps.check_bump.outputs.already_bumped == 'false' run: | if [[ -n "$(git status --porcelain)" ]]; then - git add .db-versions.toml + git add .db-versions.yml git commit -m "chore: bump db version" - git push origin HEAD + git push origin ${{ github.head_ref || github.ref_name }} fi diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 915d41ad1..55b510e86 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,6 +11,7 @@ concurrency: cancel-in-progress: true permissions: + contents: write pull-requests: write jobs: @@ -22,7 +23,7 @@ jobs: linters: name: Run linters needs: update_db_version - if: ${{ always() }} + if: ${{ github.event.pull_request.draft == false && always() }} uses: ./.github/workflows/linters.yml rust_check: @@ -38,18 +39,17 @@ jobs: coverage: name: Run Coverage needs: update_db_version - if: ${{ always() }} + if: ${{ github.event.pull_request.draft == false && always() }} secrets: inherit uses: ./.github/workflows/coverage.yml build: name: Build Madara needs: update_db_version - if: ${{ always() }} + if: ${{ github.event.pull_request.draft == false && always() }} uses: ./.github/workflows/build.yml js_test: name: Run JS Tests needs: build - if: ${{ always() }} uses: ./.github/workflows/starknet-js-test.yml diff --git a/Cargo.lock b/Cargo.lock index 17594e159..5f4ad8a5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5672,7 +5672,6 @@ dependencies = [ "rstest 0.18.2", "serde", "serde_json", - "serial_test", "starknet-types-core 0.1.7 (git+https://github.com/kasarlabs/types-rs.git?branch=feat-deserialize-v0.1.7)", "starknet_api", "tempfile", @@ -7709,15 +7708,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scc" -version = "2.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d25269dd3a12467afe2e510f69fb0b46b698e5afb296b59f2145259deaf8e8" -dependencies = [ - "sdd", -] - [[package]] name = "schannel" version = "0.1.26" @@ -7780,12 +7770,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "sdd" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49c1eeaf4b6a87c7479688c6d52b9f1153cedd3c489300564f932b065c6eab95" - [[package]] name = "sec1" version = "0.7.3" @@ -7984,31 +7968,6 @@ dependencies = [ "unsafe-libyaml", ] -[[package]] -name = "serial_test" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b4b487fe2acf240a021cf57c6b2b4903b1e78ca0ecd862a71b71d2a51fed77d" -dependencies = [ - "futures", - "log", - "once_cell", - "parking_lot 0.12.3", - "scc", - "serial_test_derive", -] - -[[package]] -name = "serial_test_derive" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.89", -] - [[package]] name = "sha-1" version = "0.9.8" diff --git a/Cargo.toml b/Cargo.toml index d991919ee..4f5e29d95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -221,7 +221,6 @@ dotenv = "0.15.0" httpmock = "0.7.0" tempfile = "3.10.1" mockall = "0.13.0" -serial_test = "3.1.1" itertools = "0.13.0" regex = "1.10.5" bytes = "1.6.0" diff --git a/crates/madara/client/eth/Cargo.toml b/crates/madara/client/eth/Cargo.toml index d46f3a436..c944fdbb2 100644 --- a/crates/madara/client/eth/Cargo.toml +++ b/crates/madara/client/eth/Cargo.toml @@ -81,7 +81,6 @@ tempfile.workspace = true dotenv.workspace = true httpmock.workspace = true tracing-test = "0.2.5" -serial_test.workspace = true lazy_static.workspace = true mp-utils = { workspace = true, features = ["testing"] } mc-mempool = { workspace = true, features = ["testing"] } diff --git a/crates/madara/client/eth/src/client.rs b/crates/madara/client/eth/src/client.rs index 8d2e7659f..196afbf48 100644 --- a/crates/madara/client/eth/src/client.rs +++ b/crates/madara/client/eth/src/client.rs @@ -167,8 +167,7 @@ pub mod eth_client_getter_test { primitives::U256, }; - use serial_test::serial; - use std::ops::Range; + use std::ops::{Deref, Range}; use std::sync::Mutex; use tokio; @@ -212,12 +211,37 @@ pub mod eth_client_getter_test { static ANVIL: Mutex>> = Mutex::new(None); - pub fn get_shared_anvil() -> Arc { - let mut anvil = ANVIL.lock().expect("poisoned lock"); - if anvil.is_none() { - *anvil = Some(Arc::new(create_anvil_instance())); + /// Wrapper for an Anvil instance that automatically cleans up when all handles are dropped + pub struct AnvilHandle { + instance: Arc, + } + + impl Drop for AnvilHandle { + fn drop(&mut self) { + let mut guard = ANVIL.lock().expect("poisoned lock"); + // Check if this Arc is the last one (strong_count == 2 because of our reference + // and the one in the static) + if Arc::strong_count(&self.instance) == 2 { + println!("Cleaning up Anvil instance"); + *guard = None; + } + } + } + + impl Deref for AnvilHandle { + type Target = AnvilInstance; + + fn deref(&self) -> &Self::Target { + &self.instance + } + } + + pub fn get_shared_anvil() -> AnvilHandle { + let mut guard = ANVIL.lock().expect("poisoned lock"); + if guard.is_none() { + *guard = Some(Arc::new(create_anvil_instance())); } - Arc::clone(anvil.as_ref().unwrap()) + AnvilHandle { instance: Arc::clone(guard.as_ref().unwrap()) } } pub fn create_anvil_instance() -> AnvilInstance { @@ -245,7 +269,6 @@ pub mod eth_client_getter_test { EthereumClient { provider: Arc::new(provider), l1_core_contract: contract.clone(), l1_block_metrics } } - #[serial] #[tokio::test] async fn fail_create_new_client_invalid_core_contract() { let anvil = get_shared_anvil(); @@ -261,7 +284,6 @@ pub mod eth_client_getter_test { assert!(new_client_result.is_err(), "EthereumClient::new should fail with an invalid core contract address"); } - #[serial] #[tokio::test] async fn get_latest_block_number_works() { let anvil = get_shared_anvil(); @@ -271,7 +293,6 @@ pub mod eth_client_getter_test { assert_eq!(block_number, L1_BLOCK_NUMBER, "provider unable to get the correct block number"); } - #[serial] #[tokio::test] async fn get_last_event_block_number_works() { let anvil = get_shared_anvil(); @@ -283,7 +304,6 @@ pub mod eth_client_getter_test { assert_eq!(block_number, L1_BLOCK_NUMBER, "block number with given event not matching"); } - #[serial] #[tokio::test] async fn get_last_verified_block_hash_works() { let anvil = get_shared_anvil(); @@ -294,7 +314,6 @@ pub mod eth_client_getter_test { assert_eq!(block_hash, expected, "latest block hash not matching"); } - #[serial] #[tokio::test] async fn get_last_state_root_works() { let anvil = get_shared_anvil(); @@ -304,7 +323,6 @@ pub mod eth_client_getter_test { assert_eq!(state_root, expected, "latest block state root not matching"); } - #[serial] #[tokio::test] async fn get_last_verified_block_number_works() { let anvil = get_shared_anvil(); diff --git a/crates/madara/client/eth/src/l1_gas_price.rs b/crates/madara/client/eth/src/l1_gas_price.rs index 4d02f4a37..723ccbd13 100644 --- a/crates/madara/client/eth/src/l1_gas_price.rs +++ b/crates/madara/client/eth/src/l1_gas_price.rs @@ -135,12 +135,10 @@ mod eth_client_gas_price_worker_test { use crate::client::eth_client_getter_test::{create_ethereum_client, get_shared_anvil}; use httpmock::{MockServer, Regex}; use mc_mempool::GasPriceProvider; - use serial_test::serial; use std::time::SystemTime; use tokio::task::JoinHandle; use tokio::time::{timeout, Duration}; - #[serial] #[tokio::test] async fn gas_price_worker_when_infinite_loop_true_works() { let anvil = get_shared_anvil(); @@ -184,7 +182,6 @@ mod eth_client_gas_price_worker_test { assert_eq!(updated_price.eth_l1_data_gas_price, 1); } - #[serial] #[tokio::test] async fn gas_price_worker_when_infinite_loop_false_works() { let anvil = get_shared_anvil(); @@ -203,7 +200,6 @@ mod eth_client_gas_price_worker_test { assert_eq!(updated_price.eth_l1_data_gas_price, 1); } - #[serial] #[tokio::test] async fn gas_price_worker_when_gas_price_fix_works() { let anvil = get_shared_anvil(); @@ -224,7 +220,6 @@ mod eth_client_gas_price_worker_test { assert_eq!(updated_price.eth_l1_data_gas_price, 1); } - #[serial] #[tokio::test] async fn gas_price_worker_when_data_gas_price_fix_works() { let anvil = get_shared_anvil(); @@ -245,7 +240,6 @@ mod eth_client_gas_price_worker_test { assert_eq!(updated_price.eth_l1_data_gas_price, 20); } - #[serial] #[tokio::test] async fn gas_price_worker_when_eth_fee_history_fails_should_fails() { let mock_server = MockServer::start(); @@ -311,7 +305,6 @@ mod eth_client_gas_price_worker_test { mock.assert(); } - #[serial] #[tokio::test] async fn update_gas_price_works() { let anvil = get_shared_anvil(); diff --git a/scripts/e2e-coverage.sh b/scripts/e2e-coverage.sh index 60e6c271c..a4abfb627 100755 --- a/scripts/e2e-coverage.sh +++ b/scripts/e2e-coverage.sh @@ -16,7 +16,11 @@ cargo build --bin madara --profile dev export COVERAGE_BIN=$(realpath target/debug/madara) # Run tests with coverage collection -cargo test --profile dev "${@:-"--workspace"}" +if cargo test --profile dev "${@:-"--workspace"}"; then + echo "✅ All tests passed successfully!" +else + echo "❌ Some tests failed." +fi # Generate coverage reports cargo llvm-cov report --lcov --output-path lcov.info # Generate LCOV report diff --git a/scripts/e2e-tests.sh b/scripts/e2e-tests.sh index 9baf73c59..9061e8265 100755 --- a/scripts/e2e-tests.sh +++ b/scripts/e2e-tests.sh @@ -10,7 +10,12 @@ export ETH_FORK_URL=https://eth.merkle.io # Build the binary cargo build --bin madara --profile dev -export BINARY_PATH=$(realpath target/debug/madara) +export COVERAGE_BIN=$(realpath target/debug/madara) # Run the tests -cargo test --profile dev "${@:-"--workspace"}" +if cargo test --profile dev "${@:-"--workspace"}"; then + echo "✅ All tests passed successfully!" +else + echo "❌ Some tests failed." + exit 1 +fi diff --git a/scripts/update-db-version.sh b/scripts/update-db-version.sh index a57bb2b5a..7f0d75a91 100755 --- a/scripts/update-db-version.sh +++ b/scripts/update-db-version.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Database version management script @@ -64,7 +64,7 @@ CURRENT_VERSION=$(yq '.current_version' "$FILE") NEW_VERSION=$((CURRENT_VERSION + 1)) # Update version and append to history -yq -i -y ".current_version = $NEW_VERSION | - .versions = [{\"version\": $NEW_VERSION, \"pr\": $PR_NUMBER}] + .versions" "$FILE" +yq e ".current_version = $NEW_VERSION | + .versions = [{\"version\": $NEW_VERSION, \"pr\": $PR_NUMBER}] + .versions" -i "$FILE" echo "Successfully updated DB version to ${NEW_VERSION} (PR #${PR_NUMBER})" \ No newline at end of file From 97f815e36d1363db9a1a323386f4617b45a8415e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 13 Jan 2025 12:08:22 +0000 Subject: [PATCH 2/3] chore: bump db version --- .db-versions.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.db-versions.yml b/.db-versions.yml index db6802319..fcc8a9d16 100644 --- a/.db-versions.yml +++ b/.db-versions.yml @@ -1,4 +1,6 @@ -current_version: 0 +current_version: 1 versions: + - version: 1 + pr: 460 - version: 0 pr: 372 From 66b6514fd3187a05e75b717e21b09d3a710b5e71 Mon Sep 17 00:00:00 2001 From: Charpa Date: Mon, 13 Jan 2025 13:18:44 +0100 Subject: [PATCH 3/3] Revert "chore: bump db version" This reverts commit 97f815e36d1363db9a1a323386f4617b45a8415e. --- .db-versions.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.db-versions.yml b/.db-versions.yml index fcc8a9d16..db6802319 100644 --- a/.db-versions.yml +++ b/.db-versions.yml @@ -1,6 +1,4 @@ -current_version: 1 +current_version: 0 versions: - - version: 1 - pr: 460 - version: 0 pr: 372