From 9884a64dee17636ea6c9242d69c9c5301e9bd0b2 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Wed, 13 Nov 2024 16:12:39 +0200 Subject: [PATCH] chore: share the test util get_absolute_path --- Cargo.lock | 1 + crates/mempool_test_utils/src/lib.rs | 8 -------- crates/mempool_test_utils/src/starknet_api_test_utils.rs | 3 +-- crates/papyrus_config/Cargo.toml | 1 + crates/papyrus_config/src/config_test.rs | 2 +- crates/papyrus_node/src/config/config_test.rs | 2 +- crates/papyrus_test_utils/src/lib.rs | 6 ------ crates/starknet_api/src/test_utils.rs | 7 ++++++- crates/starknet_sequencer_node/src/config/config_test.rs | 2 +- crates/starknet_sierra_compile/src/compile_test.rs | 3 ++- 10 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c23bd611598..b3124f6b28f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7223,6 +7223,7 @@ dependencies = [ "papyrus_test_utils", "serde", "serde_json", + "starknet_api", "strum_macros 0.25.3", "tempfile", "thiserror", diff --git a/crates/mempool_test_utils/src/lib.rs b/crates/mempool_test_utils/src/lib.rs index 860e758c536..6500101322c 100644 --- a/crates/mempool_test_utils/src/lib.rs +++ b/crates/mempool_test_utils/src/lib.rs @@ -1,6 +1,3 @@ -use std::env; -use std::path::{Path, PathBuf}; - pub mod starknet_api_test_utils; pub const TEST_FILES_FOLDER: &str = "crates/mempool_test_utils/test_files"; @@ -8,8 +5,3 @@ pub const CONTRACT_CLASS_FILE: &str = "contract_class.json"; pub const COMPILED_CLASS_HASH_OF_CONTRACT_CLASS: &str = "0x01e4f1248860f32c336f93f2595099aaa4959be515e40b75472709ef5243ae17"; pub const FAULTY_ACCOUNT_CLASS_FILE: &str = "faulty_account.sierra.json"; - -/// Returns the absolute path from the project root. -pub fn get_absolute_path(relative_path: &str) -> PathBuf { - Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../..").join(relative_path) -} diff --git a/crates/mempool_test_utils/src/starknet_api_test_utils.rs b/crates/mempool_test_utils/src/starknet_api_test_utils.rs index df1a06172da..1e130c6ffb2 100644 --- a/crates/mempool_test_utils/src/starknet_api_test_utils.rs +++ b/crates/mempool_test_utils/src/starknet_api_test_utils.rs @@ -23,7 +23,7 @@ use starknet_api::rpc_transaction::{ }; use starknet_api::test_utils::deploy_account::DeployAccountTxArgs; use starknet_api::test_utils::invoke::{rpc_invoke_tx, InvokeTxArgs}; -use starknet_api::test_utils::NonceManager; +use starknet_api::test_utils::{get_absolute_path, NonceManager}; use starknet_api::transaction::fields::{ AccountDeploymentData, AllResourceBounds, @@ -40,7 +40,6 @@ use starknet_types_core::felt::Felt; use crate::{ declare_tx_args, - get_absolute_path, COMPILED_CLASS_HASH_OF_CONTRACT_CLASS, CONTRACT_CLASS_FILE, TEST_FILES_FOLDER, diff --git a/crates/papyrus_config/Cargo.toml b/crates/papyrus_config/Cargo.toml index b798bc29baa..7e539043f76 100644 --- a/crates/papyrus_config/Cargo.toml +++ b/crates/papyrus_config/Cargo.toml @@ -23,6 +23,7 @@ assert_matches.workspace = true itertools.workspace = true lazy_static.workspace = true papyrus_test_utils.workspace = true +starknet_api.workspace = true tempfile.workspace = true [lints] diff --git a/crates/papyrus_config/src/config_test.rs b/crates/papyrus_config/src/config_test.rs index dfaaa696ea6..f9bfad1f150 100644 --- a/crates/papyrus_config/src/config_test.rs +++ b/crates/papyrus_config/src/config_test.rs @@ -8,9 +8,9 @@ use assert_matches::assert_matches; use clap::Command; use itertools::chain; use lazy_static::lazy_static; -use papyrus_test_utils::get_absolute_path; use serde::{Deserialize, Serialize}; use serde_json::json; +use starknet_api::test_utils::get_absolute_path; use tempfile::TempDir; use validator::Validate; diff --git a/crates/papyrus_node/src/config/config_test.rs b/crates/papyrus_node/src/config/config_test.rs index c6247a365d7..dda43dd8d45 100644 --- a/crates/papyrus_node/src/config/config_test.rs +++ b/crates/papyrus_node/src/config/config_test.rs @@ -15,10 +15,10 @@ use papyrus_config::dumping::SerializeConfig; use papyrus_config::presentation::get_config_presentation; use papyrus_config::{SerializationType, SerializedContent, SerializedParam}; use papyrus_monitoring_gateway::MonitoringGatewayConfig; -use papyrus_test_utils::get_absolute_path; use pretty_assertions::assert_eq; use serde_json::{json, Map, Value}; use starknet_api::core::ChainId; +use starknet_api::test_utils::get_absolute_path; use tempfile::NamedTempFile; use validator::Validate; diff --git a/crates/papyrus_test_utils/src/lib.rs b/crates/papyrus_test_utils/src/lib.rs index fb91537eecd..b00d2a15cfc 100644 --- a/crates/papyrus_test_utils/src/lib.rs +++ b/crates/papyrus_test_utils/src/lib.rs @@ -9,7 +9,6 @@ use std::hash::Hash; use std::net::SocketAddr; use std::num::NonZeroU64; use std::ops::{Deref, Index}; -use std::path::{Path, PathBuf}; use std::sync::Arc; use cairo_lang_casm::hints::{CoreHint, CoreHintBase, Hint}; @@ -183,11 +182,6 @@ pub async fn send_request( serde_json::from_str(&res_str).unwrap() } -/// Returns the absolute path from the project root. -pub fn get_absolute_path(relative_path: &str) -> PathBuf { - Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../..").join(relative_path) -} - pub fn validate_load_and_dump Deserialize<'a>>(path_in_resource_dir: &str) { let json_value = read_json_file(path_in_resource_dir); let load_result = serde_json::from_value::(json_value.clone()); diff --git a/crates/starknet_api/src/test_utils.rs b/crates/starknet_api/src/test_utils.rs index 9ca19eb7999..0f10a1ca61b 100644 --- a/crates/starknet_api/src/test_utils.rs +++ b/crates/starknet_api/src/test_utils.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::env; use std::fs::read_to_string; -use std::path::Path; +use std::path::{Path, PathBuf}; use starknet_types_core::felt::Felt; @@ -11,6 +11,11 @@ pub mod declare; pub mod deploy_account; pub mod invoke; +/// Returns the absolute path from the project root. +pub fn get_absolute_path(relative_path: &str) -> PathBuf { + Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../..").join(relative_path) +} + /// Reads from the directory containing the manifest at run time, same as current working directory. pub fn read_json_file(path_in_resource_dir: &str) -> serde_json::Value { let path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()) diff --git a/crates/starknet_sequencer_node/src/config/config_test.rs b/crates/starknet_sequencer_node/src/config/config_test.rs index 6827a4452d4..2bfc4b1f008 100644 --- a/crates/starknet_sequencer_node/src/config/config_test.rs +++ b/crates/starknet_sequencer_node/src/config/config_test.rs @@ -4,10 +4,10 @@ use std::fs::File; use assert_json_diff::assert_json_eq; use assert_matches::assert_matches; use colored::Colorize; -use mempool_test_utils::get_absolute_path; use papyrus_config::dumping::SerializeConfig; use papyrus_config::validators::config_validate; use rstest::rstest; +use starknet_api::test_utils::get_absolute_path; use starknet_sequencer_infra::component_definitions::{ LocalServerConfig, RemoteClientConfig, diff --git a/crates/starknet_sierra_compile/src/compile_test.rs b/crates/starknet_sierra_compile/src/compile_test.rs index 675f9113435..21f3f2dbf03 100644 --- a/crates/starknet_sierra_compile/src/compile_test.rs +++ b/crates/starknet_sierra_compile/src/compile_test.rs @@ -2,8 +2,9 @@ use std::env; use std::path::Path; use assert_matches::assert_matches; -use mempool_test_utils::{get_absolute_path, FAULTY_ACCOUNT_CLASS_FILE, TEST_FILES_FOLDER}; +use mempool_test_utils::{FAULTY_ACCOUNT_CLASS_FILE, TEST_FILES_FOLDER}; use rstest::rstest; +use starknet_api::test_utils::get_absolute_path; use crate::cairo_lang_compiler::CairoLangSierraToCasmCompiler; use crate::command_line_compiler::CommandLineCompiler;