From 0385976c80317bcf3a2ba4a07f71034905b72a2a Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Tue, 21 May 2024 17:12:59 +0300 Subject: [PATCH] feat: create dump_config for mempool node config --- Cargo.lock | 61 +++++++++++++++++++ Cargo.toml | 6 +- config/default_config.json | 26 +++++++- crates/mempool_node/Cargo.toml | 4 ++ crates/mempool_node/src/config/config_test.rs | 47 +++++++++++++- crates/mempool_node/src/config/mod.rs | 4 +- ...fig__config_test__dump_default_config.snap | 52 ++++++++++++++++ crates/test_utils/Cargo.toml | 12 ++++ crates/test_utils/src/lib.rs | 7 +++ 9 files changed, 212 insertions(+), 7 deletions(-) create mode 100644 crates/mempool_node/src/config/snapshots/mempool_node__config__config_test__dump_default_config.snap create mode 100644 crates/test_utils/Cargo.toml create mode 100644 crates/test_utils/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 9a733929f..e0fe1fa91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -242,6 +242,16 @@ dependencies = [ "term", ] +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "assert_matches" version = "1.5.0" @@ -1042,6 +1052,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "const-fnv1a-hash" version = "1.1.0" @@ -1259,6 +1281,12 @@ dependencies = [ "log", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -1754,6 +1782,19 @@ version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" +[[package]] +name = "insta" +version = "1.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810ae6042d48e2c9e9215043563a58a80b877bc863228a74cf10c49d4620a6f5" +dependencies = [ + "console", + "lazy_static", + "linked-hash-map", + "serde", + "similar", +] + [[package]] name = "instant" version = "0.1.12" @@ -1914,6 +1955,12 @@ dependencies = [ "libc", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -1991,16 +2038,20 @@ dependencies = [ name = "mempool_node" version = "0.0.0" dependencies = [ + "assert-json-diff", "assert_matches", "async-trait", "clap", + "colored", "const_format", + "insta", "papyrus_config", "pretty_assertions", "serde", "serde_json", "starknet_api", "starknet_gateway", + "test_utils", "thiserror", "tokio", "validator", @@ -3019,6 +3070,12 @@ dependencies = [ "libc", ] +[[package]] +name = "similar" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" + [[package]] name = "siphasher" version = "0.3.11" @@ -3396,6 +3453,10 @@ dependencies = [ "winapi", ] +[[package]] +name = "test_utils" +version = "0.0.0" + [[package]] name = "thiserror" version = "1.0.59" diff --git a/Cargo.toml b/Cargo.toml index 67c408ef9..a8637449e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "crates/mempool_node", "crates/mempool_infra", "crates/task_executor", + "crates/test_utils", ] resolver = "2" @@ -27,6 +28,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" @@ -34,9 +36,11 @@ axum = "0.6.12" blockifier = { git = "https://github.com/starkware-libs/blockifier.git", rev = "fc62b8b8", features = ["testing"] } cairo-lang-starknet-classes = "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"] } +insta = "1.29.0" papyrus_config = "0.3.0" pretty_assertions = "1.4.0" reqwest = { version = "0.11", features = ["blocking", "json"] } diff --git a/config/default_config.json b/config/default_config.json index 71c57600f..4d3809acd 100644 --- a/config/default_config.json +++ b/config/default_config.json @@ -9,14 +9,34 @@ "privacy": "Public", "value": true }, - "gateway_config.ip": { + "gateway_config.network_config.ip": { "description": "The gateway server ip.", "privacy": "Public", "value": "0.0.0.0" }, - "gateway_config.port": { + "gateway_config.network_config.port": { "description": "The gateway server port.", "privacy": "Public", "value": 8080 + }, + "gateway_config.stateless_transaction_validator_config.max_calldata_length": { + "description": "Validates that a transaction has signature length less than or equal to this value.", + "privacy": "Public", + "value": 0 + }, + "gateway_config.stateless_transaction_validator_config.max_signature_length": { + "description": "Validates that a transaction has calldata length less than or equal to this value.", + "privacy": "Public", + "value": 0 + }, + "gateway_config.stateless_transaction_validator_config.validate_non_zero_l1_gas_fee": { + "description": "If true, validates that a transaction has non-zero L1 resource bounds.", + "privacy": "Public", + "value": false + }, + "gateway_config.stateless_transaction_validator_config.validate_non_zero_l2_gas_fee": { + "description": "If true, validates that a transaction has non-zero L2 resource bounds.", + "privacy": "Public", + "value": false } -} \ No newline at end of file +} diff --git a/crates/mempool_node/Cargo.toml b/crates/mempool_node/Cargo.toml index 9f9a8612d..b5c1d7d8a 100644 --- a/crates/mempool_node/Cargo.toml +++ b/crates/mempool_node/Cargo.toml @@ -22,5 +22,9 @@ tokio.workspace = true validator.workspace = true [dev-dependencies] +assert-json-diff.workspace = true assert_matches.workspace = true +colored.workspace = true +insta = { workspace = true, features = ["json"] } pretty_assertions.workspace = true +test_utils = {path = "../test_utils"} diff --git a/crates/mempool_node/src/config/config_test.rs b/crates/mempool_node/src/config/config_test.rs index 63e3c260e..f5274bf9a 100644 --- a/crates/mempool_node/src/config/config_test.rs +++ b/crates/mempool_node/src/config/config_test.rs @@ -4,20 +4,24 @@ use std::fs::File; use std::ops::IndexMut; use std::path::{Path, PathBuf}; +use assert_json_diff::assert_json_eq; use assert_matches::assert_matches; +use colored::Colorize; use papyrus_config::dumping::SerializeConfig; use papyrus_config::loading::load_and_process_config; use papyrus_config::presentation::get_config_presentation; use papyrus_config::validators::ParsedValidationErrors; use papyrus_config::{SerializationType, SerializedContent, SerializedParam}; use starknet_gateway::config::{GatewayNetworkConfig, StatelessTransactionValidatorConfig}; +use test_utils::get_absolute_path; use validator::Validate; use crate::config::{ node_command, ComponentConfig, ComponentExecutionConfig, GatewayConfig, MempoolNodeConfig, + DEFAULT_CONFIG_PATH, }; -const TEST_FILES_FOLDER: &str = "./src/test_files"; +const TEST_FILES_FOLDER: &str = "crates/mempool_node/src/test_files"; const CONFIG_FILE: &str = "mempool_node_config.json"; fn get_config_file(file_name: &str) -> Result { @@ -27,6 +31,8 @@ fn get_config_file(file_name: &str) -> Result 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, diff --git a/crates/mempool_node/src/config/snapshots/mempool_node__config__config_test__dump_default_config.snap b/crates/mempool_node/src/config/snapshots/mempool_node__config__config_test__dump_default_config.snap new file mode 100644 index 000000000..8a48ec978 --- /dev/null +++ b/crates/mempool_node/src/config/snapshots/mempool_node__config__config_test__dump_default_config.snap @@ -0,0 +1,52 @@ +--- +source: crates/mempool_node/src/config/config_test.rs +expression: dumped_default_config +--- +{ + "components.gateway_component.execute": { + "description": "The component execution flag.", + "value": true, + "privacy": "Public" + }, + "components.mempool_component.execute": { + "description": "The component execution flag.", + "value": true, + "privacy": "Public" + }, + "gateway_config.network_config.ip": { + "description": "The gateway server ip.", + "value": "0.0.0.0", + "privacy": "Public" + }, + "gateway_config.network_config.port": { + "description": "The gateway server port.", + "value": { + "$serde_json::private::Number": "8080" + }, + "privacy": "Public" + }, + "gateway_config.stateless_transaction_validator_config.max_calldata_length": { + "description": "Validates that a transaction has signature length less than or equal to this value.", + "value": { + "$serde_json::private::Number": "0" + }, + "privacy": "Public" + }, + "gateway_config.stateless_transaction_validator_config.max_signature_length": { + "description": "Validates that a transaction has calldata length less than or equal to this value.", + "value": { + "$serde_json::private::Number": "0" + }, + "privacy": "Public" + }, + "gateway_config.stateless_transaction_validator_config.validate_non_zero_l1_gas_fee": { + "description": "If true, validates that a transaction has non-zero L1 resource bounds.", + "value": false, + "privacy": "Public" + }, + "gateway_config.stateless_transaction_validator_config.validate_non_zero_l2_gas_fee": { + "description": "If true, validates that a transaction has non-zero L2 resource bounds.", + "value": false, + "privacy": "Public" + } +} diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml new file mode 100644 index 000000000..a5cb34605 --- /dev/null +++ b/crates/test_utils/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "test_utils" +version.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true + +[features] + +[dependencies] + + diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs new file mode 100644 index 000000000..374ea1201 --- /dev/null +++ b/crates/test_utils/src/lib.rs @@ -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) +}