Skip to content

Commit

Permalink
Test oracle in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiimk committed Apr 30, 2024
1 parent 3fc43f2 commit ecd021f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 51 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@ jobs:
runs-on: ubuntu-latest
env:
CARGO_FLAGS: --profile ci --features kamu/ftp
KAMU_CONTRACTS_DIR: ../../../kamu-contracts
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: kamu-data/kamu-contracts
path: kamu-contracts
token: ${{ secrets.GH_PAT }}
- uses: actions-rs/toolchain@v1
- uses: swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: build
- uses: cargo-bins/cargo-binstall@main
- name: Install cargo tools
run: |
cargo binstall cargo-nextest -y --force
- name: Install foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Build
run: cargo test ${{ env.CARGO_FLAGS }} --no-run
- name: run tests
run: cargo test ${{ env.CARGO_FLAGS }}
- name: check git diff
- name: Run tests
run: cargo nextest run
- name: Check git diff
run: git diff && git diff-index --quiet HEAD
24 changes: 0 additions & 24 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TEST_LOG_PARAMS=RUST_LOG_SPAN_EVENTS=new,close RUST_LOG=debug

###############################################################################
# Lint
Expand Down Expand Up @@ -27,7 +28,12 @@ lint-fix:

.PHONY: test
test:
cargo test
$(TEST_LOG_PARAMS) cargo nextest run


.PHONY: test-no-oracle
test-no-oracle:
$(TEST_LOG_PARAMS) cargo nextest run -E 'not test(::oracle::)'


###############################################################################
Expand Down
3 changes: 0 additions & 3 deletions src/app/oracle-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ clap = { version = "4", default-features = false, features = [
"wrap_help",
] }
chrono = { version = "0.4", default-features = false, features = ["serde"] }
dill = { version = "0.8", default-features = false }
ciborium = { version = "0.2", default-features = false }
confique = { version = "0.2", default-features = false, features = ["yaml"] }
ethers = { version = "2", default-features = false, features = [
Expand All @@ -52,8 +51,6 @@ tokio = { version = "1", default-features = false, features = [
"macros",
] }
tracing = { version = "0.1", default-features = false, features = [] }
tracing-appender = "0.2"
tracing-bunyan-formatter = "0.3"
tracing-log = "0.2"
tracing-subscriber = { version = "0.3", default-features = false, features = [
"ansi",
Expand Down
36 changes: 25 additions & 11 deletions src/app/oracle-executor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

use clap::Parser;
use kamu_oracle_executor::{Cli, Config};
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

const DEFAULT_RUST_LOG: &str = "RUST_LOG=debug,kamu=trace,hyper=info,h2=info";

fn main() {
let args = Cli::parse();
Expand All @@ -22,14 +21,7 @@ fn main() {
.load()
.unwrap();

tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_ansi(true),
)
.with(tracing_subscriber::filter::EnvFilter::from_default_env())
.init();
configure_tracing();

let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
Expand All @@ -44,3 +36,25 @@ fn main() {
}
}
}

fn configure_tracing() {
use tracing_log::LogTracer;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

let env_filter = EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new(DEFAULT_RUST_LOG));

tracing_subscriber::registry()
.with(env_filter)
.with(
tracing_subscriber::fmt::layer()
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_ansi(true),
)
.init();

// Redirect all standard logging to tracing events
LogTracer::init().expect("Failed to set LogTracer");
}
29 changes: 21 additions & 8 deletions src/app/oracle-executor/tests/tests/test_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use std::path::PathBuf;
use std::sync::Arc;

use ethers::prelude::*;
Expand All @@ -32,14 +33,26 @@ abigen!(

/////////////////////////////////////////////////////////////////////////////////////////

fn get_contracts_dir() -> PathBuf {
let dir = if let Ok(dir) = std::env::var("KAMU_CONTRACTS_DIR") {
PathBuf::from(dir)
} else {
std::fs::canonicalize(".")
.unwrap()
.join("../../../../kamu-contracts")
};
if !dir.exists() {
panic!("Contracts dir not found at {}", dir.display());
}
dir
}

/////////////////////////////////////////////////////////////////////////////////////////

#[test_group::group(e2e, oracle)]
#[test_log::test(tokio::test)]
async fn test_e2e() {
let contracts_dir = std::fs::canonicalize(".")
.unwrap()
.join("../../../../kamu-contracts");
if !contracts_dir.exists() {
panic!("Contracts dir not found at {}", contracts_dir.display());
}
let contracts_dir = get_contracts_dir();

let anvil = ethers::core::utils::Anvil::new().spawn();
let rpc_endpoint = anvil.endpoint();
Expand All @@ -56,7 +69,7 @@ async fn test_e2e() {

std::process::Command::new("forge")
.current_dir(&contracts_dir)
.args(&[
.args([
"script",
"script/Deploy.s.sol",
"--fork-url",
Expand All @@ -66,7 +79,7 @@ async fn test_e2e() {
"--broadcast",
])
.status()
.unwrap()
.expect("Failed to deploy contracts. Is foundry installed?")
.exit_ok()
.unwrap();

Expand Down

0 comments on commit ecd021f

Please sign in to comment.