Skip to content

Commit

Permalink
Test/improve ci (#1430)
Browse files Browse the repository at this point in the history
* add ci profile

* add ci profile

Signed-off-by: Gregory Edison <[email protected]>

* add nextest

* fix testing

---------

Signed-off-by: Gregory Edison <[email protected]>
  • Loading branch information
greged93 authored Oct 10, 2024
1 parent 53a9e6d commit 5d9e1e7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/rust_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
# <https://github.com/paradigmxyz/reth/blob/027d50fc105fd527dca0bf56fe51b7240f119e66/.github/workflows/hive.yml>
Expand Down
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ lint:
- [email protected]
- [email protected]
- [email protected]
- deno@1.46.3
- deno@2.0.0
ignore:
- linters: [ALL]
paths:
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ readme = "./README.md"
license = "MIT"
rust-version = "1.81"

# Lints

[lints]
rust.missing_debug_implementations = "warn"
rust.unreachable_pub = "warn"
Expand Down Expand Up @@ -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 = [
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 3 additions & 20 deletions src/test_utils/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<u16>> = 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.
Expand Down Expand Up @@ -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?)
}
Expand Down

0 comments on commit 5d9e1e7

Please sign in to comment.