Skip to content

Commit

Permalink
fix: avoid rounding in serializations
Browse files Browse the repository at this point in the history
  • Loading branch information
yair-starkware committed Jul 9, 2024
1 parent 6e74e3f commit 8b2b64f
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ papyrus_config.workspace = true
papyrus_rpc.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_json = { workspace = true, features = ["arbitrary_precision"] }
starknet_api.workspace = true
starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" }
starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
Expand Down
10 changes: 10 additions & 0 deletions crates/gateway/src/utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@ fn test_is_subsequence(
) {
assert_eq!(is_subsequence(subsequence, sequence), expected_result);
}

// Make sure we have the arbitrary precision feature of serde_json.
#[test]
fn serialization_precision() {
let input =
"{\"value\":244116128358498188146337218061232635775543270890529169229936851982759783745}";
let serialized = serde_json::from_str::<serde_json::Value>(input).unwrap();
let deserialized = serde_json::to_string(&serialized).unwrap();
assert_eq!(input, deserialized);
}
2 changes: 1 addition & 1 deletion crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ assert-json-diff.workspace = true
assert_matches.workspace = true
colored.workspace = true
pretty_assertions.workspace = true
serde_json.workspace = true
serde_json = { workspace = true, features = ["arbitrary_precision"] }
mempool_test_utils = { path = "../mempool_test_utils" }
2 changes: 2 additions & 0 deletions crates/mempool_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ pub mod communication;
pub mod components;
pub mod config;
pub mod servers;
#[cfg(test)]
mod test;
pub mod version;
9 changes: 9 additions & 0 deletions crates/mempool_node/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Make sure we have the arbitrary precision feature of serde_json.
#[test]
fn serialization_precision() {
let input =
"{\"value\":244116128358498188146337218061232635775543270890529169229936851982759783745}";
let serialized = serde_json::from_str::<serde_json::Value>(input).unwrap();
let deserialized = serde_json::to_string(&serialized).unwrap();
assert_eq!(input, deserialized);
}
2 changes: 1 addition & 1 deletion crates/mempool_test_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ assert_matches.workspace = true
blockifier.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
serde_json.workspace = true
serde_json = { workspace = true, features = ["arbitrary_precision"] }


2 changes: 2 additions & 0 deletions crates/mempool_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::env;
use std::path::{Path, PathBuf};

pub mod starknet_api_test_utils;
#[cfg(test)]
mod test;

pub const TEST_FILES_FOLDER: &str = "crates/mempool_test_utils/test_files";
pub const CONTRACT_CLASS_FILE: &str = "contract_class.json";
Expand Down
9 changes: 9 additions & 0 deletions crates/mempool_test_utils/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Make sure we have the arbitrary precision feature of serde_json.
#[test]
fn serialization_precision() {
let input =
"{\"value\":244116128358498188146337218061232635775543270890529169229936851982759783745}";
let serialized = serde_json::from_str::<serde_json::Value>(input).unwrap();
let deserialized = serde_json::to_string(&serialized).unwrap();
assert_eq!(input, deserialized);
}
2 changes: 1 addition & 1 deletion crates/starknet_sierra_compile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-starknet-classes.workspace = true
cairo-lang-utils.workspace = true
serde_json.workspace = true
serde_json = { workspace = true, features = ["arbitrary_precision"] }
serde.workspace = true
starknet_api.workspace = true
starknet-types-core.workspace = true
Expand Down
10 changes: 10 additions & 0 deletions crates/starknet_sierra_compile/src/compile_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ fn test_negative_flow_compile_sierra_to_casm() {
Err(CompilationUtilError::AllowedLibfuncsError(AllowedLibfuncsError::SierraProgramError))
);
}

// Make sure we have the arbitrary precision feature of serde_json.
#[test]
fn serialization_precision() {
let input =
"{\"value\":244116128358498188146337218061232635775543270890529169229936851982759783745}";
let serialized = serde_json::from_str::<serde_json::Value>(input).unwrap();
let deserialized = serde_json::to_string(&serialized).unwrap();
assert_eq!(input, deserialized);
}
2 changes: 1 addition & 1 deletion crates/tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ papyrus_common.workspace = true
papyrus_rpc.workspace = true
papyrus_storage.workspace = true
reqwest.workspace = true
serde_json.workspace = true
serde_json = { workspace = true, features = ["arbitrary_precision"] }
starknet_api.workspace = true
starknet_client.workspace = true
starknet_gateway = { path = "../gateway", version = "0.0", features = ["testing"] }
Expand Down
10 changes: 10 additions & 0 deletions crates/tests-integration/tests/end_to_end_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ async fn test_end_to_end() {
expected_tx_hashes.sort();
assert_eq!(expected_tx_hashes, actual_tx_hashes);
}

// Make sure we have the arbitrary precision feature of serde_json.
#[test]
fn serialization_precision() {
let input =
"{\"value\":244116128358498188146337218061232635775543270890529169229936851982759783745}";
let serialized = serde_json::from_str::<serde_json::Value>(input).unwrap();
let deserialized = serde_json::to_string(&serialized).unwrap();
assert_eq!(input, deserialized);
}

0 comments on commit 8b2b64f

Please sign in to comment.