Skip to content

Commit

Permalink
Merge pull request #34 from aurora-is-near/test-add-logging
Browse files Browse the repository at this point in the history
test: add logging
  • Loading branch information
diegofigs committed Oct 8, 2024
2 parents 52e6222 + ee3b35c commit e78f25d
Show file tree
Hide file tree
Showing 55 changed files with 184 additions and 296 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ jobs:
cp .env.example .env
source .env
export AURORA_PLUS_API_KEY=${{secrets.AURORA_PLUS_API_KEY}}
cargo test --no-fail-fast -- -Z unstable-options --format json --report-time | cargo2junit > results.xml
cargo test -- -Z unstable-options --format json --report-time 2> test.log | tee results.json
cat results.json | cargo2junit > results.xml
- name: Log
run: cat test.log

- name: Upload results
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/tests_on_schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ jobs:
cp .env.example .env
source .env
export AURORA_PLUS_API_KEY=${{secrets.AURORA_PLUS_API_KEY}}
cargo test --no-fail-fast -- -Z unstable-options --format json --report-time | cargo2junit > results.xml
cargo test -- -Z unstable-options --format json --report-time 2> test.log | tee results.json
cat results.json | cargo2junit > results.xml
- name: Log
run: cat test.log

- name: Upload results
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ Cargo.lock
.idea/
.env
relayer-test-data-generator/

