Skip to content

Commit

Permalink
style: 🎨 fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbelleng committed Jan 30, 2024
1 parent 878766a commit 4bf0904
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
5 changes: 4 additions & 1 deletion unit_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ impl TransactionFactory for MaxFeeTransactionFactory {
max_fee: FieldElement::from_hex_be("0x100000000000000000000000000000000").unwrap(),
signature: vec![],
nonce: FieldElement::ZERO,
sender_address: FieldElement::from_hex_be("0x019f57133d6a46990231a58a8f45be87405b4494161bf9ac7b25bd14de6e4d40").unwrap(),
sender_address: FieldElement::from_hex_be(
"0x019f57133d6a46990231a58a8f45be87405b4494161bf9ac7b25bd14de6e4d40",
)
.unwrap(),
calldata: vec![
FieldElement::from_hex_be(TEST_CONTRACT_ADDRESS).unwrap(),
get_selector_from_name("sqrt").unwrap(),
Expand Down
42 changes: 29 additions & 13 deletions unit_tests/tests/test_estimate_message_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
mod common;
use common::*;

use reqwest::Client;
use reqwest::Error as ReqwestError;
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_json::Error as SerdeError;
use starknet_core::types::{BlockId, BlockTag, EthAddress, FieldElement, MsgFromL1, StarknetError};
use starknet_providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, ProviderError,
};
use std::assert_matches::assert_matches;
use std::collections::HashMap;
use reqwest::Client;
use serde_json::json;
use serde::{Deserialize, Serialize};
use std::convert::From;
use serde_json::Error as SerdeError;
use reqwest::Error as ReqwestError;
use std::fmt;

/// Test for the `get_state_update` Deoxys RPC method
Expand All @@ -32,7 +32,7 @@ use std::fmt;
// * `contract_not_found` - If the contract is not found or invalid
// * `contract_error` - If the contract is found but the message is invalid

/// Following tests runs with various example of messages from L1,
/// Following tests runs with various example of messages from L1,
/// you can of course modify address and payload to test with your own message.
pub fn get_message_from_l1(
Expand All @@ -56,7 +56,10 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
let deoxys = &clients[PATHFINDER];

let payload_message: Vec<FieldElement> = vec![];
let contract_address = FieldElement::from_hex_be("0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7").unwrap();
let contract_address = FieldElement::from_hex_be(
"0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7",
)
.unwrap();
let message = get_message_from_l1(
"0xae0ee0a63a2ce6baeeffe56e7714fb4efe48d419", //ETH address
contract_address,
Expand Down Expand Up @@ -107,7 +110,10 @@ async fn fail_contract_error(clients: HashMap<String, JsonRpcClient<HttpTranspor
//On this test, the contract address must be valid,
//but the from_address, entry_point_selector or the payload must be invalid
let payload_message: Vec<FieldElement> = vec![];
let contract_address = FieldElement::from_hex_be("0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7").unwrap();
let contract_address = FieldElement::from_hex_be(
"0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7",
)
.unwrap();
let message = get_message_from_l1(
"0xae0ee0a63a2ce6baeeffe56e7714fb4efe48d419",
contract_address,
Expand Down Expand Up @@ -190,7 +196,8 @@ async fn estimate_message_fee_works_ok() -> Result<(), CallError> {
]
});

let response = client.post(url)
let response = client
.post(url)
.header("accept", "application/json")
.header("content-type", "application/json")
.json(&request_body)
Expand All @@ -199,10 +206,19 @@ async fn estimate_message_fee_works_ok() -> Result<(), CallError> {

let body = response.text().await?;
let parsed_response: ApiResponse = serde_json::from_str(&body).map_err(CallError::from)?;

assert_eq!(&parsed_response.result.gas_consumed, "0x4bd0", "Unexpected value for Gas Consumed");
assert_eq!(&parsed_response.result.gas_price, "0x34b9d74ac", "Unexpected value for Gas Price");
assert_eq!(&parsed_response.result.overall_fee, "0xf9d4911d2fc0", "Unexpected value for Overall Fee");

assert_eq!(
&parsed_response.result.gas_consumed, "0x4bd0",
"Unexpected value for Gas Consumed"
);
assert_eq!(
&parsed_response.result.gas_price, "0x34b9d74ac",
"Unexpected value for Gas Price"
);
assert_eq!(
&parsed_response.result.overall_fee, "0xf9d4911d2fc0",
"Unexpected value for Overall Fee"
);

Ok(())
}

0 comments on commit 4bf0904

Please sign in to comment.