Skip to content

Commit

Permalink
refacto consts
Browse files Browse the repository at this point in the history
  • Loading branch information
antiyro committed Jun 17, 2024
1 parent 967f8e8 commit 74e51d1
Show file tree
Hide file tree
Showing 36 changed files with 331 additions and 156 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ use starknet_providers::{jsonrpc::{HttpTransport, JsonRpcClient}, Provider};
#[rstest]
#[tokio::test]
async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let response_deoxys = deoxys.block_number().await.expect("Deoxys : Error while getting the block number");
let response_pathfinder = pathfinder.block_number().await.expect("RPC : Error while getting the block number");
Expand Down
89 changes: 89 additions & 0 deletions rustc-ice-2024-06-17T15_15_44-57848.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions unit_tests/src/constants/mainnet/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///
/// Starknet Mainnet block number versions.
///
pub const BLOCK_0: u64 = 0;
pub const BLOCK_0_9_1: u64 = 3799;
pub const BLOCK_0_10_0: u64 = 4883;
pub const BLOCK_0_10_1: u64 = 6570;
pub const BLOCK_0_10_2: u64 = 12268;
pub const BLOCK_0_10_3: u64 = 16575;
pub const BLOCK_0_11_0: u64 = 28613;
pub const BLOCK_0_11_0_2: u64 = 43851;
pub const BLOCK_0_11_1: u64 = 61394;
pub const BLOCK_0_11_2: u64 = 68096;
pub const BLOCK_0_12_0: u64 = 103129;
pub const BLOCK_0_12_1: u64 = 164901;
pub const BLOCK_0_12_2: u64 = 194410;
pub const BLOCK_0_12_3: u64 = 472644;
pub const BLOCK_0_13_0: u64 = 501514;
pub const BLOCK_0_13_1: u64 = 607878;
54 changes: 54 additions & 0 deletions unit_tests/src/constants/mainnet/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
///
/// Contract address for StarkGate ETH starknet bridge.
///
/// Details concerning available methods can be found on [StarkScan](https://starkscan.co/contract/0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7#read-write-contract)
///
pub const STARKGATE_ETH_BRIDGE_ADDR: &str =
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";

///
/// Contract address for Jediswap exchange.
///
/// Details concerning available methods can be found on [StarkScan](https://starkscan.co/contract/0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023#read-write-contract):
///
pub const JEDI_SWAP_ADDR: &str =
"0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023";

///
/// Contract address for Starkgate USDC on Starknet.
///
/// Details concerning this coin can be found on [StarkScan](https://starkscan.co/token/0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8):
///
pub const STARKGATE_USDC: &str =
"0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8";

///
/// Contract address fpr Starkgate Ether on Starknet.
///
/// Detail concerning this coin can be found on [StarkScan](https://starkscan.co/token/0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7):
///
pub const STARKGATE_ETHER: &str =
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";

///
/// Random ERC721 Starknet contract address.
///
/// Details concerning this contract can be found on [StarkScan](https://starkscan.co/contract/0x07fa9a8eacb89fb6cd0c7fe557e71c42a4b181ba328a9a04958136e6469c4e00)
///
pub const CONTRACT_ERC721: &str =
"0x07fa9a8eacb89fb6cd0c7fe557e71c42a4b181ba328a9a04958136e6469c4e00";

///
/// Random ERC20 Starknet contract address.
///
/// Details concerning this contract can be found on [StarkScan](https://starkscan.co/contract/0x04a5fdce70877b77f03aea8a29259176f88d5bea9d0ad8c0118f5316425e6ba0)
///
pub const CONTRACT_ERC20: &str =
"0x04a5fdce70877b77f03aea8a29259176f88d5bea9d0ad8c0118f5316425e6ba0";

