Skip to content

Commit

Permalink
Merge pull request #60 from KasarLabs/fix/tests
Browse files Browse the repository at this point in the history
fix/tests
  • Loading branch information
antiyro authored Jun 17, 2024
2 parents 84d0740 + b432cf9 commit 899468c
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 95 deletions.
14 changes: 7 additions & 7 deletions unit_tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ pub const STARKGATE_ETHER: &str =
/// Details concerning this contract can be found on [StarkScan](https://starkscan.co/contract/0x07fa9a8eacb89fb6cd0c7fe557e71c42a4b181ba328a9a04958136e6469c4e00)
///
pub const CONTRACT_ERC721: &str =
"0x07fa9a8eacb89fb6cd0c7fe557e71c42a4b181ba328a9a04958136e6469c4e00";
"0x05dbdedc203e92749e2e746e2d40a768d966bd243df04a6b712e222bc040a9af";

///
/// Random ERC20 Starknet contract address.
///
/// Details concerning this contract can be found on [StarkScan](https://starkscan.co/contract/0x04a5fdce70877b77f03aea8a29259176f88d5bea9d0ad8c0118f5316425e6ba0)
///
pub const CONTRACT_ERC20: &str =
"0x04a5fdce70877b77f03aea8a29259176f88d5bea9d0ad8c0118f5316425e6ba0";
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";

///
/// Random ACCOUNT Starknet contract address.
///
/// Details concerning this contract can be found on [StarkScan](https://starkscan.co/contract/0x05e1eee30e79b4f592f444132526b2e2c7f505698e888c659e5f5def5a458c1a)
///
pub const CONTRACT_ACCOUNT: &str =
"0x05e1eee30e79b4f592f444132526b2e2c7f505698e888c659e5f5def5a458c1a";
pub const CONTRACT_ACCOUNT_CAIRO_ZERO: &str =
"0x0100104681e789e4211fba898262e1d6f6191bee797ce38a9e07fe8dec743574";

///
/// Random PROXY ACCOUNT Starknet contract address.
///
/// Details concerning this contract can be found on [StarkScan](https://starkscan.co/contract/0x05d7f4d55795b56ceb4dd93febe17954c7cfd5e15d7a79cb0cec067a713ac159)
///
pub const CONTRACT_ACCOUNT_PROXY: &str =
"0x05d7f4d55795b56ceb4dd93febe17954c7cfd5e15d7a79cb0cec067a713ac159";
pub const CONTRACT_ACCOUNT_PROXY_CAIRO_ZERO: &str =
"0x036Ef6410243034cE315eC19E7ABFEB41052f39095EE3D5AFcC20D672b1C725F";

///
/// Random legacy account using Cairo v0
Expand Down Expand Up @@ -142,7 +142,7 @@ 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: &str = "";
pub const TEST_CONTRACT_CLASS_HASH: &str = "0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003";

///
/// Value to be used as a payload for a message in the `estimate_message_fee` test.
Expand Down
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
Loading

0 comments on commit 899468c

Please sign in to comment.