Skip to content

Commit

Permalink
test: bincode serialization and deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw authored and marcospb19-cw committed Aug 1, 2024
1 parent d405c05 commit ea58295
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/eth/storage/rocks/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,53 @@ pub use hash::HashRocksdb;
pub use index::IndexRocksdb;
pub use slot::SlotIndexRocksdb;
pub use slot::SlotValueRocksdb;

#[cfg(test)]
mod tests {
use block_header::BlockHeaderRocksdb;
use bytes::BytesRocksdb;
use chain_id::ChainIdRocksdb;
use difficulty::DifficultyRocksdb;
use execution::ExecutionRocksdb;
use execution_result::ExecutionResultRocksdb;
use gas::GasRocksdb;
use log::LogRocksdb;
use log_mined::LogMinedRockdb;
use logs_bloom::LogsBloomRocksdb;
use miner_nonce::MinerNonceRocksdb;
use nonce::NonceRocksdb;
use size::SizeRocksdb;
use transaction_input::TransactionInputRocksdb;
use transaction_mined::TransactionMinedRocksdb;
use unix_time::UnixTimeRocksdb;
use wei::WeiRocksdb;

use crate::gen_test_bincode;
use super::*;

gen_test_bincode!(AccountRocksdb);
gen_test_bincode!(AddressRocksdb);
gen_test_bincode!(BlockHeaderRocksdb);
gen_test_bincode!(BlockNumberRocksdb);
gen_test_bincode!(BlockRocksdb);
gen_test_bincode!(BytesRocksdb);
gen_test_bincode!(ChainIdRocksdb);
gen_test_bincode!(DifficultyRocksdb);
gen_test_bincode!(ExecutionResultRocksdb);
gen_test_bincode!(ExecutionRocksdb);
gen_test_bincode!(GasRocksdb);
gen_test_bincode!(HashRocksdb);
gen_test_bincode!(IndexRocksdb);
gen_test_bincode!(LogMinedRockdb);
gen_test_bincode!(LogRocksdb);
gen_test_bincode!(LogsBloomRocksdb);
gen_test_bincode!(MinerNonceRocksdb);
gen_test_bincode!(NonceRocksdb);
gen_test_bincode!(SizeRocksdb);
gen_test_bincode!(SlotIndexRocksdb);
gen_test_bincode!(SlotValueRocksdb);
gen_test_bincode!(TransactionInputRocksdb);
gen_test_bincode!(TransactionMinedRocksdb);
gen_test_bincode!(UnixTimeRocksdb);
gen_test_bincode!(WeiRocksdb);
}
15 changes: 15 additions & 0 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,18 @@ macro_rules! gen_test_serde {
}
};
}

/// Generates unit test that checks that bincode's serialization and deserialization are compatible
#[macro_export]
macro_rules! gen_test_bincode {
($type:ty) => {
paste::paste! {
#[test]
pub fn [<bincode_ $type:snake>]() {
let value = <fake::Faker as fake::Fake>::fake::<$type>(&fake::Faker);
let binary = bincode::serialize(&value).unwrap();
assert_eq!(bincode::deserialize::<$type>(&binary).unwrap(), value);
}
}
};
}

0 comments on commit ea58295

Please sign in to comment.