///
/// Random ACCOUNT Starknet contract address.
///
/// Details concerning this contract can be found on [StarkScan](https://starkscan.co/contract/0x046ef77bd47ba7b1424ba2b2b1442d14168ac3dc6897032bf491ecbafd5f5c32)
pub const CONTRACT_ACCOUNT: &str =
"0x046ef77bd47ba7b1424ba2b2b1442d14168ac3dc6897032bf491ecbafd5f5c32";
4 changes: 4 additions & 0 deletions unit_tests/src/constants/mainnet/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod block;
pub mod transaction;
pub mod network;
pub mod contract;
3 changes: 3 additions & 0 deletions unit_tests/src/constants/mainnet/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub const DEOXYS: &str = "deoxys";
pub const PATHFINDER: &str = "pathfinder";
pub const JUNO: &str = "juno";
Empty file.
2 changes: 2 additions & 0 deletions unit_tests/src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod mainnet;
pub mod sepolia;
19 changes: 19 additions & 0 deletions unit_tests/src/constants/sepolia/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///
/// Starknet Mainnet block number versions.
///
pub const BLOCK_0: u64 = 0;
pub const BLOCK_0_9_1: u64 = 3799;
pub const BLOCK_0_10_0: u64 = 4883;
pub const BLOCK_0_10_1: u64 = 6570;
pub const BLOCK_0_10_2: u64 = 12268;
pub const BLOCK_0_10_3: u64 = 16575;
pub const BLOCK_0_11_0: u64 = 28613;
pub const BLOCK_0_11_0_2: u64 = 43851;
pub const BLOCK_0_11_1: u64 = 61394;
pub const BLOCK_0_11_2: u64 = 68096;
pub const BLOCK_0_12_0: u64 = 103129;
pub const BLOCK_0_12_1: u64 = 164901;
pub const BLOCK_0_12_2: u64 = 194410;
pub const BLOCK_0_12_3: u64 = 472644;
pub const BLOCK_0_13_0: u64 = 501514;
pub const BLOCK_0_13_1: u64 = 607878;
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,3 @@ pub const ERR_PATHFINDER: &str = "Error waiting for response from Pathfinder cli
pub const SPEC_0_7_0: &str = "0.7.0";
pub const SPEC_0_7_1: &str = "0.7.1";

///
/// Starknet block number versions.
///
pub const BLOCK_0: u64 = 0;
pub const BLOCK_0_9_1: u64 = 3799;
pub const BLOCK_0_10_0: u64 = 4883;
pub const BLOCK_0_10_1: u64 = 6570;
pub const BLOCK_0_10_2: u64 = 12268;
pub const BLOCK_0_10_3: u64 = 16575;
pub const BLOCK_0_11_0: u64 = 28613;
pub const BLOCK_0_11_0_2: u64 = 43851;
pub const BLOCK_0_11_1: u64 = 61394;
pub const BLOCK_0_11_2: u64 = 68096;
pub const BLOCK_0_12_0: u64 = 103129;
pub const BLOCK_0_12_1: u64 = 164901;
pub const BLOCK_0_12_2: u64 = 194410;
pub const BLOCK_0_12_3: u64 = 472644;
pub const BLOCK_0_13_0: u64 = 501514;
pub const BLOCK_0_13_1: u64 = 607878;
Empty file.
4 changes: 4 additions & 0 deletions unit_tests/src/constants/sepolia/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod block;
pub mod transaction;
pub mod network;
pub mod contract;
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions unit_tests/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub fn clients(
juno: JsonRpcClient<HttpTransport>,
) -> HashMap<String, JsonRpcClient<HttpTransport>> {
map! {
String::from(DEOXYS) => deoxys,
String::from(PATHFINDER) => pathfinder,
String::from(JUNO) => juno,
String::from(mainnet::network::DEOXYS) => deoxys,
String::from(mainnet::network::PATHFINDER) => pathfinder,
String::from(mainnet::network::JUNO) => juno,
}
}
10 changes: 5 additions & 5 deletions unit_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(assert_matches)]

use constants::*;
use starknet_accounts::{Account, Call, ConnectedAccount, Execution, SingleOwnerAccount};
use starknet_core::chain_id;
use starknet_core::types::BroadcastedInvokeTransaction;
Expand All @@ -10,6 +9,7 @@ use starknet_core::{
};
use starknet_providers::{jsonrpc::HttpTransport, JsonRpcClient};
use starknet_signers::{LocalWallet, SigningKey};
use constants::mainnet;

