diff --git a/unit_tests/src/constants.rs b/unit_tests/src/constants.rs index 5d9d926..6f03bc2 100644 --- a/unit_tests/src/constants.rs +++ b/unit_tests/src/constants.rs @@ -163,3 +163,4 @@ pub const ERR_PATHFINDER: &str = "Error waiting for response from Pathfinder cli pub const SPEC_0_5_1: &str = "0.5.1"; pub const SPEC_0_6_0: &str = "0.6.0"; pub const SPEC_0_7_0: &str = "0.7.0"; +pub const SPEC_0_7_1: &str = "0.7.1"; diff --git a/unit_tests/tests/test_block_number.rs b/unit_tests/tests/test_block_number.rs index 83bb81e..54977e0 100644 --- a/unit_tests/tests/test_block_number.rs +++ b/unit_tests/tests/test_block_number.rs @@ -7,6 +7,7 @@ use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, }; +use colored::*; // Add this import for colored output /// /// Unit test for `starknet_blockNumber` @@ -16,10 +17,10 @@ use starknet_providers::{ /// #[rstest] #[tokio::test] -// #[ignore = "Slash this ignore when Deoxys node is fully synced"] async fn work_existing_block(clients: HashMap>) { let deoxys = &clients[DEOXYS]; let pathfinder = &clients[PATHFINDER]; + let juno = &clients[JUNO]; let response_deoxys = deoxys .block_number() @@ -29,7 +30,53 @@ async fn work_existing_block(clients: HashMap 0); - assert_eq!(response_deoxys, response_pathfinder); + assert!(response_pathfinder > 0); + assert!(response_juno > 0); + + let mut mismatch = false; + + if response_deoxys != response_pathfinder || response_pathfinder != response_juno || response_juno != response_deoxys { + mismatch = true; + println!("{}", "Block number mismatch detected\n".red().bold()); + println!("Deoxys: {}", format!("{}", response_deoxys).cyan().bold()); + println!("Pathfinder: {}", format!("{}", response_pathfinder).magenta().bold()); + println!("Juno: {}\n", format!("{}", response_juno).green().bold()); + + if response_deoxys != response_pathfinder { + println!( + "{} {} != {}", + "Mismatch between Deoxys and Pathfinder:".red(), + response_deoxys.to_string().yellow().bold(), + response_pathfinder.to_string().yellow().bold() + ); + } + if response_pathfinder != response_juno { + println!( + "{} {} != {}", + "Mismatch between Pathfinder and Juno:".red(), + response_pathfinder.to_string().yellow().bold(), + response_juno.to_string().yellow().bold() + ); + } + if response_juno != response_deoxys { + println!( + "{} {} != {}", + "Mismatch between Juno and Deoxys:".red(), + response_juno.to_string().yellow().bold(), + response_deoxys.to_string().yellow().bold() + ); + } + } else { + println!("{}", "All nodes have matching block numbers".green().bold()); + } + + if mismatch { + println!("{}", "\nMismatch on Block numbers are skipped since it may not be an error.".green().bold()); + } } diff --git a/unit_tests/tests/test_specversion.rs b/unit_tests/tests/test_specversion.rs index c60aa8a..24007a2 100644 --- a/unit_tests/tests/test_specversion.rs +++ b/unit_tests/tests/test_specversion.rs @@ -1,21 +1,41 @@ #![feature(assert_matches)] mod common; +use std::collections::HashMap; + use common::*; use starknet_providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider}; +use colored::*; /// /// Unit test for `starknet_specversion` /// -/// purpose: retrieve the Deoxys node spec version -/// success case: spec version should be 0.7.0 +/// Purpose: Retrieve the Deoxys node spec version +/// Success case: Spec version should be 0.7.1 /// #[rstest] #[tokio::test] -#[logging] -async fn test_specversion(deoxys: JsonRpcClient) { - let response_deoxys = deoxys.spec_version().await.expect(ERR_DEOXYS); +async fn test_spec_version_7_1(clients: HashMap>) { + let deoxys = &clients[DEOXYS]; + let pathfinder = &clients[PATHFINDER]; + let juno = &clients[JUNO]; + + let response_deoxys = deoxys + .spec_version() + .await + .expect("Deoxys: Error while getting the block number"); + let response_pathfinder = pathfinder + .spec_version() + .await + .expect("RPC: Error while getting the block number"); + let response_juno = juno + .spec_version() + .await + .expect("Juno: Error while getting the block number"); + + assert_eq!(response_deoxys, SPEC_0_7_1, "Deoxys spec version mismatch"); + assert_eq!(response_pathfinder, SPEC_0_7_0, "Pathfinder spec version mismatch"); + assert_eq!(response_juno, SPEC_0_7_1, "Juno spec version mismatch"); - log::info!("Deoxys RPC spec: {}", response_deoxys); - assert_eq!(response_deoxys, SPEC_0_7_0); + println!("{}", format!("All clients returned the same spec version: 0.7.1").green()); } diff --git a/unit_tests/tests/test_syncing.rs b/unit_tests/tests/test_syncing.rs index 3fab296..39da1fb 100644 --- a/unit_tests/tests/test_syncing.rs +++ b/unit_tests/tests/test_syncing.rs @@ -45,9 +45,9 @@ fn assert_sync_status(a: SyncStatusType, b: SyncStatusType, c: SyncStatusType) { if !ab_sync_status_match || !bc_sync_status_match || !ca_sync_status_match { println!("{}", "Sync status mismatch detected\n".red().bold()); - println!("Deoxys: {}", format!("{:?}\n", a).cyan().bold()); - println!("Pathfinder: {}", format!("{:?}\n", b).magenta().bold()); - println!("Juno: {}", format!("{:?}\n", c).green().bold()); + println!("- Deoxys: {}", format!("{:?}", a).cyan().bold()); + println!("- Pathfinder: {}", format!("{:?}", b).magenta().bold()); + println!("- Juno: {}\n", format!("{:?}", c).green().bold()); let nodes = vec![("Deoxys", &a), ("Pathfinder", &b), ("Juno", &c)]; for i in 0..nodes.len() { @@ -59,20 +59,22 @@ fn assert_sync_status(a: SyncStatusType, b: SyncStatusType, c: SyncStatusType) { (SyncStatusType::Syncing(sync1), SyncStatusType::Syncing(sync2)) => { if sync1.current_block_num != sync2.current_block_num { println!( - "{}: {} {} != {}", - "Current block number mismatch:".red(), + "{}: {} {} != {} {}", + "Current block number mismatch".red(), name1, sync1.current_block_num.to_string().yellow().bold(), - sync2.current_block_num.to_string().yellow().bold() + sync2.current_block_num.to_string().yellow().bold(), + name2 ); } if sync1.current_block_hash != sync2.current_block_hash { println!( - "{}: {} {} != {}", + "{}: {} {} != {} {}", "Current block hash mismatch:".red(), name1, format!("0x{:x}", sync1.current_block_hash).yellow().bold(), - format!("0x{:x}", sync2.current_block_hash).yellow().bold() + format!("0x{:x}", sync2.current_block_hash).yellow().bold(), + name2 ); } if sync1.highest_block_num != sync2.highest_block_num { @@ -86,25 +88,26 @@ fn assert_sync_status(a: SyncStatusType, b: SyncStatusType, c: SyncStatusType) { } if sync1.highest_block_hash != sync2.highest_block_hash { println!( - "{}: {} {} != {}", + "{}: {} {} != {} {}", "Highest block hash mismatch:".red(), name1, format!("0x{:x}", sync1.highest_block_hash).yellow().bold(), - format!("0x{:x}", sync2.highest_block_hash).yellow().bold() + format!("0x{:x}", sync2.highest_block_hash).yellow().bold(), + name2 ); } if sync1.current_block_num != sync2.current_block_num { - println!("{}", "\nMismatch skipped since both nodes do not have the same height".green().bold()); + println!("Mismatch skipped: {}", "Nodes are not on the same height".green().bold()); } }, (SyncStatusType::Syncing(_), SyncStatusType::NotSyncing) => { - println!("{}", format!("\nMismatch skipped since {} is not syncing.", name2).green().bold()); + println!("Mismatch skipped: {}", format!("Node {} is not syncing.", name2).green().bold()); }, (SyncStatusType::NotSyncing, SyncStatusType::Syncing(_)) => { - println!("{}", format!("\nMismatch skipped since {} is not syncing.", name1).green().bold()); + println!("Mismatch skipped: {}", format!("Node {} is not syncing.", name1).green().bold()); }, _ => { - panic!("{}", "\nstarknet_syncing mismatch detected".red().bold()); + panic!("Mismatch skipped: {}", "starknet_syncing mismatch detected".red().bold()); } } }