From 274d815f36d3bcfe33401f8d5ad0b28b37bd0b66 Mon Sep 17 00:00:00 2001 From: 0xTrinityy Date: Wed, 24 Apr 2024 11:03:54 +0200 Subject: [PATCH] feat: :white_check_mark: Adding tests for get_block_with_receipts RPC call --- .../tests/test_get_block_with_receipts.rs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 unit_tests/tests/test_get_block_with_receipts.rs diff --git a/unit_tests/tests/test_get_block_with_receipts.rs b/unit_tests/tests/test_get_block_with_receipts.rs new file mode 100644 index 0000000..fa9abb3 --- /dev/null +++ b/unit_tests/tests/test_get_block_with_receipts.rs @@ -0,0 +1,107 @@ +#![feature(assert_matches)] + +mod common; +use common::*; + +use rand::Rng; +use std::assert_matches::assert_matches; +use std::sync::Arc; +use tokio::task::JoinSet; + +use starknet_core::types::{BlockId, BlockTag, FieldElement, StarknetError}; +use starknet_providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Provider, +}; + +#[rstest] +#[tokio::test] +async fn fail_non_existing_block(deoxys: JsonRpcClient) { + let response_deoxys = deoxys + .get_block_with_receipts(BlockId::Hash(FieldElement::ZERO)) + .await; + + assert!( + response_deoxys.is_err(), + "Expected an error, but got a result" + ); + + if let Err(error) = response_deoxys { + let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound); + + assert!( + is_correct_error, + "Expected BlockNotFound error, but got a different error" + ); + } +} + +#[rstest] +#[tokio::test] +async fn works_ok_for_block_1( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + let block_number = BlockId::Number(1); + + let deoxys_trace = deoxys.get_block_with_receipts(block_number).await; + let _pathfinder_trace = pathfinder.get_block_with_receipts(block_number).await; + + assert_matches!(deoxys_trace, _pathfinder_trace); +} + +#[rstest] +#[tokio::test] +async fn works_ok_for_block_with_l1_handler_tx( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + let block_number = BlockId::Number(192); //got the first L1HandlerTx at block 192 + + let deoxys_trace = deoxys.get_block_with_receipts(block_number).await; + let _pathfinder_trace = pathfinder.get_block_with_receipts(block_number).await; + + assert_matches!(deoxys_trace, _pathfinder_trace); +} + +#[rstest] +#[tokio::test] +async fn works_ok_for_block_5000( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + let block_number = BlockId::Number(5000); + + let deoxys_trace = deoxys.get_block_with_receipts(block_number).await; + let _pathfinder_trace = pathfinder.get_block_with_receipts(block_number).await; + + assert_matches!(deoxys_trace, _pathfinder_trace); +} + +#[rstest] +#[tokio::test] +async fn works_ok_for_block_10000( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + let block_number = BlockId::Number(10000); + + let deoxys_trace = deoxys.get_block_with_receipts(block_number).await; + let _pathfinder_trace = pathfinder.get_block_with_receipts(block_number).await; + + assert_matches!(deoxys_trace, _pathfinder_trace); +} + +#[rstest] +#[tokio::test] +async fn works_ok_for_block_100000( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + let block_number = BlockId::Number(100000); + + let deoxys_trace = deoxys.get_block_with_receipts(block_number).await; + let _pathfinder_trace = pathfinder.get_block_with_receipts(block_number).await; + + assert_matches!(deoxys_trace, _pathfinder_trace); +}