Skip to content

Commit

Permalink
reencode/redecode
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw committed Jul 30, 2024
1 parent efa445c commit 991983f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/eth/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ mod tests {
type TransactionExecutionValueChangeSlot = ExecutionValueChange<Slot>;
type TransactionExecutionValueChangeWei = ExecutionValueChange<Wei>;


// FIX: gen_test_serde!(Block);
// FIX: gen_test_serde!(EvmExecution);
// FIX: gen_test_serde!(ExecutionAccountChanges);
Expand Down
14 changes: 14 additions & 0 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,40 @@ macro_rules! gen_test_serde {
paste::paste! {
#[test]
pub fn [<serde_json_ $type:snake>]() {
// encode
let value_original = <fake::Faker as fake::Fake>::fake::<$type>(&fake::Faker);
let value_encoded = serde_json::to_string(&value_original).unwrap();

// decode
let value_decoded = serde_json::from_str::<$type>(&value_encoded).unwrap();
assert_eq!(value_decoded, value_original);

// re-encode
let value_reencoded = serde_json::to_string(&value_decoded).unwrap();
assert_eq!(value_reencoded, value_encoded);

// re-decode
let value_redecoded = serde_json::from_str::<$type>(&value_reencoded).unwrap();
assert_eq!(value_redecoded, value_original);
}

#[test]
pub fn [<serde_bincode_ $type:snake>]() {
// encode
let value_original = <fake::Faker as fake::Fake>::fake::<$type>(&fake::Faker);
let value_encoded = bincode::serialize(&value_original).unwrap();

// decode
let value_decoded = bincode::deserialize::<$type>(&value_encoded).unwrap();
assert_eq!(value_decoded, value_original);

// re-encode
let value_reencoded = bincode::serialize(&value_decoded).unwrap();
assert_eq!(value_reencoded, value_encoded);

// re-decode
let value_redecoded = bincode::deserialize::<$type>(&value_reencoded).unwrap();
assert_eq!(value_redecoded, value_original);
}
}
};
Expand Down

0 comments on commit 991983f

Please sign in to comment.