Skip to content

Commit

Permalink
Sync e2e tests (madara-alliance#221)
Browse files Browse the repository at this point in the history
Co-authored-by: antiyro <74653697+antiyro@users.noreply.github.com>
  • Loading branch information
cchudant and antiyro authored Aug 26, 2024
1 parent 0c41000 commit d234a4a
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 87 deletions.
48 changes: 38 additions & 10 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,52 @@ on:

jobs:
coverage:
# sadly, for now we have to "rebuild" for the coverage
permissions:
pull-requests: write
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: Swatinem/rust-cache@v2 # use a different cache key as coverae uses custom rustc args
- uses: dtolnay/rust-toolchain@master
with:
shared-key: "cache"
save-if: false
toolchain: 1.78
- name: Setup build deps
run: |
sudo apt-get update
sudo apt-get install -y clang llvm libudev-dev protobuf-compiler
- uses: rui314/setup-mold@v1
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Coverage
run: cargo llvm-cov --codecov --output-path codecov.json
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3

- 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: |
source <(cargo llvm-cov show-env --export-prefix)
cargo build --bin deoxys --profile dev
export COVERAGE_BIN=$(realpath target/debug/deoxys)
rm -f target/madara-* lcov.info
cargo test --profile dev
- name: Generate coverage info
run: |
source <(cargo llvm-cov show-env --export-prefix)
cargo llvm-cov report --cobertura --output-path coverage.cobertura.xml
- name: Display coverage
uses: ewjoachim/coverage-comment-action@v1
with:
files: codecov.json
fail_ci_if_error: false
GITHUB_TOKEN: ${{ github.token }}
COVERAGE_FILE: coverage.cobertura.xml
11 changes: 7 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ concurrency:
group: pr-checks-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
pull-requests: write

jobs:
changelog:
name: Enforce CHANGELOG
Expand All @@ -30,7 +33,7 @@ jobs:
uses: ./.github/workflows/linters-cargo.yml
needs: rust_check

rust_test:
name: Run Cargo tests
uses: ./.github/workflows/rust-test.yml
needs: rust_check
coverage:
name: Run Coverage
uses: ./.github/workflows/coverage.yml
needs: changelog
5 changes: 0 additions & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@ jobs:
name: Run Cargo linters
uses: ./.github/workflows/linters-cargo.yml
needs: rust_check

rust_test:
name: Run Cargo tests
uses: ./.github/workflows/rust-test.yml
needs: rust_check
36 changes: 0 additions & 36 deletions .github/workflows/rust-test.yml

This file was deleted.

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

- tests: add e2e tests for the node
- fix: fixed some readme stuff
- feat: gas price provider added for block production
- feat: l1 sync service
Expand Down
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"crates/primitives/receipt",
"crates/primitives/state_update",
"crates/primitives/utils",
"crates/tests",
]
resolver = "2"
# All previous except for `starknet-rpc-test` and `starknet-e2e-test`
Expand All @@ -36,6 +37,7 @@ default-members = [
"crates/primitives/receipt",
"crates/primitives/state_update",
"crates/primitives/utils",
"crates/tests",
]

[profile.dev]
Expand Down Expand Up @@ -107,11 +109,8 @@ cairo-lang-utils = "=2.7.0-rc.2"

alloy = { version = "0.2.0", features = [
"node-bindings",
"providers",
"transport-http",
"sol-types",
"json",
"rpc-types",
"provider-http",
"contract",
] }

Expand Down
2 changes: 1 addition & 1 deletion crates/client/eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ starknet_api = { workspace = true }


