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 26, 2024
1 parent 0421768 commit 084a448
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 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/starknet_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description = "Starknet Rust types related to computation and execution."
testing = ["infra_utils"]

[dependencies]
assert-json-diff.workspace = true
bitvec.workspace = true
cairo-lang-runner.workspace = true
cairo-lang-starknet-classes.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::rpc_transaction::RpcTransaction;
use crate::transaction::fields::Fee;
use crate::transaction::{Transaction, TransactionHash};

pub mod assert_json_eq;
pub mod declare;
pub mod deploy_account;
pub mod invoke;
Expand Down
37 changes: 37 additions & 0 deletions crates/starknet_api/src/test_utils/assert_json_eq.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! 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_eq::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
12 changes: 5 additions & 7 deletions crates/starknet_sequencer_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ 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 rstest::rstest;
use starknet_api::assert_json_eq;
use starknet_batcher::block_builder::BlockBuilderConfig;
use starknet_batcher::config::BatcherConfig;
use starknet_sequencer_infra::component_definitions::{
Expand Down Expand Up @@ -96,17 +96,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 084a448

Please sign in to comment.