From 5d9e1e7b706ede58528ca8a16c332d5e25fe09df Mon Sep 17 00:00:00 2001 From: greged93 <82421016+greged93@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:33:09 +0200 Subject: [PATCH] Test/improve ci (#1430) * add ci profile * add ci profile Signed-off-by: Gregory Edison * add nextest * fix testing --------- Signed-off-by: Gregory Edison --- .config/nextest.toml | 6 ++++++ .github/workflows/rust_test.yml | 2 +- .trunk/trunk.yaml | 2 +- Cargo.toml | 4 ++++ Makefile | 3 +++ src/test_utils/rpc/mod.rs | 23 +++-------------------- 6 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 .config/nextest.toml diff --git a/.config/nextest.toml b/.config/nextest.toml new file mode 100644 index 000000000..6cc1108bc --- /dev/null +++ b/.config/nextest.toml @@ -0,0 +1,6 @@ +[profile.ci] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" +# Do not cancel the test run on the first failure. +fail-fast = false diff --git a/.github/workflows/rust_test.yml b/.github/workflows/rust_test.yml index 88b0535c5..bd9f31ca9 100644 --- a/.github/workflows/rust_test.yml +++ b/.github/workflows/rust_test.yml @@ -47,7 +47,7 @@ jobs: - name: Create dump run: ./scripts/make_with_env.sh katana-genesis - name: Test code - run: make test + run: make test-ci # Inspired by Reth CI. # diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index db2b5af0f..85dea098e 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -44,7 +44,7 @@ lint: - trivy@0.56.1 - trufflehog@3.82.7 - yamllint@1.35.1 - - deno@1.46.3 + - deno@2.0.0 ignore: - linters: [ALL] paths: diff --git a/Cargo.toml b/Cargo.toml index 6c6214693..6e411cf75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,8 @@ readme = "./README.md" license = "MIT" rust-version = "1.81" +# Lints + [lints] rust.missing_debug_implementations = "warn" rust.unreachable_pub = "warn" @@ -47,6 +49,8 @@ default_trait_access = "allow" module_name_repetitions = "allow" no_effect_underscore_binding = "allow" +# Deps + [dependencies] # Starknet dependencies cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.1", default-features = false, features = [ diff --git a/Makefile b/Makefile index d208e7713..13375173a 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,9 @@ run-katana: katana-genesis test: katana-genesis load-env cargo test --all --features testing +test-ci: load-env + cargo nextest run --all --features testing --profile ci + # Example: `make test-target TARGET=test_raw_transaction` test-target: load-env cargo test --tests --all-features $(TARGET) -- --nocapture diff --git a/src/test_utils/rpc/mod.rs b/src/test_utils/rpc/mod.rs index e734dcb7e..a6075c5c7 100644 --- a/src/test_utils/rpc/mod.rs +++ b/src/test_utils/rpc/mod.rs @@ -3,24 +3,7 @@ use crate::eth_rpc::{config::RPCConfig, rpc::KakarotRpcModuleBuilder, run_server use jsonrpsee::server::ServerHandle; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::{net::SocketAddr, sync::LazyLock}; -use tokio::sync::Mutex; - -/// A lazy static mutex for managing the next available port number. -/// -/// It ensures thread-safe access to the next port number. -pub static NEXT_PORT: LazyLock> = LazyLock::new(|| Mutex::new(3030)); - -/// Asynchronously gets the next available port number. -/// -/// This function locks the `NEXT_PORT` mutex to ensure exclusive access -/// to the next port number and increments it for subsequent calls. -async fn get_next_port() -> u16 { - let mut port = NEXT_PORT.lock().await; - let next_port = *port; - *port += 1; - next_port -} +use std::net::SocketAddr; /// Sets up the environment for Kakarot RPC integration tests by deploying the Kakarot contracts /// and starting the Kakarot RPC server. @@ -77,9 +60,9 @@ pub async fn start_kakarot_rpc_server(katana: &Katana) -> Result<(SocketAddr, Se Ok(run_server( KakarotRpcModuleBuilder::new(eth_client.into()).rpc_module()?, #[cfg(feature = "testing")] - RPCConfig::new_test_config_from_port(get_next_port().await), + RPCConfig::new_test_config_from_port(rand::random()), #[cfg(not(feature = "testing"))] - RPCConfig::from_port(get_next_port().await), + RPCConfig::from_port(3030), ) .await?) }