You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Possible Bug The deserialization of BlockFilter now allows for case-insensitive matching of "latest", "pending", and "earliest". This change might introduce unexpected behavior if the system relies on exact string matching elsewhere.
Performance Concern The changes field in EvmExecution is now using ordered_map for serialization in test environments. This might impact performance if used in production code.
Performance Concern Similar to EvmExecution, the slots field in ExecutionAccountChanges is now using ordered_map for serialization in test environments. This might impact performance if used in production code.
// unhandled type
-a => {- println!("{:?}", a);- Err(serde::de::Error::custom("block filter must be a string or integer"))-}+_ => Err(serde::de::Error::custom("block filter must be a string or integer"))
Suggestion importance[1-10]: 9
Why: Removing debug print statements from production code is a crucial best practice for security and performance reasons.
9
Enhancement
Simplify the handling of the Object case in the deserialization logic
Consider using a more concise and idiomatic approach for handling the serde_json::Value::Object case. The current implementation is verbose and can be simplified.
-serde_json::Value::Object(map) =>- if let Some((key, value)) = map.iter().next() {- let Some(value_str) = value.as_str() else {- return Err(serde::de::Error::custom("block filter must be a string or integer"));- };- match key.as_str() {- "Hash" => {- let hash: Hash = value_str.parse().map_err(serde::de::Error::custom)?;- Ok(Self::Hash(hash))- }- "Number" => {- let number: BlockNumber = value_str.parse().map_err(serde::de::Error::custom)?;- Ok(Self::Number(number))- }- _ => Err(serde::de::Error::custom("block filter must be a string or integer")),- }- } else {- Err(serde::de::Error::custom("block filter must be a string or integer"))- },+serde_json::Value::Object(map) => {+ let (key, value) = map.iter().next().ok_or_else(|| serde::de::Error::custom("empty object"))?;+ let value_str = value.as_str().ok_or_else(|| serde::de::Error::custom("value must be a string"))?;+ match key.as_str() {+ "Hash" => value_str.parse().map(Self::Hash).map_err(serde::de::Error::custom),+ "Number" => value_str.parse().map(Self::Number).map_err(serde::de::Error::custom),+ _ => Err(serde::de::Error::custom("invalid key")),+ }+},
Suggestion importance[1-10]: 8
Why: The suggestion significantly improves code clarity and reduces verbosity in the Object case handling, making it more idiomatic and easier to maintain.
8
Simplify the parsing of special keywords using a match expression with lowercase comparison
Consider using a match expression instead of multiple if-else statements for parsing special keywords. This can improve readability and maintainability.
Why: The suggestion improves code readability and maintainability by using a match expression with lowercase comparison, which is more concise and less error-prone.
7
Use a consistently ordered map type for storage changes
Consider using a more specific type for changes instead of HashMap. Since you're using ordered_map for serialization in tests, you might want to use BTreeMap or a custom ordered map implementation to ensure consistent ordering across all use cases.
/// Storage changes that happened during the transaction execution.
-#[cfg_attr(test, serde(serialize_with = "ordered_map"))]-pub changes: ExecutionChanges,+pub changes: std::collections::BTreeMap<Address, ExecutionAccountChanges>,
Suggestion importance[1-10]: 6
Why: Using a consistently ordered map type like BTreeMap ensures consistent behavior across all use cases, not just in tests, which can prevent subtle bugs.
Add error handling and improve assertion messages in the serde_json test function
In the serde_json test function, consider adding error handling for the serialization and deserialization operations to provide more informative error messages in case of failure.
#[test]
pub fn [<serde_json_ $type:snake>]() {
// encode
let original = <fake::Faker as fake::Fake>::fake::<$type>(&fake::Faker);
- let encoded = serde_json::to_value(&original).unwrap();+ let encoded = serde_json::to_value(&original).expect("Failed to encode original value");
// decode
- let decoded = serde_json::from_value::<$type>(encoded.clone()).unwrap();- assert_eq!(decoded, original);+ let decoded = serde_json::from_value::<$type>(encoded.clone()).expect("Failed to decode value");+ assert_eq!(decoded, original, "Decoded value doesn't match original");
// re-encode
- let reencoded = serde_json::to_value(&decoded).unwrap();- assert_eq!(reencoded, encoded);+ let reencoded = serde_json::to_value(&decoded).expect("Failed to re-encode decoded value");+ assert_eq!(reencoded, encoded, "Re-encoded value doesn't match original encoding");
// re-decode
- let redecoded = serde_json::from_value::<$type>(reencoded).unwrap();- assert_eq!(redecoded, original);+ let redecoded = serde_json::from_value::<$type>(reencoded).expect("Failed to re-decode value");+ assert_eq!(redecoded, original, "Re-decoded value doesn't match original");
}
Suggestion importance[1-10]: 8
Why: This suggestion significantly improves error handling and provides more informative assertion messages, making debugging easier and tests more robust.
8
Implement faker::Dummy for external structs or create custom test functions instead of using commented-out gen_test_serde! macro calls
Consider removing the commented-out gen_test_serde! macro calls for external structs and internal structs that contain external structs not implementing faker::Dummy. Instead, implement faker::Dummy for these types or create custom test functions for them.
-// TODO: Test external structs and internal structs that contain external strtucts that do no implement faker::Dummy-// gen_test_serde!(ExecutionConflicts);-// gen_test_serde!(ExecutionConflictsBuilder);-// gen_test_serde!(ExternalBlock);-// gen_test_serde!(ExternalReceipt);-// gen_test_serde!(ExternalReceipts);-// gen_test_serde!(ExternalTransaction);-// gen_test_serde!(ExternalTransactionExecution);-// gen_test_serde!(PendingBlock);-// gen_test_serde!(TransactionExecution);+// Implement faker::Dummy for external structs or create custom test functions+// Example:+// impl faker::Dummy<faker::Faker> for ExecutionConflicts {+// fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &faker::Faker, _: &mut R) -> Self {+// // Implement custom dummy generation logic+// }+// }+// +// #[test]+// fn test_execution_conflicts_serde() {+// // Implement custom test logic+// }
Suggestion importance[1-10]: 7
Why: This suggestion improves code quality by replacing commented-out code with actionable tasks, enhancing maintainability and test coverage.
7
Add type annotation and improve assertion message in the serde_debug_json test function
In the serde_debug_json test function, consider adding an assertion to compare the original value with the decoded value to ensure that the debug representation can be correctly deserialized back into the original type.
#[test]
pub fn [<serde_debug_json_ $type:snake>]() {
let original = <fake::Faker as fake::Fake>::fake::<$type>(&fake::Faker);
let encoded_debug = format!("{:?}", original);
- let decoded_debug = serde_json::from_str(&encoded_debug).unwrap();- assert_eq!(original, decoded_debug);+ let decoded_debug: $type = serde_json::from_str(&encoded_debug).unwrap();+ assert_eq!(original, decoded_debug, "Debug representation deserialization mismatch");
}
Suggestion importance[1-10]: 6
Why: This suggestion enhances the test function by adding a type annotation and a more descriptive assertion message, improving test clarity and debugging.
6
Maintainability
Group related gen_test_serde! macro calls and add comments for better organization
Consider grouping related gen_test_serde! macro calls together and adding comments to explain the groupings. This can improve code organization and readability.
+// Transaction related types
gen_test_serde!(LocalTransactionExecution);
++// Log and filter related types
gen_test_serde!(LogFilter);
gen_test_serde!(LogFilterInput);
gen_test_serde!(LogFilterInputTopic);
-// TODO: gen_test_serde!(StratusError);-// TODO: gen_test_serde!(TransactionStage);++// TODO: Implement these tests+// gen_test_serde!(StratusError);+// gen_test_serde!(TransactionStage);++// Basic types
gen_test_serde!(Account);
gen_test_serde!(Address);
+gen_test_serde!(Bytes);++// Block related types
gen_test_serde!(Block);
gen_test_serde!(BlockFilter);
gen_test_serde!(BlockHeader);
gen_test_serde!(BlockNumber);
-gen_test_serde!(Bytes);++// Input types
gen_test_serde!(CallInput);
Suggestion importance[1-10]: 5
Why: This suggestion improves code readability and organization by grouping related macro calls and adding explanatory comments, but it's a minor enhancement.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Tests, Enhancement
Description
BlockFilter
,EvmExecution
, andExecutionAccountChanges
.DebugAsJson
for several types to improve debug output.mod.rs
file.BlockFilter
.Changes walkthrough 📝
7 files
evm_result.rs
Add test attributes to EvmExecutionResult
src/eth/executor/evm_result.rs
#[cfg_attr(test, derive(serde::Deserialize, fake::Dummy,
PartialEq))]
toEvmExecutionResult
structaddress.rs
Add test attributes to Address struct
src/eth/primitives/address.rs
#[cfg_attr(test, derive(PartialOrd, Ord))]
toAddress
structexecution_conflict.rs
Add test attributes to ExecutionConflict
src/eth/primitives/execution_conflict.rs
#[cfg_attr(test, derive(serde::Deserialize, fake::Dummy,
PartialEq))]
toExecutionConflict
enumlog_filter.rs
Enhance LogFilter for testing
src/eth/primitives/log_filter.rs
#[cfg_attr(test, derive(serde::Deserialize, fake::Dummy))]
toLogFilter
structoriginal_input
field serialization for testslog_filter_input.rs
Improve LogFilterInput and LogFilterInputTopic for testing
src/eth/primitives/log_filter_input.rs
DebugAsJson
and#[cfg_attr(test, derive(fake::Dummy))]
toLogFilterInput
andLogFilterInputTopic
structsmod.rs
Update and expand serde tests for primitive types
src/eth/primitives/mod.rs
transaction_execution.rs
Add test attributes to LocalTransactionExecution
src/eth/primitives/transaction_execution.rs
#[cfg_attr(test, derive(serde::Deserialize, fake::Dummy,
PartialEq))]
toLocalTransactionExecution
struct5 files
block_filter.rs
Enhance BlockFilter serialization and deserialization
src/eth/primitives/block_filter.rs
DebugAsJson
and#[cfg_attr(test, derive(fake::Dummy))]
toBlockFilter
enumserde::Deserialize
implementation to handle more cases and becase-insensitive
execution.rs
Improve EvmExecution serialization
src/eth/primitives/execution.rs
Debug
withDebugAsJson
forEvmExecution
struct#[cfg_attr(test, serde(serialize_with = "ordered_map"))]
tochanges
fieldexecution_account_changes.rs
Enhance ExecutionAccountChanges serialization
src/eth/primitives/execution_account_changes.rs
Debug
withDebugAsJson
forExecutionAccountChanges
struct#[cfg_attr(test, serde(serialize_with = "ordered_map"))]
toslots
fieldtransaction_mined.rs
Use DebugAsJson for TransactionMined
src/eth/primitives/transaction_mined.rs
Debug
withDebugAsJson
forTransactionMined
structext.rs
Add ordered map serialization and update serde tests
src/ext.rs
ordered_map
function for serializing HashMaps as ordered BTreesgen_test_serde!
macro