Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: share the test util get_absolute_path #2026

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions crates/mempool_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
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";
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)
}
3 changes: 1 addition & 2 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_config/src/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 0 additions & 6 deletions crates/papyrus_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<T: Serialize + for<'a> Deserialize<'a>>(path_in_resource_dir: &str) {
let json_value = read_json_file(path_in_resource_dir);
let load_result = serde_json::from_value::<T>(json_value.clone());
Expand Down
9 changes: 7 additions & 2 deletions crates/starknet_api/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,8 +11,13 @@ pub mod declare;
pub mod deploy_account;
pub mod invoke;

/// Returns the absolute path from the project root.
pub fn get_absolute_path<P: AsRef<Path>>(relative_path: P) -> 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 {
pub fn read_json_file<P: AsRef<Path>>(path_in_resource_dir: P) -> serde_json::Value {
let path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap())
.join("resources")
.join(path_in_resource_dir);
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_sequencer_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/starknet_sierra_compile/src/compile_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading