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

block versions #64

Merged
merged 2 commits into from
Jun 17, 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
28 changes: 24 additions & 4 deletions unit_tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -161,7 +163,25 @@ pub const ARGENT_CONTRACT_ADDRESS: &str = "";
pub const ERR_DEOXYS: &str = "Error waiting for response from Deoxys client";
pub const ERR_PATHFINDER: &str = "Error waiting for response from Pathfinder client";

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";

///
/// 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;
pub const BLOCK_0_10_1: u64 = 6570;
pub const BLOCK_0_10_2: u64 = 12268;
pub const BLOCK_0_10_3: u64 = 16575;
pub const BLOCK_0_11_0: u64 = 28613;
pub const BLOCK_0_11_0_2: u64 = 43851;
pub const BLOCK_0_11_1: u64 = 61394;
pub const BLOCK_0_11_2: u64 = 68096;
pub const BLOCK_0_12_0: u64 = 103129;
pub const BLOCK_0_12_1: u64 = 164901;
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;
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),
},
}
}
}
76 changes: 60 additions & 16 deletions unit_tests/tests/test_block_hash_and_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,55 @@ async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTranspor
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_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!(
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -135,5 +180,4 @@ fn check_block_hashes(responce_deoxys: BlockHashAndNumber, responce_pathfinder:
println!("{}", "All nodes have matching block hashes".green().bold());
return true;
}

}
21 changes: 16 additions & 5 deletions unit_tests/tests/test_block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -41,11 +41,17 @@ async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTranspor

let mut mismatch = false;

if response_deoxys != response_pathfinder || response_pathfinder != response_juno || response_juno != response_deoxys {
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!(
"Pathfinder: {}",
format!("{}", response_pathfinder).magenta().bold()
);
println!("Juno: {}\n", format!("{}", response_juno).green().bold());

if response_deoxys != response_pathfinder {
Expand Down Expand Up @@ -77,6 +83,11 @@ async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTranspor
}

if mismatch {
println!("{}", "\nMismatch on Block numbers are skipped since it may not be an error.".green().bold());
println!(
"{}",
"\nMismatch on Block numbers are skipped since it may not be an error."
.green()
.bold()
);
}
}
6 changes: 3 additions & 3 deletions unit_tests/tests/test_get_block_transaction_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async fn work_with_block(
async fn work_with_block_1(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
juno: JsonRpcClient<HttpTransport>
juno: JsonRpcClient<HttpTransport>,
) {
work_with_block(deoxys, pathfinder, juno, 1).await;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ async fn work_with_block_1_hash(clients: HashMap<String, JsonRpcClient<HttpTrans
async fn work_with_block_5066(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
juno: JsonRpcClient<HttpTransport>
juno: JsonRpcClient<HttpTransport>,
) {
work_with_block(deoxys, pathfinder, juno, 1).await;
}
Expand All @@ -157,7 +157,7 @@ async fn work_with_block_5066(
async fn work_with_block_100_000(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
juno: JsonRpcClient<HttpTransport>
juno: JsonRpcClient<HttpTransport>,
) {
work_with_block(deoxys, pathfinder, juno, 100_000).await;
}
Expand Down
77 changes: 53 additions & 24 deletions unit_tests/tests/test_get_block_with_tx_hashes.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,16 +22,24 @@ 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::<std::collections::HashSet<_>>() {
for key in map1
.keys()
.chain(map2.keys())
.collect::<std::collections::HashSet<_>>()
{
let new_path = format!("{}/{}", path, key);
match (map1.get(key), map2.get(key)) {
(Some(v1), Some(v2)) => {
if compare_json_values(&new_path, v1, v2) {
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!(),
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -143,18 +154,28 @@ async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTranspor
};

// Convert the blocks to JSON values
let block_deoxys_json: Value = serde_json::to_value(&block_deoxys).expect("Failed to convert deoxys block to JSON");
let block_pathfinder_json: Value = serde_json::to_value(&block_pathfinder).expect("Failed to convert pathfinder block to JSON");
let block_deoxys_json: Value =
serde_json::to_value(&block_deoxys).expect("Failed to convert deoxys block to JSON");
let block_pathfinder_json: Value = serde_json::to_value(&block_pathfinder)
.expect("Failed to convert pathfinder block to JSON");

// Compare the JSON values and print differences if they don't match
if block_deoxys_json != block_pathfinder_json {
println!("{}", format!("Block does not match differences found\n").red().bold());
println!(
"{}",
format!("Block does not match differences found\n")
.red()
.bold()
);
let exception_found = compare_json_values("", &block_deoxys_json, &block_pathfinder_json);

if !exception_found {
panic!("Blocks do not match");
} else {
println!("\nMismatch skipped: {}", format!("field exception found").green().bold());
println!(
"\nMismatch skipped: {}",
format!("field exception found").green().bold()
);
}
}
}
Expand Down Expand Up @@ -226,18 +247,28 @@ async fn work_with_block(
};

// Convert the blocks to JSON values
let block_deoxys_json: Value = serde_json::to_value(&block_deoxys).expect("Failed to convert deoxys block to JSON");
let block_pathfinder_json: Value = serde_json::to_value(&block_pathfinder).expect("Failed to convert pathfinder block to JSON");
let block_deoxys_json: Value =
serde_json::to_value(&block_deoxys).expect("Failed to convert deoxys block to JSON");
let block_pathfinder_json: Value = serde_json::to_value(&block_pathfinder)
.expect("Failed to convert pathfinder block to JSON");

// Compare the JSON values and print differences if they don't match
if block_deoxys_json != block_pathfinder_json {
println!("{}", format!("Block does not match differences found\n").red().bold());
println!(
"{}",
format!("Block does not match differences found\n")
.red()
.bold()
);
let exception_found = compare_json_values("", &block_deoxys_json, &block_pathfinder_json);

if !exception_found {
panic!("Blocks do not match");
} else {
println!("\nMismatch skipped: {}", format!("field exception found").green().bold());
println!(
"\nMismatch skipped: {}",
format!("field exception found").green().bold()
);
}
}
}
Expand Down Expand Up @@ -311,16 +342,14 @@ async fn work_loop(deoxys: JsonRpcClient<HttpTransport>, 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))
Expand Down
Loading
Loading