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

Enhancing Ditto and adding some pending tests 🧪 #52

Merged
merged 7 commits into from
Apr 2, 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
27 changes: 27 additions & 0 deletions ditto.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪⬛⬛🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛🟪🟪🟪🟪⬛🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪⬛⬛🟪🟪🟪🟪🟪⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛
⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛
⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛
⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛
⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛
⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛
⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛
⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛
⬛⬛⬛⬛🟪🟪🟪⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛🟪🟪🟪🟪🟪⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛🟪🟪🟪🟪🟪🟪🟪🟪🟪⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
28 changes: 28 additions & 0 deletions run_Ditto.sh
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions unit_tests/tests/test_get_block_with_tx_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,52 @@ async fn work_loop(deoxys: JsonRpcClient<HttpTransport>, 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<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
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"
);
}
8 changes: 8 additions & 0 deletions unit_tests/tests/test_get_transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
}
63 changes: 62 additions & 1 deletion unit_tests/tests/test_trace_block_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
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"
);
}
Loading