From 23846053c37e499047d498bf494276b65dd738ab Mon Sep 17 00:00:00 2001 From: jb caron Date: Fri, 19 Jan 2024 01:05:43 +0100 Subject: [PATCH] test: :test_tube: add tests for mismatch block_hash, optional multithread loop tests #38 --- .../tests/test_get_block_transaction_count.rs | 124 +++++++++++----- .../tests/test_get_block_with_tx_hashes.rs | 120 ++++++++++++++++ unit_tests/tests/test_get_block_with_txs.rs | 135 ++++++++++++++---- .../tests/test_get_transaction_receipt.rs | 131 +++++++++-------- .../tests/test_get_transaction_status.rs | 80 +++++++++++ 5 files changed, 464 insertions(+), 126 deletions(-) diff --git a/unit_tests/tests/test_get_block_transaction_count.rs b/unit_tests/tests/test_get_block_transaction_count.rs index 0a2a3a8..ce4ecff 100644 --- a/unit_tests/tests/test_get_block_transaction_count.rs +++ b/unit_tests/tests/test_get_block_transaction_count.rs @@ -1,16 +1,16 @@ #![feature(assert_matches)] -/// TODO test on a block withouth transactions +/// TODO test on a block without transactions mod common; use common::*; -use std::{assert_matches::assert_matches, collections::HashMap}; - use starknet_core::types::{BlockId, BlockTag, FieldElement, StarknetError}; use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, ProviderError, }; +use std::sync::Arc; +use std::{assert_matches::assert_matches, collections::HashMap}; use unit_tests::constants::DEOXYS; #[require(spec_version = "0.5.1")] @@ -52,14 +52,12 @@ async fn work_with_latest_block(clients: HashMap>) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let block_number = BlockId::Number(1); +async fn work_with_block( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, + block_number: u64, +) { + let block_number = BlockId::Number(block_number); let response_deoxys = deoxys .get_block_transaction_count(block_number) @@ -77,7 +75,17 @@ async fn work_with_block_one_num(clients: HashMap>) { +async fn work_with_block_1( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 1).await; +} + +#[require(block_min = 1, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_1_hash(clients: HashMap>) { let deoxys = &clients[DEOXYS]; let pathfinder = &clients[PATHFINDER]; @@ -101,36 +109,31 @@ async fn work_with_block_one_hash(clients: HashMap>, +async fn work_with_block_5066( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, ) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let block_number = BlockId::Number(100000); - - let response_deoxys = deoxys - .get_block_transaction_count(block_number) - .await - .expect("Error waiting for response from Deoxys node"); - - let response_pathfinder = pathfinder - .get_block_transaction_count(block_number) - .await - .expect("Error waiting for response from Pathfinder node"); - - assert_eq!(response_deoxys, response_pathfinder); + work_with_block(deoxys, pathfinder, 1).await; } #[require(block_min = 100_000, spec_version = "0.5.1")] #[rstest] #[tokio::test] -async fn work_with_block_one_hundred_thousand_hash( - clients: HashMap>, +async fn work_with_block_100_000( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, ) { + work_with_block(deoxys, pathfinder, 100_000).await; +} + +#[require(block_min = 100_000, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_100_000_hash(clients: HashMap>) { let deoxys = &clients[DEOXYS]; let pathfinder = &clients[PATHFINDER]; @@ -153,3 +156,58 @@ async fn work_with_block_one_hundred_thousand_hash( assert_eq!(response_deoxys, response_pathfinder); } + +#[require(block_min = 100_000, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +#[ignore = "ignore this test"] +async fn work_loop(deoxys: JsonRpcClient, pathfinder: JsonRpcClient) { + let arc_deoxys = Arc::new(deoxys); + let arc_pathfinder = Arc::new(pathfinder); + let parallels_queries = 10; + let mut diff = false; + + for block_group in (0..=100_000).step_by(parallels_queries) { + let mut set = tokio::task::JoinSet::new(); + for offset in 0..parallels_queries { + let block_id = (block_group + offset) as u64; + let block = BlockId::Number(block_id); + let clone_deoxys = Arc::clone(&arc_deoxys); + let clone_pathfinder = Arc::clone(&arc_pathfinder); + set.spawn(async move { + let response_deoxys = clone_deoxys + .get_block_transaction_count(block) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = clone_pathfinder.get_block_transaction_count(block).await; + + match response_pathfinder { + Ok(response_pathfinder) => { + if response_deoxys != response_pathfinder { + Err(format!("block {}", block_id)) + } else { + Ok(()) + } + } + Err(e) => Err(format!("Error pathfinder: {}", e)), + } + }); + } + while let Some(result) = set.join_next().await { + match result { + Ok(result) => match result { + Ok(_) => {} + Err(e) => { + println!("{}", e); + diff = true; + } + }, + Err(e) => { + panic!("{}", e); + } + } + } + } + assert_eq!(diff, false); +} 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 0e7ff00..9a1a219 100644 --- a/unit_tests/tests/test_get_block_with_tx_hashes.rs +++ b/unit_tests/tests/test_get_block_with_tx_hashes.rs @@ -4,6 +4,7 @@ mod common; use common::*; use starknet_core::types::MaybePendingBlockWithTxHashes; +use std::sync::Arc; use std::{assert_matches::assert_matches, collections::HashMap}; use starknet_core::types::{BlockId, BlockTag, FieldElement, StarknetError}; @@ -111,3 +112,122 @@ async fn work_pending_block(clients: HashMap, + pathfinder: JsonRpcClient, + block_number: u64, +) { + let block_number = BlockId::Number(block_number); + + let response_deoxys = deoxys + .get_block_with_tx_hashes(block_number) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = pathfinder + .get_block_with_tx_hashes(block_number) + .await + .expect("Error waiting for response from Pathfinder node"); + + assert_eq!(response_deoxys, response_pathfinder); +} + +/// block 1 +#[require(block_min = 1, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_1( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 1).await; +} + +/// block 3800 is the first block with starknet_version in the header +#[require(block_min = 3800, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_3800( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 1).await; +} + +/// block 50066 is one of the biggest blocks in the mainnet +#[require(block_min = 5066, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_5066( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 1).await; +} + +/// block 1466-2242 mismatch block_hash +#[require(block_min = 1500, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_1500( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 1500).await; +} + +#[require(block_min = 100_000, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +#[ignore = "ignore this test"] +async fn work_loop(deoxys: JsonRpcClient, pathfinder: JsonRpcClient) { + let arc_deoxys = Arc::new(deoxys); + let arc_pathfinder = Arc::new(pathfinder); + let parallels_queries = 10; + let mut diff = false; + + for block_group in (0..=100_000).step_by(parallels_queries) { + let mut set = tokio::task::JoinSet::new(); + for offset in 0..parallels_queries { + let block_id = (block_group + offset) as u64; + let block = BlockId::Number(block_id); + let clone_deoxys = Arc::clone(&arc_deoxys); + let clone_pathfinder = Arc::clone(&arc_pathfinder); + set.spawn(async move { + let response_deoxys = clone_deoxys + .get_block_with_tx_hashes(block) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = clone_pathfinder.get_block_with_tx_hashes(block).await; + + match response_pathfinder { + Ok(response_pathfinder) => { + if response_deoxys != response_pathfinder { + Err(format!("block {}", block_id)) + } else { + Ok(()) + } + } + Err(e) => Err(format!("Error pathfinder: {}", e)), + } + }); + } + while let Some(result) = set.join_next().await { + match result { + Ok(result) => match result { + Ok(_) => {} + Err(e) => { + println!("{}", e); + diff = true; + } + }, + Err(e) => { + panic!("{}", e); + } + } + } + } + assert_eq!(diff, false); +} diff --git a/unit_tests/tests/test_get_block_with_txs.rs b/unit_tests/tests/test_get_block_with_txs.rs index 9869cd3..4a7ca5b 100644 --- a/unit_tests/tests/test_get_block_with_txs.rs +++ b/unit_tests/tests/test_get_block_with_txs.rs @@ -3,6 +3,7 @@ /// TODO test on a block withouth transactions mod common; use common::*; +use std::sync::Arc; use std::{assert_matches::assert_matches, collections::HashMap}; @@ -52,14 +53,12 @@ async fn work_with_latest_block(clients: HashMap>) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let block_number = BlockId::Number(1); +async fn work_with_block( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, + block_number: u64, +) { + let block_number = BlockId::Number(block_number); let response_deoxys = deoxys .get_block_with_txs(block_number) @@ -74,6 +73,17 @@ async fn work_with_block_one_num(clients: HashMap, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 1).await; +} + #[require(block_min = 1, spec_version = "0.5.1")] #[rstest] #[tokio::test] @@ -104,25 +114,11 @@ async fn work_with_block_one_hash(clients: HashMap>, +async fn work_with_block_100_000( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, ) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let block_number = BlockId::Number(100000); - - let response_deoxys = deoxys - .get_block_with_txs(block_number) - .await - .expect("Error waiting for response from Deoxys node"); - - let response_pathfinder = pathfinder - .get_block_with_txs(block_number) - .await - .expect("Error waiting for response from Pathfinder node"); - - assert_eq!(response_deoxys, response_pathfinder); + work_with_block(deoxys, pathfinder, 100_000).await; } #[require(block_min = 100_000, spec_version = "0.5.1")] @@ -153,3 +149,90 @@ async fn work_with_block_one_hundred_thousand_hash( assert_eq!(response_deoxys, response_pathfinder); } + +/// block 3800 is the first block with starknet_version in the header +#[require(block_min = 3800, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_3800( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 3800).await; +} + +/// block 50066 is one of the biggest blocks in the mainnet +#[require(block_min = 5066, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_5066( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 5066).await; +} +/// block 1466-2242 mismatch block_hash +#[require(block_min = 1500, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_block_1500( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_block(deoxys, pathfinder, 1500).await; +} + +#[require(block_min = 100_000, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +#[ignore = "ignore this test"] +async fn work_loop(deoxys: JsonRpcClient, pathfinder: JsonRpcClient) { + let arc_deoxys = Arc::new(deoxys); + let arc_pathfinder = Arc::new(pathfinder); + let parallels_queries = 10; + let mut diff = false; + + for block_group in (0..=100_000).step_by(parallels_queries) { + let mut set = tokio::task::JoinSet::new(); + for offset in 0..parallels_queries { + let block_id = (block_group + offset) as u64; + let block = BlockId::Number(block_id); + let clone_deoxys = Arc::clone(&arc_deoxys); + let clone_pathfinder = Arc::clone(&arc_pathfinder); + set.spawn(async move { + let response_deoxys = clone_deoxys + .get_block_with_txs(block) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = clone_pathfinder.get_block_with_txs(block).await; + + match response_pathfinder { + Ok(response_pathfinder) => { + if response_deoxys != response_pathfinder { + Err(format!("block {}", block_id)) + } else { + Ok(()) + } + } + Err(e) => Err(format!("Error pathfinder: {}", e)), + } + }); + } + while let Some(result) = set.join_next().await { + match result { + Ok(result) => match result { + Ok(_) => {} + Err(e) => { + println!("{}", e); + diff = true; + } + }, + Err(e) => { + panic!("{}", e); + } + } + } + } + assert_eq!(diff, false); +} diff --git a/unit_tests/tests/test_get_transaction_receipt.rs b/unit_tests/tests/test_get_transaction_receipt.rs index c93ff24..75b3d7f 100644 --- a/unit_tests/tests/test_get_transaction_receipt.rs +++ b/unit_tests/tests/test_get_transaction_receipt.rs @@ -31,18 +31,13 @@ async fn fail_invalid_transaction_hash(clients: HashMap>) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let transaction_hash = FieldElement::from_hex_be( - "0x410e4d74a2322b78d2e342ac376ea555c89b1a0fe73bb36067eb149da123dd1", - ) - .expect("Error parsing transaction hash"); +async fn work_with_hash( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, + transaction_hash: &str, +) { + let transaction_hash = + FieldElement::from_hex_be(transaction_hash).expect("Error parsing transaction hash"); let response_deoxys = deoxys .get_transaction_receipt(transaction_hash) @@ -57,80 +52,82 @@ async fn work_with_rejected_transaction(clients: HashMap, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, + "0x410e4d74a2322b78d2e342ac376ea555c89b1a0fe73bb36067eb149da123dd1", + ) + .await; +} + /// first transaction on block 0 #[require(spec_version = "0.5.1")] #[rstest] #[tokio::test] -async fn work_with_first_transaction(clients: HashMap>) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let transaction_hash = FieldElement::from_hex_be( +async fn work_with_first_transaction_block_0( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, "0xe0a2e45a80bb827967e096bcf58874f6c01c191e0a0530624cba66a508ae75", ) - .expect("Error parsing transaction hash"); - - let response_deoxys = deoxys - .get_transaction_receipt(transaction_hash) - .await - .expect("Error waiting for response from Deoxys node"); - - let response_pathfinder = pathfinder - .get_transaction_receipt(transaction_hash) - .await - .expect("Error waiting for response from Pathfinder node"); - - assert_eq!(response_deoxys, response_pathfinder); + .await; } -/// deploy transaction +/// deploy transaction on block 0 #[require(spec_version = "0.5.1")] #[rstest] #[tokio::test] -async fn work_with_deploy(clients: HashMap>) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let transaction_hash = FieldElement::from_hex_be( +async fn work_with_deploy_transaction_block_0( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, "0x12c96ae3c050771689eb261c9bf78fac2580708c7f1f3d69a9647d8be59f1e1", ) - .expect("Error parsing transaction hash"); - - let response_deoxys = deoxys - .get_transaction_receipt(transaction_hash) - .await - .expect("Error waiting for response from Deoxys node"); - - let response_pathfinder = pathfinder - .get_transaction_receipt(transaction_hash) - .await - .expect("Error waiting for response from Pathfinder node"); - - assert_eq!(response_deoxys, response_pathfinder); + .await; } -///invoke transaction +///invoke transaction on block 0 #[require(spec_version = "0.5.1")] #[rstest] #[tokio::test] -async fn work_with_invoke(clients: HashMap>) { - let deoxys = &clients[DEOXYS]; - let pathfinder = &clients[PATHFINDER]; - - let transaction_hash = FieldElement::from_hex_be( +async fn work_with_invoke_transaction_block_0( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, "0xce54bbc5647e1c1ea4276c01a708523f740db0ff5474c77734f73beec2624", ) - .expect("Error parsing transaction hash"); - - let response_deoxys = deoxys - .get_transaction_receipt(transaction_hash) - .await - .expect("Error waiting for response from Deoxys node"); - - let response_pathfinder = pathfinder - .get_transaction_receipt(transaction_hash) - .await - .expect("Error waiting for response from Pathfinder node"); + .await; +} - assert_eq!(response_deoxys, response_pathfinder); +///deploy transaction on block 1 +#[require(block_min = 1, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_deploy_transaction_block_1( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, + "0x2f07a65f9f7a6445b2a0b1fb90ef12f5fd3b94128d06a67712efd3b2f163533", + ) + .await; } diff --git a/unit_tests/tests/test_get_transaction_status.rs b/unit_tests/tests/test_get_transaction_status.rs index a11ff37..176f14e 100644 --- a/unit_tests/tests/test_get_transaction_status.rs +++ b/unit_tests/tests/test_get_transaction_status.rs @@ -132,3 +132,83 @@ async fn work_transaction_reverted(clients: HashMap, + pathfinder: JsonRpcClient, + transaction_hash: &str, +) { + let tx = FieldElement::from_hex_be(transaction_hash).unwrap(); + let response_deoxys = deoxys.get_transaction_status(tx).await.expect(ERR_DEOXYS); + + let response_pathfinder = pathfinder + .get_transaction_status(tx) + .await + .expect(ERR_PATHFINDER); + + assert_eq!(response_deoxys, response_pathfinder); +} + +/// first transaction on block 0 +#[require(spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_first_transaction_block_0( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, + "0xe0a2e45a80bb827967e096bcf58874f6c01c191e0a0530624cba66a508ae75", + ) + .await; +} + +/// deploy transaction on block 0 +#[require(spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_deploy_transaction_block_0( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, + "0x12c96ae3c050771689eb261c9bf78fac2580708c7f1f3d69a9647d8be59f1e1", + ) + .await; +} + +///invoke transaction on block 0 +#[require(spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_invoke_transaction_block_0( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, + "0xce54bbc5647e1c1ea4276c01a708523f740db0ff5474c77734f73beec2624", + ) + .await; +} + +///deploy transaction on block 1 +#[require(block_min = 1, spec_version = "0.5.1")] +#[rstest] +#[tokio::test] +async fn work_with_deploy_transaction_block_1( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { + work_with_hash( + deoxys, + pathfinder, + "0x2f07a65f9f7a6445b2a0b1fb90ef12f5fd3b94128d06a67712efd3b2f163533", + ) + .await; +}