Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/tests #59

Merged
merged 9 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion macro_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ url = "2.5.0"
syn = "2.0.48"
quote = "1.0.35"
tokio = { version = "1", features = ["full"] }
lazy_static = "1.4.0"
lazy_static = "1.4.0"
1 change: 1 addition & 0 deletions unit_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ macro_utils = { path = "../macro_utils/" }
rand = "0.8.5"
serde_json = "1.0"
once_cell = "1.8.0"
colored = "2.0"

[dev-dependencies]
jsonrpsee = { version = "0.21.0", features = ["client"] }
Expand Down
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";
2 changes: 1 addition & 1 deletion unit_tests/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ pub fn get_block_setting() -> BlockId {
Err(_) => BlockId::Number(100000),
},
}
}
}
122 changes: 111 additions & 11 deletions unit_tests/tests/test_block_hash_and_number.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod common;
use common::*;
use starknet_core::types::BlockHashAndNumber;

use std::collections::HashMap;

Expand All @@ -8,6 +9,8 @@ use starknet_providers::{
Provider,
};

use colored::*;

///
/// Unit test for `starknet_BlockHashAndNumber`
///
Expand All @@ -16,24 +19,121 @@ use starknet_providers::{
///
#[rstest]
#[tokio::test]
#[ignore = "Slash this ignore when Deoxys node is fully synced"]
async fn work_latest_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
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
let deoxys_responce = deoxys
.block_hash_and_number()
.await
.expect("Error waiting for response from Deoxys node");
let response_pathfinder = pathfinder
.expect("Deoxys : Error while getting the block number");
let pathfinder_responce = pathfinder
.block_hash_and_number()
.await
.expect("Error waiting for response from Deoxys node");
let response_expected = deoxys
.block_number()
.expect("RPC : Error while getting the block number");
let juno_responce = juno
.block_hash_and_number()
.await
.expect("Error waiting for response from Deoxys node");
.expect("Juno : Error while getting the block number");

assert!(deoxys_responce.block_number > 0);
assert!(pathfinder_responce.block_number > 0);
assert!(juno_responce.block_number > 0);

if !check_block_number(deoxys_responce.clone(), pathfinder_responce.clone(), juno_responce.clone()) {
println!("{}", "\nMismatch on Block numbers are skipped since it may not be an error.".green().bold());
}

if !check_block_hashes(deoxys_responce, pathfinder_responce, juno_responce) {
println!("{}", "\nMismatch on Block hashes are skipped since it may not be an error.".green().bold());
}
}

fn check_block_number(responce_deoxys: BlockHashAndNumber, responce_pathfinder: BlockHashAndNumber, responce_juno: BlockHashAndNumber) -> bool {
let deoxys_block_number = responce_deoxys.block_number;
let pathfinder_block_number = responce_pathfinder.block_number;
let juno_block_number = responce_juno.block_number;

if deoxys_block_number != pathfinder_block_number || pathfinder_block_number != juno_block_number || juno_block_number != deoxys_block_number {
println!("{}", "Block number mismatch detected\n".red().bold());
println!("Deoxys: {}", format!("{}", deoxys_block_number).cyan().bold());
println!("Pathfinder: {}", format!("{}", pathfinder_block_number).magenta().bold());
println!("Juno: {}\n", format!("{}", juno_block_number).green().bold());

if deoxys_block_number != pathfinder_block_number {
println!(
"{} {} != {}",
"Mismatch between Deoxys and Pathfinder:".red(),
deoxys_block_number.to_string().yellow().bold(),
pathfinder_block_number.to_string().yellow().bold()
);
}
if pathfinder_block_number != juno_block_number {
println!(
"{} {} != {}",
"Mismatch between Pathfinder and Juno:".red(),
pathfinder_block_number.to_string().yellow().bold(),
juno_block_number.to_string().yellow().bold()
);
}
if juno_block_number != deoxys_block_number {
println!(
"{} {} != {}",
"Mismatch between Juno and Deoxys:".red(),
juno_block_number.to_string().yellow().bold(),
deoxys_block_number.to_string().yellow().bold()
);
}

return false;
} else {
println!("{}", "All nodes have matching block numbers".green().bold());
return true;
}

}

fn check_block_hashes(responce_deoxys: BlockHashAndNumber, responce_pathfinder: BlockHashAndNumber, responce_juno: BlockHashAndNumber) -> bool {
let deoxys_block_hash = responce_deoxys.block_hash;
let pathfinder_block_hash = responce_pathfinder.block_hash;
let juno_block_hash = responce_juno.block_hash;

if deoxys_block_hash != pathfinder_block_hash || pathfinder_block_hash != juno_block_hash || juno_block_hash != deoxys_block_hash {
println!("{}", "Block hash mismatch detected\n".red().bold());
println!("Deoxys: {}", format!("0x{:x}", deoxys_block_hash).cyan().bold());
println!("Pathfinder: {}", format!("0x{:x}", pathfinder_block_hash).magenta().bold());
println!("Juno: {}\n", format!("0x{:x}", juno_block_hash).green().bold());

if deoxys_block_hash != pathfinder_block_hash {
println!(
"{} {} != {}",
"Mismatch between Deoxys and Pathfinder:".red(),
format!("0x{:x}", deoxys_block_hash).yellow().bold(),
format!("0x{:x}", pathfinder_block_hash).yellow().bold()
);
}
if pathfinder_block_hash != juno_block_hash {
println!(
"{} {} != {}",
"Mismatch between Pathfinder and Juno:".red(),
format!("0x{:x}", pathfinder_block_hash).yellow().bold(),
format!("0x{:x}", juno_block_hash).yellow().bold()
);
}
if juno_block_hash != deoxys_block_hash {
println!(
"{} {} != {}",
"Mismatch between Juno and Deoxys:".red(),
format!("0x{:x}", juno_block_hash).yellow().bold(),
format!("0x{:x}", deoxys_block_hash).yellow().bold()
);
}

return false;
} else {
println!("{}", "All nodes have matching block hashes".green().bold());
return true;
}

assert_eq!(response_deoxys.block_number, response_expected);
assert_eq!(response_deoxys, response_pathfinder);
}
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());
}
}
2 changes: 2 additions & 0 deletions unit_tests/tests/test_chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async fn chain_id(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
.await
.expect("Error while getting chain id from deoxys");

log::info!("response_deoxys: {:?}", response_deoxys);

let response_pathfinder = pathfinder
.chain_id()
.await
Expand Down
Loading
Loading