Skip to content

Commit

Permalink
Tests : e2e test (#101)
Browse files Browse the repository at this point in the history
* feat: added modules in e2e test crate

* feat : setup stage completed

* feat : added sharp env vars

* feat : updated implementation temp

* updated code and removed redundant code

* feat : e2e tests config change

* feat : updated code for state update worker

* feat : updated test

* e2e test workflow added

* feat : updated changelog.yml & updated code

* lint fixes

* feat : updated tests and fixed coverage tests

* lint fix

* tests and lint fix

* DA sorted fix

* run e2e parallel to coverage

* ignore e2e tests folder from coverage

* prettier fix

* remove --ignored

* update cargo llvm command

* remove dependency of rust_build in CI

* feat : updated code and removed debug logs

* refactor

* chore : resolved some comments

* chore : resolved some comments

* chore : resolved some comments

* feat : added feature flag and refactored the code

* lint fix

* chore : refactoring

* refactor

* chore : refactor

* updated code and fixed tests

---------

Co-authored-by: apoorvsadana <[email protected]>
  • Loading branch information
ocdbytes and apoorvsadana authored Sep 9, 2024
1 parent 764c4fa commit 369ccbe
Show file tree
Hide file tree
Showing 60 changed files with 11,325 additions and 1,353 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ SHARP_PROOF_LAYOUT=

DA_LAYER=
SETTLEMENT_LAYER=
ETHEREUM_RPC_URL=
SETTLEMENT_RPC_URL=
MADARA_RPC_URL=
MEMORY_PAGES_CONTRACT_ADDRESS=
PRIVATE_KEY=
Expand Down
9 changes: 3 additions & 6 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SQS_JOB_HANDLE_FAILURE_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.clou
SQS_WORKER_TRIGGER_QUEUE_URL="http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/madara_orchestrator_worker_trigger_queue"

##### SNS #####

ALERTS="sns"
AWS_SNS_REGION="us-east-1"
AWS_SNS_ARN="arn:aws:sns:us-east-1:000000000000:madara-orchestrator-arn"
Expand All @@ -51,7 +52,7 @@ SHARP_PROOF_LAYOUT="small"
DA_LAYER="ethereum"
SETTLEMENT_LAYER="ethereum"
SETTLEMENT_RPC_URL="https://eth-mainnet.public.blastapi.io"
MADARA_RPC_URL="http://localhost:3000"
MADARA_RPC_URL="http://localhost:5000"
L1_CORE_CONTRACT_ADDRESS="0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"
MEMORY_PAGES_CONTRACT_ADDRESS="0x47312450B3Ac8b5b8e247a6bB6d523e7605bDb60"
PRIVATE_KEY="0xdead"
Expand All @@ -60,8 +61,4 @@ STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS="0xc662c410C0ECf747543f5bA90660f6ABeBD9C
DEFAULT_L1_CORE_CONTRACT_ADDRESS="0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"
TEST_DUMMY_CONTRACT_ADDRESS="0xE5b6F5e695BA6E4aeD92B68c4CC8Df1160D69A81"
STARKNET_OPERATOR_ADDRESS="0x2C169DFe5fBbA12957Bdd0Ba47d9CEDbFE260CA7"
ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io"

##### E2E test vars #####

L2_BLOCK_NUMBER_FOR_TEST=671070
ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.public.blastapi.io"
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Run llvm-cov tests
env:
ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }}
run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --lcov --output-path lcov.info --test-threads=1
run: RUST_LOG=debug RUST_BACKTRACE=1 cargo llvm-cov nextest --release --features testing --lcov --output-path lcov.info --test-threads=1 --workspace --exclude=e2e-tests

- name: Coveralls
uses: coverallsapp/github-action@v2
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: E2E test

on:
workflow_call:

jobs:
coverage:
runs-on: ubuntu-latest

