Skip to content

Commit

Permalink
added pathfinder spec version test
Browse files Browse the repository at this point in the history
  • Loading branch information
antiyro committed May 23, 2024
1 parent b808a0e commit e17a9a8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 23 deletions.
1 change: 1 addition & 0 deletions unit_tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
51 changes: 49 additions & 2 deletions unit_tests/tests/test_block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider,
};
use colored::*; // Add this import for colored output

///
/// Unit test for `starknet_blockNumber`
Expand All @@ -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<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let juno = &clients[JUNO];

let response_deoxys = deoxys
.block_number()
Expand All @@ -29,7 +30,53 @@ async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTranspor
.block_number()
.await
.expect("RPC : Error while getting the block number");
let response_juno = juno
.block_number()
.await
.expect("Juno : Error while getting the block number");

assert!(response_deoxys > 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());
}
}
34 changes: 27 additions & 7 deletions unit_tests/tests/test_specversion.rs
Original file line number Diff line number Diff line change
@@ -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<HttpTransport>) {
let response_deoxys = deoxys.spec_version().await.expect(ERR_DEOXYS);
async fn test_spec_version_7_1(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
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());
}
31 changes: 17 additions & 14 deletions unit_tests/tests/test_syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand All @@ -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());
}
}
}
Expand Down

0 comments on commit e17a9a8

Please sign in to comment.