Skip to content

Commit

Permalink
feat: 🎨 fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbelleng committed Mar 11, 2024
1 parent 87e1a1a commit e401f7c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 48 deletions.
25 changes: 11 additions & 14 deletions unit_tests/tests/test_add_invoke_transaction.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::{BroadcastedInvokeTransaction, FieldElement, StarknetError, TransactionStatus};
use starknet_core::types::{
BroadcastedInvokeTransaction, FieldElement, StarknetError, TransactionStatus,
};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, ProviderError,
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -43,7 +45,6 @@ use std::time::Duration;
#[rstest]
#[tokio::test]
async fn fail_if_param_(deoxys: JsonRpcClient<HttpTransport>) {

let invalid_invoke_transaction = BroadcastedInvokeTransaction {
sender_address: FieldElement::from_hex_be("valid_address").unwrap(),
calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()],
Expand All @@ -68,7 +69,6 @@ async fn fail_if_param_(deoxys: JsonRpcClient<HttpTransport>) {
#[rstest]
#[tokio::test]
async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient<HttpTransport>) {

let invalid_invoke_transaction = BroadcastedInvokeTransaction {
sender_address: FieldElement::from_hex_be("valid_address").unwrap(),
calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()],
Expand All @@ -93,7 +93,6 @@ async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient<HttpTransport>) {
#[rstest]
#[tokio::test]
async fn fail_if_bad_calldata(deoxys: JsonRpcClient<HttpTransport>) {

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
Expand All @@ -118,7 +117,6 @@ async fn fail_if_bad_calldata(deoxys: JsonRpcClient<HttpTransport>) {
#[rstest]
#[tokio::test]
async fn works_ok_with_valid_params(deoxys: JsonRpcClient<HttpTransport>) {

let valid_invoke_transaction = BroadcastedInvokeTransaction {
sender_address: FieldElement::from_hex_be("valid_address").unwrap(),
calldata: vec![FieldElement::from_hex_be("calldata_array").unwrap()],
Expand All @@ -134,7 +132,9 @@ async fn works_ok_with_valid_params(deoxys: JsonRpcClient<HttpTransport>) {
.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));
Expand All @@ -144,8 +144,5 @@ async fn works_ok_with_valid_params(deoxys: JsonRpcClient<HttpTransport>) {
.get_transaction_status(transaction_submitted_hash)
.await;

assert_matches!(
transaction_status.unwrap(),
TransactionStatus::Received
);
}
assert_matches!(transaction_status.unwrap(), TransactionStatus::Received);
}
49 changes: 26 additions & 23 deletions unit_tests/tests/test_deploy_account_transaction.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::{BroadcastedDeployAccountTransaction, FieldElement, StarknetError, TransactionStatus};
use starknet_core::types::{
BroadcastedDeployAccountTransaction, FieldElement, StarknetError, TransactionStatus,
};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, ProviderError,
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -48,7 +50,6 @@ use std::time::Duration;
#[rstest]
#[tokio::test]
async fn fail_if_param_(deoxys: JsonRpcClient<HttpTransport>) {

let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction {
max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(),
signature: vec![FieldElement::from_hex_be("signature_array").unwrap()],
Expand All @@ -65,14 +66,15 @@ async fn fail_if_param_(deoxys: JsonRpcClient<HttpTransport>) {

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<HttpTransport>) {

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()],
Expand All @@ -89,14 +91,15 @@ async fn fail_if_insufficient_max_fee(deoxys: JsonRpcClient<HttpTransport>) {

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<HttpTransport>) {

let invalid_deploy_account_transaction = BroadcastedDeployAccountTransaction {
max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(),
signature: vec![FieldElement::from_hex_be("signature_array").unwrap()],
Expand All @@ -113,14 +116,15 @@ async fn fail_if_invalid_transaction_nonce(deoxys: JsonRpcClient<HttpTransport>)

assert_matches!(
response_deoxys,
Err(ProviderError::StarknetError(StarknetError::InvalidTransactionNonce))
Err(ProviderError::StarknetError(
StarknetError::InvalidTransactionNonce
))
);
}

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

let valid_deploy_account_transaction = BroadcastedDeployAccountTransaction {
max_fee: FieldElement::from_hex_be("0x0ffffffff").unwrap(),
signature: vec![FieldElement::from_hex_be("signature_array").unwrap()],
Expand All @@ -139,18 +143,17 @@ async fn works_ok(deoxys: JsonRpcClient<HttpTransport>) {
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
);
}
let transaction_status = deoxys
.get_transaction_status(transaction_submitted_hash)
.await;

assert_matches!(transaction_status.unwrap(), TransactionStatus::Received);
}
30 changes: 19 additions & 11 deletions unit_tests/tests/test_trace_block_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,29 +15,34 @@ use starknet_providers::{
#[rstest]
#[tokio::test]
async fn fail_non_existing_block(deoxys: JsonRpcClient<HttpTransport>) {

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<HttpTransport>, pathfinder: JsonRpcClient<HttpTransport>) {

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>) {

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;
Expand All @@ -48,7 +53,10 @@ async fn works_ok_for_block_300000(deoxys: JsonRpcClient<HttpTransport>, pathfin

#[rstest]
#[tokio::test]
async fn works_ok_for_random_block(deoxys: JsonRpcClient<HttpTransport>, pathfinder: JsonRpcClient<HttpTransport>) {
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);

Expand All @@ -60,4 +68,4 @@ async fn works_ok_for_random_block(deoxys: JsonRpcClient<HttpTransport>, pathfin
println!("block choose is: {:?}", block_number);

assert_matches!(deoxys_trace, _pathfinder_trace);
}
}

0 comments on commit e401f7c

Please sign in to comment.