Skip to content

Commit

Permalink
feat: 🚑 Working on Ditto
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbelleng committed Mar 6, 2024
1 parent 019c369 commit 1b286f7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions unit_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", r
starknet-signers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "96c6803", default-features = false }
env_logger = "0.10.1"
macro_utils = { path = "../macro_utils/" }
rand = "0.8.5"
serde_json = "1.0"

[dev-dependencies]
jsonrpsee = { version = "0.21.0", features = ["client"] }
Expand Down
63 changes: 63 additions & 0 deletions unit_tests/tests/test_trace_block_transactions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#![feature(assert_matches)]

mod common;
use common::*;

use std::assert_matches::assert_matches;
use rand::Rng;

use starknet_core::types::{FieldElement, StarknetError, BlockId};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, ProviderError,
};

#[rstest]
#[tokio::test]
async fn fail_non_existing_block(deoxys: JsonRpcClient<HttpTransport>) {

assert_matches!(
deoxys.trace_block_transactions(BlockId::Hash(FieldElement::ZERO)).await,
Err(ProviderError::StarknetError(StarknetError::BlockNotFound))
);
}

#[rstest]
#[tokio::test]
async fn works_ok_for_block_10000(deoxys: JsonRpcClient<HttpTransport>, pathfinder: JsonRpcClient<HttpTransport>) {

let block_number = BlockId::Number(10000);

let deoxys_trace = deoxys.trace_block_transactions(block_number).await;
let _pathfinder_trace = pathfinder.trace_block_transactions(block_number).await;

assert_matches!(deoxys_trace, _pathfinder_trace);
}

#[rstest]
#[tokio::test]
async fn works_ok_for_block_300000(deoxys: JsonRpcClient<HttpTransport>, pathfinder: JsonRpcClient<HttpTransport>) {

let block_number = BlockId::Number(300000);

let deoxys_trace = deoxys.trace_block_transactions(block_number).await;
let _pathfinder_trace = pathfinder.trace_block_transactions(block_number).await;

assert_matches!(deoxys_trace, _pathfinder_trace);
}

#[rstest]
#[tokio::test]
async fn works_ok_for_random_block(deoxys: JsonRpcClient<HttpTransport>, pathfinder: JsonRpcClient<HttpTransport>) {
let mut rng = rand::thread_rng();
let random_block_number = rng.gen_range(100000..602000);

let block_number = BlockId::Number(random_block_number);

let deoxys_trace = deoxys.trace_block_transactions(block_number).await;
let _pathfinder_trace = pathfinder.trace_block_transactions(block_number).await;
println!("{:?}", deoxys_trace);
println!("block choose is: {:?}", block_number);

assert_matches!(deoxys_trace, _pathfinder_trace);
}

0 comments on commit 1b286f7

Please sign in to comment.