pub mod constants;
pub mod fixtures;
Expand All @@ -28,10 +28,10 @@ impl TransactionFactory for OkTransactionFactory {
max_fee: FieldElement::ZERO,
signature: vec![],
nonce: nonce.unwrap_or(FieldElement::ZERO),
sender_address: FieldElement::from_hex_be(ACCOUNT_CONTRACT).unwrap(),
sender_address: FieldElement::from_hex_be(mainnet::contract::CONTRACT_ACCOUNT).unwrap(),
calldata: vec![
FieldElement::from_hex_be(TEST_CONTRACT_ADDRESS).unwrap(),
get_selector_from_name("sqrt").unwrap(),
FieldElement::from_hex_be(mainnet::contract::CONTRACT_ERC20).unwrap(),
get_selector_from_name("transfer").unwrap(),
FieldElement::from_hex_be("1").unwrap(),
FieldElement::from(81u8),
],
Expand Down Expand Up @@ -70,7 +70,7 @@ impl TransactionFactory for MaxFeeTransactionFactory {
)
.unwrap(),
calldata: vec![
FieldElement::from_hex_be(TEST_CONTRACT_ADDRESS).unwrap(),
FieldElement::from_hex_be(mainnet::contract::CONTRACT_ERC20).unwrap(),
get_selector_from_name("sqrt").unwrap(),
FieldElement::from_hex_be("1").unwrap(),
FieldElement::from(81u8),
Expand Down
6 changes: 3 additions & 3 deletions unit_tests/tests/test_block_hash_and_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use colored::*;
#[rstest]
#[tokio::test]
async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let juno = &clients[JUNO];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];
let juno = &clients[mainnet::network::JUNO];

let deoxys_responce = deoxys
.block_hash_and_number()
Expand Down
6 changes: 3 additions & 3 deletions unit_tests/tests/test_block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use starknet_providers::{
#[rstest]
#[tokio::test]
async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let juno = &clients[JUNO];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];
let juno = &clients[mainnet::network::JUNO];

let response_deoxys = deoxys
.block_number()
Expand Down
30 changes: 15 additions & 15 deletions unit_tests/tests/test_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use starknet_providers::{
#[rstest]
#[tokio::test]
async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let response_deoxys = deoxys
.call(
Expand Down Expand Up @@ -74,8 +74,8 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
#[rstest]
#[tokio::test]
async fn fail_non_existing_contract(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let response_deoxys = deoxys
.call(
Expand Down Expand Up @@ -128,7 +128,7 @@ async fn fail_non_existing_contract(clients: HashMap<String, JsonRpcClient<HttpT
async fn fail_invalid_contract_entry_point_selector(
clients: HashMap<String, JsonRpcClient<HttpTransport>>,
) {
let deoxys = &clients[DEOXYS];
let deoxys = &clients[mainnet::network::DEOXYS];

let response_deoxys = deoxys
.call(
Expand Down Expand Up @@ -164,8 +164,8 @@ async fn fail_invalid_contract_entry_point_selector(
#[rstest]
#[tokio::test]
async fn fail_missing_contract_call_data(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let response_deoxys = deoxys
.call(
Expand Down Expand Up @@ -220,7 +220,7 @@ async fn fail_missing_contract_call_data(clients: HashMap<String, JsonRpcClient<
#[rstest]
#[tokio::test]
async fn fail_invalid_contract_call_data(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let deoxys = &clients[mainnet::network::DEOXYS];

let response_deoxys = deoxys
.call(
Expand Down Expand Up @@ -249,7 +249,7 @@ async fn fail_invalid_contract_call_data(clients: HashMap<String, JsonRpcClient<
#[rstest]
#[tokio::test]
async fn fail_too_many_call_data(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let deoxys = &clients[mainnet::network::DEOXYS];

let response_deoxys = deoxys
.call(
Expand Down Expand Up @@ -292,8 +292,8 @@ async fn fail_too_many_call_data(clients: HashMap<String, JsonRpcClient<HttpTran
#[rstest]
#[tokio::test]
async fn work_correct_call(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let response_deoxys = deoxys
.call(
Expand Down Expand Up @@ -334,8 +334,8 @@ async fn work_correct_call(clients: HashMap<String, JsonRpcClient<HttpTransport>
#[rstest]
#[tokio::test]
async fn work_correct_call_with_args(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let block_number = get_block_setting();

Expand Down Expand Up @@ -378,8 +378,8 @@ async fn work_correct_call_with_args(clients: HashMap<String, JsonRpcClient<Http
#[rstest]
#[tokio::test]
async fn work_with_multiple_args(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let block_number = get_block_setting();

Expand Down
4 changes: 2 additions & 2 deletions unit_tests/tests/test_chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::collections::HashMap;
#[rstest]
#[tokio::test]
async fn chain_id(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let response_deoxys = deoxys
.chain_id()
Expand Down
8 changes: 4 additions & 4 deletions unit_tests/tests/test_estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use unit_tests::{BadTransactionFactory, OkTransactionFactory, TransactionFactory
#[tokio::test]
#[ignore = "Fix failing unwrap due to empty constant"]
async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let deoxys = &clients[mainnet::network::DEOXYS];

let ok_invoke_transaction = OkTransactionFactory::build(Some(FieldElement::ZERO));
let simulation_flag = vec![SimulationFlagForEstimateFee::SkipValidate];
Expand Down Expand Up @@ -52,7 +52,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
async fn fail_if_one_txn_cannot_be_executed(
clients: HashMap<String, JsonRpcClient<HttpTransport>>,
) {
let deoxys = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::PATHFINDER];

let bad_invoke_transaction = BadTransactionFactory::build(None);
let simulate_flag = vec![SimulationFlagForEstimateFee::SkipValidate];
Expand Down Expand Up @@ -82,8 +82,8 @@ async fn fail_if_one_txn_cannot_be_executed(
#[tokio::test]
#[ignore = "Fix failing unwrap due to empty constant"]
async fn works_ok(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];
let deoxys = &clients[mainnet::network::DEOXYS];
let pathfinder = &clients[mainnet::network::PATHFINDER];

let block_number = get_block_setting();

Expand Down
Loading

0 comments on commit 74e51d1

Please sign in to comment.