Skip to content

Commit

Permalink
feat: 🎨 fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbelleng committed Mar 16, 2024
1 parent ea41f53 commit 57163f3
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 113 deletions.
19 changes: 4 additions & 15 deletions unit_tests/tests/test_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use starknet_core::{
types::{BlockId, BlockTag, ContractErrorData, FieldElement, FunctionCall, StarknetError},
utils::get_selector_from_name,
};
use starknet_providers::{jsonrpc::{HttpTransport, JsonRpcError}, JsonRpcClient, Provider};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcError},
JsonRpcClient, Provider,
};

///
/// Unit test for `starknet_call`
Expand Down Expand Up @@ -126,7 +129,6 @@ async fn fail_invalid_contract_entry_point_selector(
clients: HashMap<String, JsonRpcClient<HttpTransport>>,
) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];

let response_deoxys = deoxys
.call(
Expand All @@ -140,18 +142,6 @@ async fn fail_invalid_contract_entry_point_selector(
.await
.err();

let response_pathfinder = pathfinder
.call(
FunctionCall {
contract_address: FieldElement::from_hex_be(STARKGATE_ETH_BRIDGE_ADDR).unwrap(),
entry_point_selector: FieldElement::ZERO,
calldata: vec![],
},
BlockId::Tag(BlockTag::Latest),
)
.await
.err();

let expected_error = JsonRpcError {
code: -32602,
message: "Invalid params".to_string(),
Expand Down Expand Up @@ -201,7 +191,6 @@ async fn fail_missing_contract_call_data(clients: HashMap<String, JsonRpcClient<
.await
.err();


let error_reason = ContractErrorData {
revert_error: "ContractError".to_string(),
};
Expand Down
9 changes: 3 additions & 6 deletions unit_tests/tests/test_estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use common::*;
use starknet_core::types::{BlockId, BlockTag, FieldElement, StarknetError};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient, JsonRpcError},
Provider
Provider,
};
use std::collections::HashMap;
use unit_tests::{BadTransactionFactory, OkTransactionFactory, TransactionFactory};
Expand All @@ -32,10 +32,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::InvalidTransactionHash,
);
let is_correct_error = checking_error_format(&error, StarknetError::InvalidTransactionHash);

assert!(
is_correct_error,
Expand Down Expand Up @@ -66,7 +63,7 @@ async fn fail_if_one_txn_cannot_be_executed(
message: "Invalid params".to_string(),
data: None,
};

assert!(
response_deoxys.is_err(),
"Expected an error response, but got Ok. Expected error: {:?}",
Expand Down
27 changes: 9 additions & 18 deletions unit_tests/tests/test_estimate_message_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

mod common;
use common::*;
use starknet_core::types::{BlockId, BlockTag, EthAddress, FieldElement, MsgFromL1, StarknetError, ContractErrorData};
use starknet_core::types::{
BlockId, BlockTag, ContractErrorData, EthAddress, FieldElement, MsgFromL1, StarknetError,
};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider,
Expand Down Expand Up @@ -65,10 +67,7 @@ async fn fail_non_existing_block(deoxys: JsonRpcClient<HttpTransport>) {
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand Down Expand Up @@ -107,15 +106,10 @@ async fn fail_contract_not_found(deoxys: JsonRpcClient<HttpTransport>) {
};

if let Err(error) = response_deoxys {
let is_contract_not_found = checking_error_format(
&error,
StarknetError::ContractNotFound,
);
let is_contract_not_found = checking_error_format(&error, StarknetError::ContractNotFound);

let is_contract_error = checking_error_format(
&error,
StarknetError::ContractError(revert_error)
);
let is_contract_error =
checking_error_format(&error, StarknetError::ContractError(revert_error));

assert!(
is_contract_not_found || is_contract_error,
Expand All @@ -124,7 +118,6 @@ async fn fail_contract_not_found(deoxys: JsonRpcClient<HttpTransport>) {
}
}


#[rstest]
#[tokio::test]
async fn fail_contract_error(deoxys: JsonRpcClient<HttpTransport>) {
Expand Down Expand Up @@ -156,10 +149,8 @@ async fn fail_contract_error(deoxys: JsonRpcClient<HttpTransport>) {
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::ContractError(error_reason),
);
let is_correct_error =
checking_error_format(&error, StarknetError::ContractError(error_reason));

assert!(
is_correct_error,
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/tests/test_get_block_transaction_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider,
};
use std::sync::Arc;
use std::collections::HashMap;
use std::sync::Arc;
use unit_tests::constants::{DEOXYS, PATHFINDER};

#[rstest]
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/tests/test_get_block_with_tx_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod common;
use common::*;
use starknet_core::types::MaybePendingBlockWithTxHashes;

use std::sync::Arc;
use std::collections::HashMap;
use std::sync::Arc;

use starknet_core::types::{BlockId, BlockTag, FieldElement, StarknetError};
use starknet_providers::{
Expand Down
12 changes: 3 additions & 9 deletions unit_tests/tests/test_get_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand All @@ -52,15 +49,12 @@ async fn fail_non_existing_class_hash(clients: HashMap<String, JsonRpcClient<Htt
.await;

assert!(
response_deoxys.is_ok(),
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::ClassHashNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::ClassHashNotFound);

assert!(
is_correct_error,
Expand Down
5 changes: 1 addition & 4 deletions unit_tests/tests/test_get_class_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand Down
5 changes: 4 additions & 1 deletion unit_tests/tests/test_get_class_hash_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use common::*;
use std::collections::HashMap;

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

///
/// Unit test for `starknet_getClassHashAt`
Expand Down
5 changes: 4 additions & 1 deletion unit_tests/tests/test_get_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use anyhow::anyhow;
use common::*;
use starknet::macros::{felt_hex, selector};
use starknet_core::types::{BlockId, EventFilter, EventsPage, FieldElement};
use starknet_providers::{jsonrpc::{HttpTransport, JsonRpcError}, JsonRpcClient, Provider, ProviderError};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcError},
JsonRpcClient, Provider, ProviderError,
};
use tokio::task::JoinSet;

///
Expand Down
10 changes: 2 additions & 8 deletions unit_tests/tests/test_get_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand Down Expand Up @@ -83,10 +80,7 @@ async fn fail_non_existing_contract(clients: HashMap<String, JsonRpcClient<HttpT
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::ContractNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::ContractNotFound);

assert!(
is_correct_error,
Expand Down
5 changes: 1 addition & 4 deletions unit_tests/tests/test_get_state_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand Down
10 changes: 2 additions & 8 deletions unit_tests/tests/test_get_storage_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand Down Expand Up @@ -70,10 +67,7 @@ async fn fail_non_existing_contract(clients: HashMap<String, JsonRpcClient<HttpT
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::ContractNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::ContractNotFound);

assert!(
is_correct_error,
Expand Down
11 changes: 3 additions & 8 deletions unit_tests/tests/test_get_transaction_by_block_id_and_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ async fn fail_non_existent_block(clients: HashMap<String, JsonRpcClient<HttpTran
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand Down Expand Up @@ -61,10 +58,8 @@ async fn fail_non_existent_block_index(clients: HashMap<String, JsonRpcClient<Ht
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::InvalidTransactionIndex,
);
let is_correct_error =
checking_error_format(&error, StarknetError::InvalidTransactionIndex);

assert!(
is_correct_error,
Expand Down
6 changes: 2 additions & 4 deletions unit_tests/tests/test_get_transaction_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ async fn fail_non_existing_transaction(clients: HashMap<String, JsonRpcClient<Ht
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::TransactionHashNotFound,
);
let is_correct_error =
checking_error_format(&error, StarknetError::TransactionHashNotFound);

assert!(
is_correct_error,
Expand Down
11 changes: 4 additions & 7 deletions unit_tests/tests/test_get_transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ async fn fail_invalid_transaction_hash(clients: HashMap<String, JsonRpcClient<Ht
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::TransactionHashNotFound,
);
let is_correct_error =
checking_error_format(&error, StarknetError::TransactionHashNotFound);

assert!(
is_correct_error,
Expand All @@ -55,9 +53,8 @@ async fn work_with_hash(
.await
.unwrap();


println!("✅ {:?}", response_deoxys);
println!("✅ {:?}", response_pathfinder);
println!("✅ {:?}", response_deoxys);
println!("✅ {:?}", response_pathfinder);
assert_eq!(response_deoxys, response_pathfinder);
}

Expand Down
6 changes: 2 additions & 4 deletions unit_tests/tests/test_get_transaction_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ async fn fail_invalid_transaction(clients: HashMap<String, JsonRpcClient<HttpTra
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::TransactionHashNotFound,
);
let is_correct_error =
checking_error_format(&error, StarknetError::TransactionHashNotFound);

assert!(
is_correct_error,
Expand Down
15 changes: 5 additions & 10 deletions unit_tests/tests/test_simulate_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod common;
use common::*;

use starknet_core::types::{
BlockId, BlockTag, BroadcastedInvokeTransaction, BroadcastedTransaction, FieldElement,
SimulationFlag, StarknetError, ContractErrorData,
BlockId, BlockTag, BroadcastedInvokeTransaction, BroadcastedTransaction, ContractErrorData,
FieldElement, SimulationFlag, StarknetError,
};
use starknet_core::utils::get_selector_from_name;
use starknet_providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider};
Expand Down Expand Up @@ -76,10 +76,7 @@ async fn fail_non_existing_block(deoxys: JsonRpcClient<HttpTransport>) {
);

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::BlockNotFound,
);
let is_correct_error = checking_error_format(&error, StarknetError::BlockNotFound);

assert!(
is_correct_error,
Expand Down Expand Up @@ -275,10 +272,8 @@ async fn fail_if_one_txn_cannot_be_executed(deoxys: JsonRpcClient<HttpTransport>
};

if let Err(error) = response_deoxys {
let is_correct_error = checking_error_format(
&error,
StarknetError::ContractError(error_reason),
);
let is_correct_error =
checking_error_format(&error, StarknetError::ContractError(error_reason));

assert!(
is_correct_error,
Expand Down
Loading

0 comments on commit 57163f3

Please sign in to comment.