diff --git a/unit_tests/src/constants.rs b/unit_tests/src/constants.rs index 43d5dd6..3cdedcc 100644 --- a/unit_tests/src/constants.rs +++ b/unit_tests/src/constants.rs @@ -142,8 +142,10 @@ pub const TRANSACTION_REVERTED: &str = pub const ACCOUNT_CONTRACT: &str = ""; pub const TEST_CONTRACT_ADDRESS: &str = ""; pub const CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH: &str = ""; -pub const TEST_CONTRACT_CLASS_HASH_V0: &str = "0x036e5b6081df2174189fb83800d2a09132286dcd1004ad960a0c8d69364e6e9a"; -pub const TEST_CONTRACT_CLASS_HASH_V1: &str = "0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003"; +pub const TEST_CONTRACT_CLASS_HASH_V0: &str = + "0x036e5b6081df2174189fb83800d2a09132286dcd1004ad960a0c8d69364e6e9a"; +pub const TEST_CONTRACT_CLASS_HASH_V1: &str = + "0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003"; /// /// Value to be used as a payload for a message in the `estimate_message_fee` test. @@ -166,7 +168,7 @@ pub const SPEC_0_7_1: &str = "0.7.1"; /// /// Starknet block number versions. -/// +/// pub const BLOCK_0: u64 = 0; pub const BLOCK_0_9_1: u64 = 3799; pub const BLOCK_0_10_0: u64 = 4883; @@ -183,5 +185,3 @@ pub const BLOCK_0_12_2: u64 = 194410; pub const BLOCK_0_12_3: u64 = 472644; pub const BLOCK_0_13_0: u64 = 501514; pub const BLOCK_0_13_1: u64 = 607878; - - diff --git a/unit_tests/tests/common.rs b/unit_tests/tests/common.rs index 8c90218..ebed895 100644 --- a/unit_tests/tests/common.rs +++ b/unit_tests/tests/common.rs @@ -50,4 +50,4 @@ pub fn get_block_setting() -> BlockId { Err(_) => BlockId::Number(100000), }, } -} \ No newline at end of file +} diff --git a/unit_tests/tests/test_block_hash_and_number.rs b/unit_tests/tests/test_block_hash_and_number.rs index cd91544..591634d 100644 --- a/unit_tests/tests/test_block_hash_and_number.rs +++ b/unit_tests/tests/test_block_hash_and_number.rs @@ -41,25 +41,55 @@ async fn work_existing_block(clients: HashMap 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_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()); + 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 { +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 { + 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()); + 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!( @@ -91,19 +121,34 @@ fn check_block_number(responce_deoxys: BlockHashAndNumber, responce_pathfinder: 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 { +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 { + 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()); + 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!( @@ -135,5 +180,4 @@ fn check_block_hashes(responce_deoxys: BlockHashAndNumber, responce_pathfinder: println!("{}", "All nodes have matching block hashes".green().bold()); return true; } - } diff --git a/unit_tests/tests/test_block_number.rs b/unit_tests/tests/test_block_number.rs index 54977e0..92f671b 100644 --- a/unit_tests/tests/test_block_number.rs +++ b/unit_tests/tests/test_block_number.rs @@ -3,11 +3,11 @@ use common::*; use std::collections::HashMap; +use colored::*; use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, -}; -use colored::*; // Add this import for colored output +}; // Add this import for colored output /// /// Unit test for `starknet_blockNumber` @@ -41,11 +41,17 @@ async fn work_existing_block(clients: HashMap, pathfinder: JsonRpcClient, - juno: JsonRpcClient + juno: JsonRpcClient, ) { work_with_block(deoxys, pathfinder, juno, 1).await; } @@ -147,7 +147,7 @@ async fn work_with_block_1_hash(clients: HashMap, pathfinder: JsonRpcClient, - juno: JsonRpcClient + juno: JsonRpcClient, ) { work_with_block(deoxys, pathfinder, juno, 1).await; } @@ -157,7 +157,7 @@ async fn work_with_block_5066( async fn work_with_block_100_000( deoxys: JsonRpcClient, pathfinder: JsonRpcClient, - juno: JsonRpcClient + juno: JsonRpcClient, ) { work_with_block(deoxys, pathfinder, juno, 100_000).await; } diff --git a/unit_tests/tests/test_get_block_with_tx_hashes.rs b/unit_tests/tests/test_get_block_with_tx_hashes.rs index f316810..8a76c3c 100644 --- a/unit_tests/tests/test_get_block_with_tx_hashes.rs +++ b/unit_tests/tests/test_get_block_with_tx_hashes.rs @@ -1,19 +1,19 @@ #![feature(assert_matches)] mod common; -use common::*; use colored::*; +use common::*; use starknet_core::types::MaybePendingBlockWithTxHashes; use std::collections::HashMap; use std::sync::Arc; +use serde_json::Value; use starknet_core::types::{BlockId, BlockTag, FieldElement, StarknetError}; use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, }; -use serde_json::Value; use unit_tests::constants::DEOXYS; // Define a recursive function to compare JSON values and print differences @@ -22,7 +22,11 @@ fn compare_json_values(path: &str, value1: &Value, value2: &Value) -> bool { match (value1, value2) { (Value::Object(map1), Value::Object(map2)) => { - for key in map1.keys().chain(map2.keys()).collect::>() { + for key in map1 + .keys() + .chain(map2.keys()) + .collect::>() + { let new_path = format!("{}/{}", path, key); match (map1.get(key), map2.get(key)) { (Some(v1), Some(v2)) => { @@ -30,8 +34,12 @@ fn compare_json_values(path: &str, value1: &Value, value2: &Value) -> bool { exception_found = true; } } - (Some(v1), None) => println!("{}: present in first, absent in second", new_path), - (None, Some(v2)) => println!("{}: absent in first, present in second", new_path), + (Some(v1), None) => { + println!("{}: present in first, absent in second", new_path) + } + (None, Some(v2)) => { + println!("{}: absent in first, present in second", new_path) + } (None, None) => unreachable!(), } } @@ -57,11 +65,14 @@ fn compare_json_values(path: &str, value1: &Value, value2: &Value) -> bool { if value1 != value2 { let exception_paths = [ "/l1_data_gas_price/price_in_fri", - "/l1_data_gas_price/price_in_wei" + "/l1_data_gas_price/price_in_wei", ]; if exception_paths.contains(&path) { - println!("{} - Bypassed as exception", format!("{}: {:?} != {:?}", path, value1, value2).yellow()); + println!( + "{} - Bypassed as exception", + format!("{}: {:?} != {:?}", path, value1, value2).yellow() + ); exception_found = true; } else { println!("{}: {:?} != {:?}", path, value1, value2); @@ -143,18 +154,28 @@ async fn work_existing_block(clients: HashMap, pathfinder: JsonRpcClie // Convert the blocks to JSON values let block_deoxys_json: Value = serde_json::to_value(&response_deoxys) .expect("Failed to convert deoxys block to JSON"); - let block_pathfinder_json: Value = serde_json::to_value(&response_pathfinder) - .expect("Failed to convert pathfinder block to JSON"); + let block_pathfinder_json: Value = + serde_json::to_value(&response_pathfinder) + .expect("Failed to convert pathfinder block to JSON"); // Compare the JSON values and print differences println!("Blocks for block {} do not match. Differences:", block_id); - let exception_found = compare_json_values( - "", - &block_deoxys_json, - &block_pathfinder_json, - ); + let exception_found = + compare_json_values("", &block_deoxys_json, &block_pathfinder_json); if !exception_found { Err(format!("block {}", block_id)) diff --git a/unit_tests/tests/test_get_class.rs b/unit_tests/tests/test_get_class.rs index 7fb4ec6..f3621dd 100644 --- a/unit_tests/tests/test_get_class.rs +++ b/unit_tests/tests/test_get_class.rs @@ -11,11 +11,13 @@ use std::collections::HashMap; #[rstest] #[tokio::test] -async fn fail_non_existing_block(clients: HashMap>) -> Result<()> { +async fn fail_non_existing_block( + clients: HashMap>, +) -> Result<()> { let deoxys = &clients[DEOXYS]; - let test_contract_class_hash = - FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0).map_err(|e| anyhow!("Invalid Contract Class Hash: {}", e))?; + let test_contract_class_hash = FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0) + .map_err(|e| anyhow!("Invalid Contract Class Hash: {}", e))?; let block_id = BlockId::Number(800000); match deoxys.get_class(block_id, test_contract_class_hash).await { @@ -26,7 +28,7 @@ async fn fail_non_existing_block(clients: HashMap panic!("Unexpected success: Class was found when it shouldn't be."), } } @@ -69,8 +71,8 @@ async fn work_ok_retrieving_class_for_contract_version_0( let deoxys = &clients[DEOXYS]; let pathfinder = &clients[PATHFINDER]; - let test_contract_class_hash = - FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0).expect("Invalid Contract Class Hash"); + let test_contract_class_hash = FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0) + .expect("Invalid Contract Class Hash"); let deoxys_class = deoxys .get_class(BlockId::Number(50000), test_contract_class_hash) @@ -82,13 +84,20 @@ async fn work_ok_retrieving_class_for_contract_version_0( .await .unwrap(); - if let (ContractClass::Legacy(deoxys_legacy), ContractClass::Legacy(pathfinder_legacy)) = (deoxys_class, pathfinder_class) { - assert_eq!(deoxys_legacy.entry_points_by_type, pathfinder_legacy.entry_points_by_type); + if let (ContractClass::Legacy(deoxys_legacy), ContractClass::Legacy(pathfinder_legacy)) = + (deoxys_class, pathfinder_class) + { + assert_eq!( + deoxys_legacy.entry_points_by_type, + pathfinder_legacy.entry_points_by_type + ); assert_eq!(deoxys_legacy.abi, pathfinder_legacy.abi); - - let deoxys_program = decode(&deoxys_legacy.program).expect("Failed to decode base64 program"); - let pathfinder_program = decode(&pathfinder_legacy.program).expect("Failed to decode base64 program"); - + + let deoxys_program = + decode(&deoxys_legacy.program).expect("Failed to decode base64 program"); + let pathfinder_program = + decode(&pathfinder_legacy.program).expect("Failed to decode base64 program"); + assert_eq!(deoxys_program, pathfinder_program); } else { panic!("Contract classes are not of the Legacy variant"); diff --git a/unit_tests/tests/test_get_state_update.rs b/unit_tests/tests/test_get_state_update.rs index cd46deb..896af27 100644 --- a/unit_tests/tests/test_get_state_update.rs +++ b/unit_tests/tests/test_get_state_update.rs @@ -3,7 +3,9 @@ mod common; use common::*; -use starknet_core::types::{BlockId, BlockTag, MaybePendingStateUpdate, StarknetError, StateUpdate}; +use starknet_core::types::{ + BlockId, BlockTag, MaybePendingStateUpdate, StarknetError, StateUpdate, +}; use starknet_providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider}; use std::collections::HashMap; @@ -27,7 +29,9 @@ pub fn sort_state_update(state_update: StateUpdate) -> StateUpdate { state_diff.deprecated_declared_classes.sort(); state_diff.declared_classes.sort_by_key(|x| x.class_hash); state_diff.deployed_contracts.sort_by_key(|x| x.address); - state_diff.replaced_classes.sort_by_key(|x| x.contract_address); + state_diff + .replaced_classes + .sort_by_key(|x| x.contract_address); state_diff.nonces.sort_by_key(|x| x.contract_address); sorted_state_update @@ -93,9 +97,18 @@ async fn work_genesis_block(clients: HashMap let sorted_pathfinder = extract_and_sort_state_update(response_pathfinder); let sorted_juno = extract_and_sort_state_update(response_juno); - assert_eq!(sorted_deoxys, sorted_pathfinder, "The sorted responses do not match"); - assert_eq!(sorted_deoxys, sorted_juno, "The sorted responses do not match"); - assert_eq!(sorted_juno, sorted_pathfinder, "The sorted responses do not match"); + assert_eq!( + sorted_deoxys, sorted_pathfinder, + "The sorted responses do not match" + ); + assert_eq!( + sorted_deoxys, sorted_juno, + "The sorted responses do not match" + ); + assert_eq!( + sorted_juno, sorted_pathfinder, + "The sorted responses do not match" + ); } diff --git a/unit_tests/tests/test_spec_version.rs b/unit_tests/tests/test_spec_version.rs index cb07e43..cf0f603 100644 --- a/unit_tests/tests/test_spec_version.rs +++ b/unit_tests/tests/test_spec_version.rs @@ -3,9 +3,9 @@ mod common; use std::collections::HashMap; +use colored::*; use common::*; use starknet_providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider}; -use colored::*; /// /// Unit test for `starknet_specversion` @@ -34,8 +34,14 @@ async fn test_spec_version_7_1(clients: HashMap { - println!("Mismatch skipped: {}", format!("Node {} is not syncing.", name2).green().bold()); - }, + println!( + "Mismatch skipped: {}", + format!("Node {} is not syncing.", name2).green().bold() + ); + } (SyncStatusType::NotSyncing, SyncStatusType::Syncing(_)) => { - println!("Mismatch skipped: {}", format!("Node {} is not syncing.", name1).green().bold()); - }, + println!( + "Mismatch skipped: {}", + format!("Node {} is not syncing.", name1).green().bold() + ); + } _ => { - panic!("Mismatch detected: {}", "starknet_syncing mismatch".red().bold()); + panic!( + "Mismatch detected: {}", + "starknet_syncing mismatch".red().bold() + ); } } }