Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add coveralls to ci #257

Merged
merged 15 commits into from
Sep 12, 2024
22 changes: 5 additions & 17 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Task - Integration Tests

on:
Expand Down Expand Up @@ -31,16 +30,6 @@ jobs:
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Launch Anvil
run: anvil --fork-url $ANVIL_FORK_URL --fork-block-number $ANVIL_BLOCK_NUMBER &
env:
ANVIL_FORK_URL: "https://eth.merkle.io"
ANVIL_BLOCK_NUMBER: 20395662
- name: Wait for Anvil to be ready
run: |
while ! nc -z localhost 8545; do
sleep 1
done

- name: Build and run tests
run: |
Expand All @@ -53,11 +42,10 @@ jobs:
- name: Generate coverage info
run: |
source <(cargo llvm-cov show-env --export-prefix)
cargo llvm-cov report --cobertura --output-path coverage.cobertura.xml
cargo llvm-cov report --lcov --output-path lcov.info

- name: Display coverage
uses: ewjoachim/coverage-comment-action@v1
continue-on-error: true
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
GITHUB_TOKEN: ${{ github.token }}
COVERAGE_FILE: coverage.cobertura.xml
files: lcov.info
debug: true
1 change: 1 addition & 0 deletions .github/workflows/linters-cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ jobs:
- name: Format and clippy
run: |
cargo fmt -- --check
cargo clippy --workspace --no-deps -- -D warnings
cargo clippy --workspace --tests --no-deps -- -D warnings
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- ci: add coveralls report
- test: added tests for declare and deploy transactions
- fix: pending block must always be returned in rpc even if none is in db
- fix: fixed the starting block arg with an ignore_block_order argument
Expand Down
28 changes: 22 additions & 6 deletions crates/client/eth/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,43 @@ impl EthereumClient {
#[cfg(test)]
pub mod eth_client_getter_test {
use super::*;
use alloy::primitives::U256;
use alloy::{
node_bindings::{Anvil, AnvilInstance},
primitives::U256,
};
use mc_metrics::MetricsService;
use rstest::*;
use tokio;

// https://etherscan.io/tx/0xcadb202495cd8adba0d9b382caff907abf755cd42633d23c4988f875f2995d81#eventlog
// The txn we are referring to it is here ^
const L1_BLOCK_NUMBER: u64 = 20395662;
const FORK_URL: &str = "https://eth.merkle.io";
const CORE_CONTRACT_ADDRESS: &str = "0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4";
const L2_BLOCK_NUMBER: u64 = 662703;
const L2_BLOCK_HASH: &str = "563216050958639290223177746678863910249919294431961492885921903486585884664";
const L2_STATE_ROOT: &str = "1456190284387746219409791261254265303744585499659352223397867295223408682130";

#[fixture]
#[once]
fn anvil_instance() -> AnvilInstance {
let anvil = Anvil::new()
.fork(FORK_URL)
.fork_block_number(L1_BLOCK_NUMBER)
.try_spawn()
.expect("failed to spawn anvil instance");
println!("Anvil started and running at `{}`", anvil.endpoint());
anvil
}

#[rstest]
#[tokio::test]
async fn fail_create_new_client_invalid_core_contract() {
async fn fail_create_new_client_invalid_core_contract(anvil_instance: &AnvilInstance) {
let anvil = anvil_instance;
// Sepolia core contract instead of mainnet
const INVALID_CORE_CONTRACT_ADDRESS: &str = "0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057";

let rpc_url_string = String::from("http://localhost:8545");
let rpc_url: Url = rpc_url_string.parse().expect("issue while parsing URL");
let rpc_url: Url = anvil.endpoint_url();

let core_contract_address = Address::parse_checksummed(INVALID_CORE_CONTRACT_ADDRESS, None).unwrap();
let prometheus_service = MetricsService::new(true, false, 9615).unwrap();
Expand All @@ -183,8 +199,8 @@ pub mod eth_client_getter_test {

#[fixture]
#[once]
pub fn eth_client() -> EthereumClient {
create_ethereum_client(None)
pub fn eth_client(anvil_instance: &AnvilInstance) -> EthereumClient {
create_ethereum_client(Some(&anvil_instance.endpoint()))
}

#[rstest]
Expand Down
17 changes: 3 additions & 14 deletions crates/client/eth/src/l1_gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async fn update_l1_block_metrics(eth_client: &EthereumClient, l1_gas_provider: G
#[cfg(test)]
mod eth_client_gas_price_worker_test {
use super::*;
use crate::client::eth_client_getter_test::create_ethereum_client;
use crate::client::eth_client_getter_test::{create_ethereum_client, eth_client};
use alloy::node_bindings::Anvil;
use httpmock::{MockServer, Regex};
use mc_mempool::GasPriceProvider;
Expand All @@ -109,20 +109,9 @@ mod eth_client_gas_price_worker_test {
(server, eth_client)
}

#[fixture]
#[once]
pub fn eth_client() -> EthereumClient {
create_ethereum_client(None)
}

#[rstest]
#[tokio::test]
async fn gas_price_worker_when_infinite_loop_true_works() {
let anvil = Anvil::new()
.fork("https://eth.merkle.io")
.fork_block_number(20395662)
.try_spawn()
.expect("issue while forking for the anvil");
let eth_client = create_ethereum_client(Some(anvil.endpoint().as_str()));
async fn gas_price_worker_when_infinite_loop_true_works(eth_client: &EthereumClient) {
let l1_gas_provider = GasPriceProvider::new();

// Spawn the gas_price_worker in a separate task
Expand Down
5 changes: 0 additions & 5 deletions crates/node/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ pub struct RunCmd {
/// The network chain configuration.
#[clap(long, short, default_value = "main")]
pub network: NetworkType,

/// Run the TUI dashboard
#[cfg(feature = "tui")]
#[clap(long)]
pub tui: bool,
}

impl RunCmd {
Expand Down
6 changes: 3 additions & 3 deletions crates/node/src/cli/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct SyncParams {
pub unsafe_starting_block: Option<u64>,

/// This will produce sound interpreted from the block hashes.
#[cfg(feature = "m")]
#[cfg(feature = "sound")]
#[clap(long)]
pub sound: bool,

Expand Down Expand Up @@ -57,9 +57,9 @@ impl SyncParams {

let polling = if self.no_sync_polling { None } else { Some(Duration::from_secs(self.sync_polling_interval)) };

#[cfg(feature = "m")]
#[cfg(feature = "sound")]
let sound = self.sound;
#[cfg(not(feature = "m"))]
#[cfg(not(feature = "sound"))]
let sound = false;

FetchConfig {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.78"
channel = "1.81"
components = ["rustfmt", "clippy", "rust-analyzer"]
profile = "minimal"
5 changes: 0 additions & 5 deletions scripts/e2e-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash
set -e

# will also launch anvil and automatically close it down on error or success

anvil --fork-url https://eth.merkle.io --fork-block-number 20395662 &

subshell() {
set -e
rm -f target/madara-* lcov.info
Expand All @@ -21,5 +17,4 @@ subshell() {
}

(subshell && r=$?) || r=$?
pkill -P $$
exit $r
Loading