diff --git a/ditto.txt b/ditto.txt new file mode 100644 index 0000000..1988f48 --- /dev/null +++ b/ditto.txt @@ -0,0 +1,27 @@ +⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪⬛⬛🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛🟪🟪🟪🟪⬛🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪⬛⬛🟪🟪🟪🟪🟪⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛ +⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛ +⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛ +⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛ +⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛ +⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛ +⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛ +⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛ +⬛⬛⬛⬛🟪🟪🟪⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛🟪🟪🟪🟪🟪⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ \ No newline at end of file diff --git a/run_Ditto.sh b/run_Ditto.sh new file mode 100644 index 0000000..bc539df --- /dev/null +++ b/run_Ditto.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +test_files=($(basename -a $(find unit_tests/tests -type f -name "*.rs" ! -name "common.rs"))) + +cat art.txt + +echo "\n" +echo "\033[31mSelect a test file to run:\033[0m" +echo "🧬 0) Run all tests 💥" + +for i in "${!test_files[@]}"; do + echo "🧪 $((i+1))) ${test_files[$i]}" +done + +read -p "Enter number (0-${#test_files[@]}): " choice + +if [ "$choice" -eq 0 ]; then + cargo test + exit +fi + +((choice--)) + +if [[ $choice -ge 0 && $choice -lt ${#test_files[@]} ]]; then + cargo test --test "${test_files[$choice]%.*}" +else + echo "Invalid selection." +fi 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 7306b7d..aa113bd 100644 --- a/unit_tests/tests/test_get_block_with_tx_hashes.rs +++ b/unit_tests/tests/test_get_block_with_tx_hashes.rs @@ -233,3 +233,52 @@ async fn work_loop(deoxys: JsonRpcClient, pathfinder: JsonRpcClie } assert_eq!(diff, false); } + +/// This test may crash because if 2 clients doesnt exactly have the same computation time, the trace will be different +#[rstest] +#[tokio::test] +async fn work_ok_with_pending_block( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + let mut set = tokio::task::JoinSet::new(); + let arc_deoxys = Arc::new(deoxys); + let arc_pathfinder = Arc::new(pathfinder); + + let clone_deoxys = Arc::clone(&arc_deoxys); + set.spawn(async move { + clone_deoxys + .get_block_with_tx_hashes(BlockId::Tag(BlockTag::Pending)) + .await + .expect("Error waiting for response from Deoxys node") + }); + + let clone_pathfinder = Arc::clone(&arc_pathfinder); + set.spawn(async move { + clone_pathfinder + .get_block_with_tx_hashes(BlockId::Tag(BlockTag::Pending)) + .await + .expect("Error waiting for response from Pathfinder node") + }); + + let mut deoxys_result = None; + let mut pathfinder_result = None; + + while let Some(result) = set.join_next().await { + match result { + Ok(response) => { + if deoxys_result.is_none() { + deoxys_result = Some(response); + } else if pathfinder_result.is_none() { + pathfinder_result = Some(response); + } + } + Err(e) => panic!("Task panicked or encountered an error: {:?}", e), + } + } + + assert_eq!( + deoxys_result, pathfinder_result, + "Responses from Deoxys and Pathfinder do not match" + ); +} diff --git a/unit_tests/tests/test_get_transaction_receipt.rs b/unit_tests/tests/test_get_transaction_receipt.rs index e4dfe50..0c6f6f2 100644 --- a/unit_tests/tests/test_get_transaction_receipt.rs +++ b/unit_tests/tests/test_get_transaction_receipt.rs @@ -132,3 +132,11 @@ async fn work_with_deploy_transaction_block_1( ) .await; } + +#[rstest] +#[tokio::test] +async fn work_ok_with_pending_transaction( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { +} diff --git a/unit_tests/tests/test_trace_block_transactions.rs b/unit_tests/tests/test_trace_block_transactions.rs index e105fef..c301c19 100644 --- a/unit_tests/tests/test_trace_block_transactions.rs +++ b/unit_tests/tests/test_trace_block_transactions.rs @@ -5,8 +5,10 @@ use common::*; use rand::Rng; use std::assert_matches::assert_matches; +use std::sync::Arc; +use tokio::task::JoinSet; -use starknet_core::types::{BlockId, FieldElement, StarknetError}; +use starknet_core::types::{BlockId, BlockTag, FieldElement, StarknetError}; use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, @@ -79,3 +81,62 @@ async fn works_ok_for_random_block( assert_matches!(deoxys_trace, _pathfinder_trace); } + +//This test may crash because if 2 clients doesnt exactly have the same computation time, the trace will be different +#[rstest] +#[tokio::test] +async fn works_ok_for_pending_block( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + let mut set = JoinSet::new(); + let arc_deoxys = Arc::new(deoxys); + let arc_pathfinder = Arc::new(pathfinder); + + let clone_deoxys = Arc::clone(&arc_deoxys); + set.spawn(async move { + clone_deoxys + .trace_block_transactions(BlockId::Tag(BlockTag::Pending)) + .await + .expect("Error waiting for response from Deoxys node") + }); + + let clone_pathfinder = Arc::clone(&arc_pathfinder); + set.spawn(async move { + clone_pathfinder + .trace_block_transactions(BlockId::Tag(BlockTag::Pending)) + .await + .expect("Error waiting for response from Pathfinder node") + }); + + let mut deoxys_result = None; + let mut pathfinder_result = None; + + while let Some(result) = set.join_next().await { + match result { + Ok(response) => { + if deoxys_result.is_none() { + deoxys_result = Some(response); + } else if pathfinder_result.is_none() { + pathfinder_result = Some(response); + } + } + Err(e) => panic!("Task panicked or encountered an error: {:?}", e), + } + } + + println!( + "response_deoxys: {:?}", + deoxys_result.clone().expect("Deoxys result not found") + ); + println!( + "response_pathfinder: {:?}", + pathfinder_result + .clone() + .expect("Pathfinder result not found") + ); + assert_eq!( + deoxys_result, pathfinder_result, + "Responses from Deoxys and Pathfinder do not match" + ); +}