From 1b286f7ca1734e74baf9df6a64766bbbc36e47da Mon Sep 17 00:00:00 2001 From: 0xTrinityy Date: Wed, 6 Mar 2024 18:06:51 +0100 Subject: [PATCH 1/3] feat: :ambulance: Working on Ditto --- Cargo.lock | 2 + unit_tests/Cargo.toml | 2 + .../tests/test_trace_block_transactions.rs | 63 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 unit_tests/tests/test_trace_block_transactions.rs diff --git a/Cargo.lock b/Cargo.lock index 3771fda..729ca6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2811,7 +2811,9 @@ dependencies = [ "log", "macro", "macro_utils", + "rand", "rstest", + "serde_json", "starknet 0.8.0", "starknet-accounts 0.7.0", "starknet-core 0.8.0", diff --git a/unit_tests/Cargo.toml b/unit_tests/Cargo.toml index 2c4893f..4fda557 100644 --- a/unit_tests/Cargo.toml +++ b/unit_tests/Cargo.toml @@ -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"] } diff --git a/unit_tests/tests/test_trace_block_transactions.rs b/unit_tests/tests/test_trace_block_transactions.rs new file mode 100644 index 0000000..8486335 --- /dev/null +++ b/unit_tests/tests/test_trace_block_transactions.rs @@ -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) { + + 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, pathfinder: JsonRpcClient) { + + 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, pathfinder: JsonRpcClient) { + + 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, pathfinder: JsonRpcClient) { + 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); +} \ No newline at end of file From 87e1a1a793abe3f0bec728b5bf6c92f03c238f01 Mon Sep 17 00:00:00 2001 From: 0xTrinityy Date: Fri, 8 Mar 2024 18:03:21 +0100 Subject: [PATCH 2/3] feat: :sparkles: Adding add_invoke_transaction and deploy_account_transaction test --- .../tests/test_add_invoke_transaction.rs | 151 +++++++++++++++++ .../tests/test_deploy_account_transaction.rs | 156 ++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 unit_tests/tests/test_add_invoke_transaction.rs create mode 100644 unit_tests/tests/test_deploy_account_transaction.rs diff --git a/unit_tests/tests/test_add_invoke_transaction.rs b/unit_tests/tests/test_add_invoke_transaction.rs new file mode 100644 index 0000000..1446581 --- /dev/null +++ b/unit_tests/tests/test_add_invoke_transaction.rs @@ -0,0 +1,151 @@ +#![feature(assert_matches)] + +mod common; +use common::*; +use starknet_core::types::{BroadcastedInvokeTransaction, FieldElement, StarknetError, TransactionStatus}; +use starknet_providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Provider, ProviderError, +}; +use std::assert_matches::assert_matches; +use std::thread; +use std::time::Duration; + +/// Test for the `add_invoke_transaction` Deoxys RPC method +/// Submit a new transaction to be added to the chain +/// +/// # Arguments +/// * `invoke_transaction` - An invoke transaction, +/// with following fields: +/// * `type` - INVOKE +/// * `sender_address` - The address of the sender +/// * `calldata` - The calldata to send +/// * `max_fee` - The maximum fees sender is willing to pay +/// * `version` - The version of the transaction +/// * `signature` - The transaction signature +/// * `nonce` - The nonce of the transaction +/// +/// # Returns +/// * `result` - The result of the transaction submission, with the transaction hash that has been submitted +/// +/// # Errors +/// * `invalid_transaction_nonce` - If the transaction nonce is invalid +/// * `insufficient_account_balance` - If the account balance is insufficient +/// * `insufficient_max_fee` - If the max fee is insufficient +/// * `invalid_transaction_nonce` - If the transaction nonce is invalid +/// * `validation_failure` - If the transaction validation fails +/// * `non_account` - If the sender address is not a valid account +/// * `duplicate_transaction` - If a transaction with same params already exists +/// * `unsupported_transaction_version` - If the transaction version is not supported +/// * `unexpected_error` - If an unexpected error occurs + +/// Following tests runs using V1 Invoke Transaction (params follow starknet-rs implementation) +#[rstest] +#[tokio::test] +async fn fail_if_param_(deoxys: JsonRpcClient) { + + let invalid_invoke_transaction = BroadcastedInvokeTransaction { + sender_address: FieldElement::from_hex_be("valid_address").unwrap(), + calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()], + max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x000000").unwrap(), //here nonce is invalid + is_query: false, + }; + + let response_deoxys = deoxys + .add_invoke_transaction(invalid_invoke_transaction) + .await; + + assert_matches!( + response_deoxys, + Err(ProviderError::StarknetError( + StarknetError::InvalidTransactionNonce + )) + ); +} + +#[rstest] +#[tokio::test] +async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient) { + + let invalid_invoke_transaction = BroadcastedInvokeTransaction { + sender_address: FieldElement::from_hex_be("valid_address").unwrap(), + calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()], + max_fee: FieldElement::from_hex_be("0x000000").unwrap(), //here max_fee is insufficient + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x01").unwrap(), + is_query: false, + }; + + let response_deoxys = deoxys + .add_invoke_transaction(invalid_invoke_transaction) + .await; + + assert_matches!( + response_deoxys, + Err(ProviderError::StarknetError( + StarknetError::InsufficientMaxFee + )) + ); +} + +#[rstest] +#[tokio::test] +async fn fail_if_bad_calldata(deoxys: JsonRpcClient) { + + let invalid_invoke_transaction = BroadcastedInvokeTransaction { + sender_address: FieldElement::from_hex_be("valid_address").unwrap(), + calldata: vec![FieldElement::from_hex_be("0x000000").unwrap()], //here calldata is invalid + max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x01").unwrap(), + is_query: false, + }; + + let response_deoxys = deoxys + .add_invoke_transaction(invalid_invoke_transaction) + .await; + + assert_matches!( + response_deoxys, + Err(ProviderError::StarknetError( + StarknetError::ValidationFailure + )) + ); +} + +#[rstest] +#[tokio::test] +async fn works_ok_with_valid_params(deoxys: JsonRpcClient) { + + let valid_invoke_transaction = BroadcastedInvokeTransaction { + sender_address: FieldElement::from_hex_be("valid_address").unwrap(), + calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()], + max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x01").unwrap(), + is_query: false, + }; + + //Here we added a valid transaction + let response_deoxys = deoxys + .add_invoke_transaction(valid_invoke_transaction) + .await; + + //Now, if the transaction is valid, the rpc call response contain the transaction hash + let transaction_submitted_hash = response_deoxys.expect("Transaction submition failed").transaction_hash; + + //Wait for the transaction to be added to the chain + thread::sleep(Duration::from_secs(15)); + + //Let's check the transaction status + let transaction_status = deoxys + .get_transaction_status(transaction_submitted_hash) + .await; + + assert_matches!( + transaction_status.unwrap(), + TransactionStatus::Received + ); +} \ No newline at end of file diff --git a/unit_tests/tests/test_deploy_account_transaction.rs b/unit_tests/tests/test_deploy_account_transaction.rs new file mode 100644 index 0000000..951ccb0 --- /dev/null +++ b/unit_tests/tests/test_deploy_account_transaction.rs @@ -0,0 +1,156 @@ +#![feature(assert_matches)] + +mod common; +use common::*; +use starknet_core::types::{BroadcastedDeployAccountTransaction, FieldElement, StarknetError, TransactionStatus}; +use starknet_providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Provider, ProviderError, +}; +use std::assert_matches::assert_matches; +use std::thread; +use std::time::Duration; + +/// Test for the `deploy_account_transaction` Deoxys RPC method +/// Submit a new deploy account transaction +/// +/// There is two type of DeployAccountTransaction: V1 and V3 +/// +/// # Arguments +/// * `deploy_account_transaction` - A deploy account transaction +/// with following fields (V1): +/// * `type` - DEPLOY_ACCOUNT +/// * `max_fee` - The maximal fee willing to be paid +/// * `signature` - The transaction signature +/// * `nonce` - The nonce of the transaction +/// * `contract_address_salt` - The salt for the address of the deployed contract +/// * `constructor_calldata` - The parameters passed to the constructor +/// * `class_hash` - The hash of the deployed contract's class +/// * `is_query` - If set to `true`, uses a query-only transaction version that's invalid for execution +/// +/// # Returns +/// * `result` - The result of the transaction submission +/// with following fields: +/// * `transaction_hash` - The hash of the transaction +/// * `contract_address` - The address of the deployed contract +/// +/// # Errors +/// * `invalid_transaction_nonce` - If the transaction nonce is invalid +/// * `insufficient_account_balance` - If the account balance is insufficient +/// * `insufficient_max_fee` - If the max fee is insufficient +/// * `invalid_transaction_nonce` - If the transaction nonce is invalid +/// * `validation_failure` - If the transaction validation fails +/// * `non_account` - If the sender address is not a valid account +/// * `duplicate_transaction` - If a transaction with same params already exists +/// * `unsupported_transaction_version` - If the transaction version is not supported +/// * `unexpected_error` - If an unexpected error occurs + +#[rstest] +#[tokio::test] +async fn fail_if_param_(deoxys: JsonRpcClient) { + + let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction { + max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x000000").unwrap(), //here nonce is invalid + contract_address_salt: FieldElement::from_hex_be("0x000000").unwrap(), + constructor_calldata: vec![FieldElement::from_hex_be("constructor_calldata_array").unwrap()], + class_hash: FieldElement::from_hex_be("0x000000").unwrap(), + is_query: false, + }; + + let response_deoxys = deoxys + .add_deploy_account_transaction(invalid_deploy_account_transaction) + .await; + + assert_matches!( + response_deoxys, + Err(ProviderError::StarknetError(StarknetError::InvalidTransactionNonce)) + ); +} + +#[rstest] +#[tokio::test] +async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient) { + + let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction { + max_fee: FieldElement::from_hex_be("0x000000").unwrap(), //here max_fee is insufficient + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x000000").unwrap(), + contract_address_salt: FieldElement::from_hex_be("0x000000").unwrap(), + constructor_calldata: vec![FieldElement::from_hex_be("constructor_calldata_array").unwrap()], + class_hash: FieldElement::from_hex_be("0x000000").unwrap(), + is_query: false, + }; + + let response_deoxys = deoxys + .add_deploy_account_transaction(invalid_deploy_account_transaction) + .await; + + assert_matches!( + response_deoxys, + Err(ProviderError::StarknetError(StarknetError::InsufficientMaxFee)) + ); +} + +#[rstest] +#[tokio::test] +async fn fail_if_invalid_transaction_nonce(deoxys: JsonRpcClient) { + + let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction { + max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x000000").unwrap(), //here nonce is invalid + contract_address_salt: FieldElement::from_hex_be("0x000000").unwrap(), + constructor_calldata: vec![FieldElement::from_hex_be("constructor_calldata_array").unwrap()], + class_hash: FieldElement::from_hex_be("0x000000").unwrap(), + is_query: false, + }; + + let response_deoxys = deoxys + .add_deploy_account_transaction(invalid_deploy_account_transaction) + .await; + + assert_matches!( + response_deoxys, + Err(ProviderError::StarknetError(StarknetError::InvalidTransactionNonce)) + ); +} + +#[rstest] +#[tokio::test] +async fn works_ok(deoxys: JsonRpcClient) { + + let valid_deploy_account_transaction = BroadcastedDeployAccountTransaction { + max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), + signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], + nonce: FieldElement::from_hex_be("0x000000").unwrap(), + contract_address_salt: FieldElement::from_hex_be("0x000000").unwrap(), + constructor_calldata: vec![FieldElement::from_hex_be("constructor_calldata_array").unwrap()], + class_hash: FieldElement::from_hex_be("0x000000").unwrap(), + is_query: false, + }; + + let response_deoxys = deoxys + .add_deploy_account_transaction(valid_deploy_account_transaction) + .await; + + //Here, as response we got the transaction hash and the contract address deployed + let result = response_deoxys.unwrap(); + + //Now, if the transaction is valid, the rpc call response contain the transaction hash + let transaction_submitted_hash = response_deoxys.expect("Transaction submition failed").transaction_hash; + + //Wait for the transaction to be added to the chain + thread::sleep(Duration::from_secs(15)); + + //Let's check the transaction status + let transaction_status = deoxys + .get_transaction_status(transaction_submitted_hash) + .await; + + assert_matches!( + transaction_status.unwrap(), + TransactionStatus::Received + ); +} \ No newline at end of file From e401f7c56e6b45d365390b66babf80f89020cb3d Mon Sep 17 00:00:00 2001 From: 0xTrinityy Date: Mon, 11 Mar 2024 09:49:43 +0100 Subject: [PATCH 3/3] feat: :art: fmt --- .../tests/test_add_invoke_transaction.rs | 25 +++++----- .../tests/test_deploy_account_transaction.rs | 49 ++++++++++--------- .../tests/test_trace_block_transactions.rs | 30 +++++++----- 3 files changed, 56 insertions(+), 48 deletions(-) diff --git a/unit_tests/tests/test_add_invoke_transaction.rs b/unit_tests/tests/test_add_invoke_transaction.rs index 1446581..65f483f 100644 --- a/unit_tests/tests/test_add_invoke_transaction.rs +++ b/unit_tests/tests/test_add_invoke_transaction.rs @@ -2,7 +2,9 @@ mod common; use common::*; -use starknet_core::types::{BroadcastedInvokeTransaction, FieldElement, StarknetError, TransactionStatus}; +use starknet_core::types::{ + BroadcastedInvokeTransaction, FieldElement, StarknetError, TransactionStatus, +}; use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, ProviderError, @@ -13,7 +15,7 @@ use std::time::Duration; /// Test for the `add_invoke_transaction` Deoxys RPC method /// Submit a new transaction to be added to the chain -/// +/// /// # Arguments /// * `invoke_transaction` - An invoke transaction, /// with following fields: @@ -24,10 +26,10 @@ use std::time::Duration; /// * `version` - The version of the transaction /// * `signature` - The transaction signature /// * `nonce` - The nonce of the transaction -/// +/// /// # Returns /// * `result` - The result of the transaction submission, with the transaction hash that has been submitted -/// +/// /// # Errors /// * `invalid_transaction_nonce` - If the transaction nonce is invalid /// * `insufficient_account_balance` - If the account balance is insufficient @@ -43,7 +45,6 @@ use std::time::Duration; #[rstest] #[tokio::test] async fn fail_if_param_(deoxys: JsonRpcClient) { - let invalid_invoke_transaction = BroadcastedInvokeTransaction { sender_address: FieldElement::from_hex_be("valid_address").unwrap(), calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()], @@ -68,7 +69,6 @@ async fn fail_if_param_(deoxys: JsonRpcClient) { #[rstest] #[tokio::test] async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient) { - let invalid_invoke_transaction = BroadcastedInvokeTransaction { sender_address: FieldElement::from_hex_be("valid_address").unwrap(), calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()], @@ -93,7 +93,6 @@ async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient) { #[rstest] #[tokio::test] async fn fail_if_bad_calldata(deoxys: JsonRpcClient) { - let invalid_invoke_transaction = BroadcastedInvokeTransaction { sender_address: FieldElement::from_hex_be("valid_address").unwrap(), calldata: vec![FieldElement::from_hex_be("0x000000").unwrap()], //here calldata is invalid @@ -118,7 +117,6 @@ async fn fail_if_bad_calldata(deoxys: JsonRpcClient) { #[rstest] #[tokio::test] async fn works_ok_with_valid_params(deoxys: JsonRpcClient) { - let valid_invoke_transaction = BroadcastedInvokeTransaction { sender_address: FieldElement::from_hex_be("valid_address").unwrap(), calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()], @@ -134,7 +132,9 @@ async fn works_ok_with_valid_params(deoxys: JsonRpcClient) { .await; //Now, if the transaction is valid, the rpc call response contain the transaction hash - let transaction_submitted_hash = response_deoxys.expect("Transaction submition failed").transaction_hash; + let transaction_submitted_hash = response_deoxys + .expect("Transaction submition failed") + .transaction_hash; //Wait for the transaction to be added to the chain thread::sleep(Duration::from_secs(15)); @@ -144,8 +144,5 @@ async fn works_ok_with_valid_params(deoxys: JsonRpcClient) { .get_transaction_status(transaction_submitted_hash) .await; - assert_matches!( - transaction_status.unwrap(), - TransactionStatus::Received - ); -} \ No newline at end of file + assert_matches!(transaction_status.unwrap(), TransactionStatus::Received); +} diff --git a/unit_tests/tests/test_deploy_account_transaction.rs b/unit_tests/tests/test_deploy_account_transaction.rs index 951ccb0..80e475e 100644 --- a/unit_tests/tests/test_deploy_account_transaction.rs +++ b/unit_tests/tests/test_deploy_account_transaction.rs @@ -2,7 +2,9 @@ mod common; use common::*; -use starknet_core::types::{BroadcastedDeployAccountTransaction, FieldElement, StarknetError, TransactionStatus}; +use starknet_core::types::{ + BroadcastedDeployAccountTransaction, FieldElement, StarknetError, TransactionStatus, +}; use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, ProviderError, @@ -13,9 +15,9 @@ use std::time::Duration; /// Test for the `deploy_account_transaction` Deoxys RPC method /// Submit a new deploy account transaction -/// +/// /// There is two type of DeployAccountTransaction: V1 and V3 -/// +/// /// # Arguments /// * `deploy_account_transaction` - A deploy account transaction /// with following fields (V1): @@ -27,13 +29,13 @@ use std::time::Duration; /// * `constructor_calldata` - The parameters passed to the constructor /// * `class_hash` - The hash of the deployed contract's class /// * `is_query` - If set to `true`, uses a query-only transaction version that's invalid for execution -/// +/// /// # Returns /// * `result` - The result of the transaction submission /// with following fields: /// * `transaction_hash` - The hash of the transaction /// * `contract_address` - The address of the deployed contract -/// +/// /// # Errors /// * `invalid_transaction_nonce` - If the transaction nonce is invalid /// * `insufficient_account_balance` - If the account balance is insufficient @@ -48,7 +50,6 @@ use std::time::Duration; #[rstest] #[tokio::test] async fn fail_if_param_(deoxys: JsonRpcClient) { - let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction { max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], @@ -65,14 +66,15 @@ async fn fail_if_param_(deoxys: JsonRpcClient) { assert_matches!( response_deoxys, - Err(ProviderError::StarknetError(StarknetError::InvalidTransactionNonce)) + Err(ProviderError::StarknetError( + StarknetError::InvalidTransactionNonce + )) ); } #[rstest] #[tokio::test] async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient) { - let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction { max_fee: FieldElement::from_hex_be("0x000000").unwrap(), //here max_fee is insufficient signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], @@ -89,14 +91,15 @@ async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient) { assert_matches!( response_deoxys, - Err(ProviderError::StarknetError(StarknetError::InsufficientMaxFee)) + Err(ProviderError::StarknetError( + StarknetError::InsufficientMaxFee + )) ); } #[rstest] #[tokio::test] async fn fail_if_invalid_transaction_nonce(deoxys: JsonRpcClient) { - let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction { max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], @@ -113,14 +116,15 @@ async fn fail_if_invalid_transaction_nonce(deoxys: JsonRpcClient) assert_matches!( response_deoxys, - Err(ProviderError::StarknetError(StarknetError::InvalidTransactionNonce)) + Err(ProviderError::StarknetError( + StarknetError::InvalidTransactionNonce + )) ); } #[rstest] #[tokio::test] async fn works_ok(deoxys: JsonRpcClient) { - let valid_deploy_account_transaction = BroadcastedDeployAccountTransaction { max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(), signature: vec![FieldElement::from_hex_be("signature_array").unwrap()], @@ -139,18 +143,17 @@ async fn works_ok(deoxys: JsonRpcClient) { let result = response_deoxys.unwrap(); //Now, if the transaction is valid, the rpc call response contain the transaction hash - let transaction_submitted_hash = response_deoxys.expect("Transaction submition failed").transaction_hash; + let transaction_submitted_hash = response_deoxys + .expect("Transaction submition failed") + .transaction_hash; //Wait for the transaction to be added to the chain thread::sleep(Duration::from_secs(15)); - + //Let's check the transaction status - let transaction_status = deoxys - .get_transaction_status(transaction_submitted_hash) - .await; - - assert_matches!( - transaction_status.unwrap(), - TransactionStatus::Received - ); -} \ No newline at end of file + let transaction_status = deoxys + .get_transaction_status(transaction_submitted_hash) + .await; + + assert_matches!(transaction_status.unwrap(), TransactionStatus::Received); +} diff --git a/unit_tests/tests/test_trace_block_transactions.rs b/unit_tests/tests/test_trace_block_transactions.rs index 8486335..81d1782 100644 --- a/unit_tests/tests/test_trace_block_transactions.rs +++ b/unit_tests/tests/test_trace_block_transactions.rs @@ -3,10 +3,10 @@ mod common; use common::*; -use std::assert_matches::assert_matches; use rand::Rng; +use std::assert_matches::assert_matches; -use starknet_core::types::{FieldElement, StarknetError, BlockId}; +use starknet_core::types::{BlockId, FieldElement, StarknetError}; use starknet_providers::{ jsonrpc::{HttpTransport, JsonRpcClient}, Provider, ProviderError, @@ -15,29 +15,34 @@ use starknet_providers::{ #[rstest] #[tokio::test] async fn fail_non_existing_block(deoxys: JsonRpcClient) { - assert_matches!( - deoxys.trace_block_transactions(BlockId::Hash(FieldElement::ZERO)).await, + 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, pathfinder: JsonRpcClient) { - +async fn works_ok_for_block_10000( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { 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, pathfinder: JsonRpcClient) { - +async fn works_ok_for_block_300000( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { let block_number = BlockId::Number(300000); let deoxys_trace = deoxys.trace_block_transactions(block_number).await; @@ -48,7 +53,10 @@ async fn works_ok_for_block_300000(deoxys: JsonRpcClient, pathfin #[rstest] #[tokio::test] -async fn works_ok_for_random_block(deoxys: JsonRpcClient, pathfinder: JsonRpcClient) { +async fn works_ok_for_random_block( + deoxys: JsonRpcClient, + pathfinder: JsonRpcClient, +) { let mut rng = rand::thread_rng(); let random_block_number = rng.gen_range(100000..602000); @@ -60,4 +68,4 @@ async fn works_ok_for_random_block(deoxys: JsonRpcClient, pathfin println!("block choose is: {:?}", block_number); assert_matches!(deoxys_trace, _pathfinder_trace); -} \ No newline at end of file +}