Skip to content

Commit

Permalink
chore(starknet_sequencer_node): fix the conditional print on config t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
ArniStarkware committed Dec 25, 2024
1 parent 4004370 commit 5965481
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/papyrus_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license-file.workspace = true
description = "A library for handling node configuration."

[dependencies]
assert-json-diff.workspace = true
clap = { workspace = true, features = ["env", "string"] }
infra_utils.workspace = true
itertools.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub mod converters;
pub mod dumping;
pub mod loading;
pub mod presentation;
pub mod test_utils;
pub mod validators;

/// The privacy level of a config parameter, that received as input from the configs.
Expand Down
35 changes: 35 additions & 0 deletions crates/papyrus_config/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Utils for config test.
use assert_json_diff::{assert_json_matches_no_panic, CompareMode, Config};
use serde::Serialize;

/// Compares two JSON values for an exact match without panicking.
/// See [`assert_json_matches_no_panic`]
pub fn assert_json_exact_matches_no_panic<Lhs, Rhs>(lhs: &Lhs, rhs: &Rhs) -> Result<(), String>
where
Lhs: Serialize,
Rhs: Serialize,
{
assert_json_matches_no_panic(lhs, rhs, Config::new(CompareMode::Strict))
}

#[macro_export]
/// Compare two JSON values for an exact match.
///
/// Extends the functionality of [`assert_json_diff::assert_json_eq`] by also adding a customizable
/// error message print.
macro_rules! assert_json_eq {
($lhs:expr, $rhs:expr, $error_message:expr $(,)?) => {{
if let Err(error) = $crate::test_utils::assert_json_exact_matches_no_panic(&$lhs, &$rhs) {
let printed_error = format!("\n\n{}\n{}\n\n", $error_message, error);
panic!("{}", printed_error);
}
}};

($lhs:expr, $rhs:expr $(,)?) => {{
if let Err(error) = $crate::test_utils::assert_json_exact_matches_no_panic(&$lhs, &$rhs) {
let printed_error = format!("\n\n{}\n\n", error);
panic!("{}", printed_error);
}
}};
}
1 change: 0 additions & 1 deletion crates/starknet_sequencer_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ tracing.workspace = true
validator.workspace = true

[dev-dependencies]
assert-json-diff.workspace = true
assert_matches.workspace = true
colored.workspace = true
infra_utils.workspace = true
Expand Down
13 changes: 5 additions & 8 deletions crates/starknet_sequencer_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use std::collections::HashSet;
use std::env;
use std::fs::File;

use assert_json_diff::assert_json_eq;
use assert_matches::assert_matches;
use colored::Colorize;
use infra_utils::path::resolve_project_relative_path;
use papyrus_config::dumping::SerializeConfig;
use papyrus_config::validators::config_validate;
use papyrus_config::SerializedParam;
use papyrus_config::{assert_json_eq, SerializedParam};
use rstest::rstest;
use starknet_batcher::block_builder::BlockBuilderConfig;
use starknet_batcher::config::BatcherConfig;
Expand Down Expand Up @@ -96,17 +95,15 @@ fn test_default_config_file_is_up_to_date() {
let from_code: serde_json::Value =
serde_json::from_reader(File::open(tmp_file_path).unwrap()).unwrap();

println!(
"{}",
let error_message = format!(
"{}\n{}",
"Default config file doesn't match the default NodeConfig implementation. Please update \
it using the sequencer_dump_config binary."
.purple()
.bold()
);
println!(
.bold(),
"Diffs shown below (default config file <<>> dump of SequencerNodeConfig::default())."
);
assert_json_eq!(from_default_config_file, from_code)
assert_json_eq!(from_default_config_file, from_code, error_message);
}

/// Tests parsing a node config without additional args.
Expand Down

0 comments on commit 5965481

Please sign in to comment.