# Generated artifacts from tests
results.json
results.xml
test.log
24 changes: 12 additions & 12 deletions dao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod tests {
use crate::dao::models::{get_db_connection, TestRun, TestTask};
use crate::utils::utils::{get_env_var, get_full_db_path, load_env_file};
use std::cmp::Ordering;
use tracing::{debug, Level};
use tracing_subscriber::FmtSubscriber;
// use tracing::{debug, Level};
// use tracing_subscriber::FmtSubscriber;

#[test]
fn it_loads_env_file() {
Expand Down Expand Up @@ -41,10 +41,10 @@ mod tests {
.filter_tasks_with_limit_one(task_type.clone())
.unwrap();
assert_eq!(task.task_type, task_type);
debug!(
"{}, {}, {}, {}, {}",
task.db_id, task.task_type, task.parameters, task.begin, task.end
);
// debug!(
// "{}, {}, {}, {}, {}",
// task.db_id, task.task_type, task.parameters, task.begin, task.end
// );
let data_contents: Vec<String> = task
.get_test_data_content_array("receipt".to_string())
.unwrap();
Expand All @@ -71,15 +71,15 @@ mod tests {
.get_test_data_content_array("receipt".to_string())
.unwrap();
let number_of_data_contents = data_contents.len();
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::TRACE)
.finish();
tracing::subscriber::set_global_default(subscriber)
.expect("setting default subscriber failed");
// let subscriber = FmtSubscriber::builder()
// .with_max_level(Level::TRACE)
// .finish();
// tracing::subscriber::set_global_default(subscriber)
// .expect("setting default subscriber failed");
// debug!("{}", data_contents[0]);
let receipts = TransactionReceipt::load(data_contents).unwrap();
// debug!("{:?}", receipts[0].events[0].args);
debug!("Number of receipts: {:?}", receipts.len());
// debug!("Number of receipts: {:?}", receipts.len());
let number_of_receipts = receipts.len();
let result = number_of_receipts.cmp(&0);
assert_eq!(Ordering::Greater, result);
Expand Down
4 changes: 4 additions & 0 deletions dao/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod utils {

const MAINNET_AURORA_CHAIN_ID: i64 = 1313161554;
const TESTNET_AURORA_CHAIN_ID: i64 = 1313161555;
const SEPOLIA_CHAIN_ID: i64 = 11155111;
const ROPSTEN_CHAIN_ID: i64 = 3;
const GOERLI_CHAIN_ID: i64 = 5;

Expand Down Expand Up @@ -32,6 +33,7 @@ pub mod utils {

pub fn get_chain_id(network_name: &str) -> Option<i64> {
match network_name {
"sepolia" => Some(SEPOLIA_CHAIN_ID),
"ropsten" => Some(ROPSTEN_CHAIN_ID),
"goerli" => Some(GOERLI_CHAIN_ID),
"testnet_aurora_plus" => Some(TESTNET_AURORA_CHAIN_ID),
Expand All @@ -48,6 +50,7 @@ pub mod utils {
pub fn get_client_version(network_name: &str) -> Option<String> {
static AURORA_WEB3_CLIENT_VERSION: &str = "Aurora";
match network_name {
"sepolia" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"ropsten" => Some("erigon/2022.99.99/linux-amd64/go1.18.3".to_string()), // https://rpc.ankr.com/eth_ropsten
"goerli" => Some("Geth/v1.10.23-omnibus-b38477ec/linux-amd64/go1.18.5".to_string()), // infura
"testnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
Expand All @@ -63,6 +66,7 @@ pub mod utils {

pub fn get_protocol_version(network: &str) -> Option<i32> {
match network {
"sepolia" => Some(65),
"ropsten" => Some(0), // this one is unknown!
"goerli" => Some(65),
"testnet_aurora_plus" => Some(65), // 0x41
Expand Down
2 changes: 1 addition & 1 deletion dynamic_apis_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dao = { path = "../dao", default-features = false}
dao = { path = "../dao", default-features = false }
anyhow.workspace = true
jsonrpsee-http-client.workspace = true
jsonrpsee-ws-client.workspace = true
Expand Down
11 changes: 11 additions & 0 deletions dynamic_apis_tests/tests/it/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use tracing::subscriber::DefaultGuard;

pub fn init() -> DefaultGuard {
// Build a subscriber with the non-blocking file appender
let subscriber = tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// .with_writer(non_blocking)
.with_writer(std::io::stderr)
.finish();
tracing::subscriber::set_default(subscriber)
}
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use jsonrpsee_core::client::ClientT;
use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_accounts() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
let configs = Configs::load().unwrap();
let params = rpc_params![];
let client = http_client::HttpClientBuilder::default().build(configs.rpc_url)?;
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use std::cmp::Ordering;
use std::i64;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_block_number() -> anyhow::Result<()> {
let _guard = init();
let configs = Configs::load().unwrap();
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
let task: TestTask = test_run
Expand All @@ -22,10 +23,6 @@ async fn test_eth_block_number() -> anyhow::Result<()> {
.unwrap();
let receipts = TransactionReceipt::load(data_contents).unwrap();
let client = http_client::HttpClientBuilder::default().build(configs.rpc_url)?;
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
for i in 0..receipts.len() {
let params = rpc_params![];
let response: Result<String, _> = client.request("eth_blockNumber", params).await;
Expand Down
14 changes: 4 additions & 10 deletions dynamic_apis_tests/tests/it/eth_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use jsonrpsee_core::client::ClientT;
use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use serde::{Deserialize, Serialize};
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -22,10 +22,7 @@ impl MessageCallParams {

#[tokio::test]
async fn test_eth_call() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
let configs = Configs::load().unwrap();
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
let task: TestTask = test_run
Expand All @@ -49,10 +46,7 @@ async fn test_eth_call() -> anyhow::Result<()> {

#[tokio::test]
async fn test_eth_call_eoa() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
info!("calling precompile SHA256 from EOA");
let configs = Configs::load().unwrap();
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use std::cmp::Ordering;
use std::i64;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_chain_id() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
let configs = Configs::load().unwrap();
let client = http_client::HttpClientBuilder::default().build(configs.rpc_url)?;
let params = rpc_params![];
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_coinbase.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use jsonrpsee_core::client::ClientT;
use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_coinbase() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
let configs = Configs::load().unwrap();
let params = rpc_params![];
let client = http_client::HttpClientBuilder::default().build(configs.rpc_url.clone())?;
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_estimate_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use jsonrpsee_http_client as http_client;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::i64;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -29,10 +29,7 @@ impl MessageCallParams {

#[tokio::test]
async fn test_eth_estimate_gas() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
let configs = Configs::load().unwrap();
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
let task: TestTask = test_run
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use std::cmp::Ordering;
use std::i64;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

use crate::utils::hex_string_to_i64;

#[tokio::test]
async fn test_eth_gas_price() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
let configs = Configs::load().unwrap();
let client_aurora_plus = http_client::HttpClientBuilder::default().build(configs.rpc_url)?;
let aurora_rpc_url = format!("{}", get_env_var(&"RPC_URL".to_string()).unwrap());
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_get_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ use jsonrpsee_core::client::ClientT;
use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use std::i64;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_get_balance() -> anyhow::Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let _guard = init();
let configs = Configs::load().unwrap();
let client = http_client::HttpClientBuilder::default().build(configs.rpc_url)?;
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_get_block_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ use dao::dao::models::{TestRun, TestTask};
use jsonrpsee_core::client::ClientT;
use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_get_block_by_hash() -> anyhow::Result<()> {
let _guard = init();
let configs = Configs::load().unwrap();
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
let task: TestTask = test_run
.filter_tasks_with_limit_one("transferNtimes".to_string())
Expand Down
9 changes: 3 additions & 6 deletions dynamic_apis_tests/tests/it/eth_get_block_by_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ use dao::dao::models::{TestRun, TestTask};
use jsonrpsee_core::client::ClientT;
use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_get_block_by_number() -> anyhow::Result<()> {
let _guard = init();
let configs = Configs::load().unwrap();
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
let task: TestTask = test_run
.filter_tasks_with_limit_one("transferNtimes".to_string())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ use jsonrpsee_core::rpc_params;
use jsonrpsee_http_client as http_client;
use std::cmp::Ordering;
use std::i64;
use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
use tracing::info;

use crate::common::init;
use crate::configs::Configs;

#[tokio::test]
async fn test_eth_get_block_transaction_count_by_hash() -> anyhow::Result<()> {
let _guard = init();
let configs = Configs::load().unwrap();
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
let _ = tracing::subscriber::set_global_default(subscriber);
let test_run = TestRun::new(&configs.conn, configs.network).unwrap();
let task: TestTask = test_run
.filter_tasks_with_limit_one("transferNtimes".to_string())
Expand Down
Loading

0 comments on commit e78f25d

Please sign in to comment.