services:
localstack:
image: localstack/localstack
env:
DEFAULT_REGION: us-east-1
AWS_ACCESS_KEY_ID: "AWS_ACCESS_KEY_ID"
AWS_SECRET_ACCESS_KEY: "AWS_SECRET_ACCESS_KEY"
ports:
- 4566:4566
mongodb:
image: mongo:latest
ports:
- 27017:27017

steps:
- uses: actions/checkout@v3

# selecting a toolchain either by action or manual `rustup` calls should happen
# before the plugin, as the cache uses the current rustc version as its cache key
- run: rustup show

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Check Anvil Installation
run: |
if command -v anvil &> /dev/null
then
echo "Anvil is installed. Version information:"
anvil --version
else
echo "Anvil is not installed or not in PATH"
exit 1
fi
- name: Run e2e test
env:
ETHEREUM_BLAST_RPC_URL: ${{ secrets.ETHEREUM_BLAST_RPC_URL }}
run: |
RUST_LOG=trace cargo test --features testing test_orchestrator_workflow -- --nocapture
2 changes: 2 additions & 0 deletions .github/workflows/linters-cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ jobs:
cargo fmt -- --check
cargo clippy --no-deps -- -D warnings
cargo clippy --tests --no-deps -- -D warnings
cargo clippy --features testing --no-deps -- -D warnings
cargo clippy --features testing --tests --no-deps -- -D warnings
6 changes: 5 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ jobs:
coverage:
name: Run coverage
uses: ./.github/workflows/coverage.yml
needs: rust_build
secrets: inherit

e2e-test:
name: E2E test
uses: ./.github/workflows/e2e-test.yml
secrets: inherit
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Added

- e2e flow test
- database timestamps
- alerts module.
- Tests for Settlement client.
Expand Down
63 changes: 62 additions & 1 deletion Cargo.lock

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

