Skip to content

Commit

Permalink
Add a [de]serialization unit test for the Bytes
Browse files Browse the repository at this point in the history
Co-authored-by: Harald Hoyer <harald@matterlabs.dev>
  • Loading branch information
pbeza and haraldh committed May 15, 2024
1 parent 148dbd0 commit d7d0ed4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/lib/basic_types/src/web3/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,27 @@ fn block_can_be_deserialized() {
let block: Block<H256> = serde_json::from_str(pre_dencun).unwrap();
assert!(block.excess_blob_gas.is_none());
}

#[test]
fn test_bytes_serde_bincode() {
let original = Bytes(vec![0, 1, 2, 3, 4]);
let encoded: Vec<u8> = bincode::serialize(&original).unwrap();
let decoded: Bytes = bincode::deserialize(&encoded).unwrap();
assert_eq!(original, decoded);
}

#[test]
fn test_bytes_serde_bincode_snapshot() {
let original = Bytes(vec![0, 1, 2, 3, 4]);
let encoded: Vec<u8> = vec![5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4];
let decoded: Bytes = bincode::deserialize(&encoded).unwrap();
assert_eq!(original, decoded);
}

#[test]
fn test_bytes_serde_json() {
let original = Bytes(vec![0, 1, 2, 3, 4]);
let encoded = serde_json::to_string(&original).unwrap();
let decoded: Bytes = serde_json::from_str(&encoded).unwrap();
assert_eq!(original, decoded);
}

0 comments on commit d7d0ed4

Please sign in to comment.