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

feat: create dump_config for mempool node config #164

Merged
merged 1 commit into from
May 30, 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
18 changes: 18 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"crates/mempool_infra",
"crates/starknet_sierra_compile",
"crates/task_executor",
"crates/test_utils",
]
resolver = "2"

Expand All @@ -28,6 +29,7 @@ as_conversions = "deny"

[workspace.dependencies]
anyhow = "1.0"
assert-json-diff = "2.0.2"
assert_matches = "1.5.0"
async-trait = "0.1.79"
axum = "0.6.12"
Expand All @@ -37,8 +39,9 @@ cairo-lang-sierra = "2.6.0"
cairo-lang-starknet-classes = "2.6.0"
cairo-lang-utils = "2.6.0"
clap = "4.3.10"
derive_more = "0.99"
colored = "2.1.0"
const_format = "0.2.30"
derive_more = "0.99"
hyper = { version = "0.14", features = ["client", "http1"] }
papyrus_config = "0.3.0"
pretty_assertions = "1.4.0"
Expand Down
4 changes: 4 additions & 0 deletions crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ tokio.workspace = true
validator.workspace = true

[dev-dependencies]
assert-json-diff.workspace = true
assert_matches.workspace = true
colored.workspace = true
pretty_assertions.workspace = true
serde_json.workspace = true
test_utils = {path = "../test_utils"}
35 changes: 34 additions & 1 deletion crates/mempool_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#[cfg(any(feature = "testing", test))]
use std::env::{self};
use std::fs::File;

use assert_json_diff::assert_json_eq;
use assert_matches::assert_matches;
use colored::Colorize;
use papyrus_config::dumping::SerializeConfig;
use papyrus_config::validators::{ParsedValidationError, ParsedValidationErrors};
use test_utils::get_absolute_path;
use validator::Validate;

use crate::config::{ComponentConfig, ComponentExecutionConfig};
use crate::config::{
ComponentConfig, ComponentExecutionConfig, MempoolNodeConfig, DEFAULT_CONFIG_PATH,
};

/// Test the validation of the struct ComponentConfig.
/// The validation validates at least one of the components is set with execute: true.
Expand Down Expand Up @@ -41,3 +50,27 @@ fn test_components_config_validation() {
assert!(component_config.validate().is_ok());
}
}

/// Test the validation of the struct MempoolNodeConfig and that the default config file is up to
/// date. To update the default config file, run:
/// cargo run --bin dump_config -q
#[test]
fn default_config_file_is_up_to_date() {
let default_config = MempoolNodeConfig::default();
assert!(default_config.validate().is_ok());
let from_code: serde_json::Value = serde_json::to_value(default_config.dump()).unwrap();

env::set_current_dir(get_absolute_path("")).expect("Couldn't set working dir.");
let from_default_config_file: serde_json::Value =
serde_json::from_reader(File::open(DEFAULT_CONFIG_PATH).unwrap()).unwrap();

println!(
"{}",
"Default config file doesn't match the default NodeConfig implementation. Please update \
it using the dump_config binary."
.purple()
.bold()
);
println!("Diffs shown below.");
assert_json_eq!(from_default_config_file, from_code)
}
4 changes: 2 additions & 2 deletions crates/mempool_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Default for ComponentExecutionConfig {
}

/// The components configuration.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq, Default)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
#[validate(schema(function = "validate_components_config"))]
pub struct ComponentConfig {
pub gateway_component: ComponentExecutionConfig,
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn validate_components_config(components: &ComponentConfig) -> Result<(), Va
}

/// The configurations of the various components of the node.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Validate, Default)]
#[derive(Debug, Deserialize, Default, Serialize, Clone, PartialEq, Validate)]
pub struct MempoolNodeConfig {
#[validate]
pub components: ComponentConfig,
Expand Down
12 changes: 12 additions & 0 deletions crates/test_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "test_utils"
version.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true

[features]

[dependencies]


7 changes: 7 additions & 0 deletions crates/test_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::env;
use std::path::{Path, PathBuf};

/// 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)
}
Loading