17 changes: 16 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@ authors = ["Apoorv Sadana <@apoorvsadana>"]
[workspace.dependencies]
num = { version = "0.4.1" }
async-trait = { version = "0.1.77" }
alloy = { version = "0.2.1", features = ["full"] }
alloy = { version = "0.2.1", features = [
"full",
"node-bindings",
"rpc-types-debug",
"rpc-types-trace",
"json-rpc",
"rpc-client",
] }
aws-config = { version = "1.1.7", features = ["behavior-version-latest"] }
aws-sdk-s3 = { version = "1.38.0", features = ["behavior-version-latest"] }
aws-sdk-eventbridge = { version = "1.41.0", features = [
"behavior-version-latest",
] }
aws-sdk-sqs = "1.36.0"
axum = { version = "0.7.4" }
axum-macros = "0.4.1"
bincode = "1.3.3"
bytes = "1.6.0"
color-eyre = "0.6.2"
chrono = "0.4.0"
c-kzg = "1.0.0"
dotenvy = "0.15.7"
futures = "0.3.30"
log = "0.4.21"
mongodb = { version = "2.8.1", features = ["bson-chrono-0_4"] }
omniqueue = { version = "0.2.0" }
reqwest = { version = "0.12.7", features = [
Expand Down
9 changes: 5 additions & 4 deletions crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ arc-swap = { workspace = true }
assert_matches = "1.5.0"
async-std = "1.12.0"
async-trait = { workspace = true }
aws-config = { version = "1.1.7", features = ["behavior-version-latest"] }
aws-config = { workspace = true, features = ["behavior-version-latest"] }
aws-credential-types = { version = "1.2.1", features = [
"hardcoded-credentials",
] }
aws-sdk-s3 = { version = "1.38.0", features = ["behavior-version-latest"] }
aws-sdk-s3 = { workspace = true, features = ["behavior-version-latest"] }
aws-sdk-sns = { version = "1.40.0", features = ["behavior-version-latest"] }
aws-sdk-sqs = "1.36.0"
aws-sdk-sqs = { workspace = true }
axum = { workspace = true, features = ["macros"] }
axum-macros = { workspace = true }
bincode = { workspace = true }
bytes = "1.6.0"
bytes.workspace = true
c-kzg = { workspace = true }
cairo-vm = { workspace = true }
chrono = { workspace = true }
Expand Down Expand Up @@ -73,6 +73,7 @@ default = ["ethereum", "with_mongodb", "with_sqs"]
ethereum = ["ethereum-da-client"]
with_mongodb = ["mongodb"]
with_sqs = ["omniqueue"]
testing = []

[dev-dependencies]
hyper = { version = "0.14", features = ["full"] }
Expand Down
23 changes: 22 additions & 1 deletion crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#[cfg(feature = "testing")]
use alloy::primitives::Address;
#[cfg(feature = "testing")]
use alloy::providers::RootProvider;
#[cfg(feature = "testing")]
use std::str::FromStr;

use std::sync::Arc;

use crate::alerts::aws_sns::AWSSNS;
Expand Down Expand Up @@ -217,7 +224,21 @@ pub fn build_prover_service(settings_provider: &impl Settings) -> Box<dyn Prover
/// Builds the settlement client depending on the env variable SETTLEMENT_LAYER
pub async fn build_settlement_client(settings_provider: &impl Settings) -> Box<dyn SettlementClient + Send + Sync> {
match get_env_var_or_panic("SETTLEMENT_LAYER").as_str() {
"ethereum" => Box::new(EthereumSettlementClient::new_with_settings(settings_provider)),
"ethereum" => {
#[cfg(not(feature = "testing"))]
{
Box::new(EthereumSettlementClient::new_with_settings(settings_provider))
}
#[cfg(feature = "testing")]
{
Box::new(EthereumSettlementClient::with_test_settings(
RootProvider::new_http(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str().parse().unwrap()),
Address::from_str(&get_env_var_or_panic("DEFAULT_L1_CORE_CONTRACT_ADDRESS")).unwrap(),
Url::from_str(get_env_var_or_panic("SETTLEMENT_RPC_URL").as_str()).unwrap(),
Some(Address::from_str(get_env_var_or_panic("STARKNET_OPERATOR_ADDRESS").as_str()).unwrap()),
))
}
}
"starknet" => Box::new(StarknetSettlementClient::new_with_settings(settings_provider).await),
_ => panic!("Unsupported Settlement layer"),
}
Expand Down
1 change: 1 addition & 0 deletions crates/orchestrator/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub const BLOB_DATA_FILE_NAME: &str = "blob_data.txt";
pub const SNOS_OUTPUT_FILE_NAME: &str = "snos_output.json";
pub const PROGRAM_OUTPUT_FILE_NAME: &str = "program_output.txt";
1 change: 0 additions & 1 deletion crates/orchestrator/src/data_storage/aws_s3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl DataStorage for AWSS3 {
Ok(())
}

#[cfg(test)]
async fn build_test_bucket(&self, bucket_name: &str) -> Result<()> {
self.client.create_bucket().bucket(bucket_name).send().await?;
Ok(())
Expand Down
1 change: 0 additions & 1 deletion crates/orchestrator/src/data_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use utils::settings::Settings;
pub trait DataStorage: Send + Sync {
async fn get_data(&self, key: &str) -> Result<Bytes>;
async fn put_data(&self, data: Bytes, key: &str) -> Result<()>;
#[cfg(test)]
async fn build_test_bucket(&self, bucket_name: &str) -> Result<()>;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/database/mongodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl MongoDb {
let client = Client::with_options(client_options).expect("Failed to create MongoDB client");
// Ping the server to see if you can connect to the cluster
client.database("admin").run_command(doc! {"ping": 1}, None).await.expect("Failed to ping MongoDB deployment");
println!("Pinged your deployment. You successfully connected to MongoDB!");
log::debug!("Pinged your deployment. You successfully connected to MongoDB!");

Self { client }
}
Expand Down
Loading

0 comments on commit 369ccbe

Please sign in to comment.