# Other
alloy = { workspace = true, features = ["node-bindings"] }
alloy = { workspace = true }
anyhow = "1.0.75"
async-trait = "0.1.80"
bitvec = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/client/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod starknet_sync_worker {
use dc_telemetry::TelemetryHandle;
use dp_convert::ToFelt;
use fetch::fetchers::FetchConfig;

use starknet_providers::SequencerGatewayProvider;
use std::{sync::Arc, time::Duration};

Expand Down
4 changes: 2 additions & 2 deletions crates/node/src/cli/block_production.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Parameters used to config telemetry.
/// Parameters used to config block production.
#[derive(Clone, Debug, clap::Parser)]
pub struct BlockProductionParams {
/// Disable the block production service.
/// The block production service is only enabled with the authority (sequencer) mode.
#[arg(long, alias = "no-disabled")]
#[arg(long, alias = "no-block-production")]
pub block_production_disabled: bool,
}
1 change: 1 addition & 0 deletions crates/node/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::sync::Arc;
use url::Url;

#[derive(Clone, Debug, clap::Parser)]
/// Madara: High performance Starknet sequencer/full-node.
pub struct RunCmd {
/// The human-readable name for this node.
/// It is used as the network node name.
Expand Down
1 change: 1 addition & 0 deletions crates/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ async fn main() -> anyhow::Result<()> {
l1_gas_setter,
chain_config.chain_id.clone(),
chain_config.eth_core_contract_address,
run_cmd.authority,
)
.await
.context("Initializing the l1 sync service")?;
Expand Down
47 changes: 23 additions & 24 deletions crates/node/src/service/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl L1SyncService {
l1_gas_provider: GasPriceProvider,
chain_id: ChainId,
l1_core_address: H160,
authority: bool,
) -> anyhow::Result<Self> {
let eth_client = if !config.sync_l1_disabled {
if let Some(l1_rpc_url) = &config.l1_endpoint {
Expand All @@ -50,13 +51,13 @@ impl L1SyncService {
None
};

let gas_price_sync_disabled = config.gas_price_sync_disabled;
let gas_price_sync_enabled = authority && !config.gas_price_sync_disabled;
let gas_price_poll_ms = Duration::from_secs(config.gas_price_poll_ms);

if !gas_price_sync_disabled {
let eth_client = eth_client.clone().ok_or_else(|| {
anyhow::anyhow!("EthereumClient is required to start the l1 sync service but not provided.")
})?;
if gas_price_sync_enabled {
let eth_client = eth_client
.clone()
.context("EthereumClient is required to start the l1 sync service but not provided.")?;
// running at-least once before the block production service
dc_eth::l1_gas_price::gas_price_worker(&eth_client, l1_gas_provider.clone(), gas_price_poll_ms).await?;
}
Expand All @@ -66,7 +67,7 @@ impl L1SyncService {
eth_client,
l1_gas_provider,
chain_id,
gas_price_sync_disabled,
gas_price_sync_disabled: !gas_price_sync_enabled,
gas_price_poll_ms,
})
}
Expand All @@ -75,26 +76,24 @@ impl L1SyncService {
#[async_trait::async_trait]
impl Service for L1SyncService {
async fn start(&mut self, join_set: &mut JoinSet<anyhow::Result<()>>) -> anyhow::Result<()> {
let L1SyncService { eth_client, l1_gas_provider, chain_id, gas_price_sync_disabled, gas_price_poll_ms, .. } =
self.clone();
let L1SyncService { l1_gas_provider, chain_id, gas_price_sync_disabled, gas_price_poll_ms, .. } = self.clone();

let db_backend = Arc::clone(&self.db_backend);
if let Some(eth_client) = self.eth_client.take() {
// enabled

let eth_client = eth_client.ok_or_else(|| {
anyhow::anyhow!("EthereumClient is required to start the l1 sync service but not provided.")
})?;

join_set.spawn(async move {
dc_eth::sync::l1_sync_worker(
&db_backend,
&eth_client,
chain_id.to_felt(),
l1_gas_provider,
gas_price_sync_disabled,
gas_price_poll_ms,
)
.await
});
let db_backend = Arc::clone(&self.db_backend);
join_set.spawn(async move {
dc_eth::sync::l1_sync_worker(
&db_backend,
&eth_client,
chain_id.to_felt(),
l1_gas_provider,
gas_price_sync_disabled,
gas_price_poll_ms,
)
.await
});
}

Ok(())
}
Expand Down
21 changes: 21 additions & 0 deletions crates/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "dc-e2e-tests"
authors.workspace = true
homepage.workspace = true
edition.workspace = true
repository.workspace = true
version.workspace = true
license.workspace = true

[dependencies]

anyhow.workspace = true
env_logger.workspace = true
lazy_static.workspace = true
log.workspace = true
reqwest.workspace = true
rstest.workspace = true
starknet-core.workspace = true
starknet-providers.workspace = true
tempfile.workspace = true
tokio = { workspace = true, features = ["rt", "macros"] }
Loading

0 comments on commit d234a4a

Please sign in to comment.