#![allow(dead_code)]
use std::{ops::Deref, sync::Arc};
use crate::service::finalized_state::{
disk_format::{FromDisk, IntoDisk},
FinalizedState, ZebraDb,
};
impl Deref for FinalizedState {
type Target = ZebraDb;
fn deref(&self) -> &Self::Target {
&self.db
}
}
pub fn round_trip<T>(input: T) -> T
where
T: IntoDisk + FromDisk,
{
let bytes = input.as_bytes();
T::from_bytes(bytes)
}
pub fn assert_round_trip<T>(input: T)
where
T: IntoDisk + FromDisk + Clone + PartialEq + std::fmt::Debug,
{
let before = input.clone();
let after = round_trip(input);
assert_eq!(before, after);
}
pub fn round_trip_ref<T>(input: &T) -> T
where
T: IntoDisk + FromDisk,
{
let bytes = input.as_bytes();
T::from_bytes(bytes)
}
pub fn assert_round_trip_ref<T>(input: &T)
where
T: IntoDisk + FromDisk + Clone + PartialEq + std::fmt::Debug,
{
let before = input;
let after = round_trip_ref(input);
assert_eq!(before, &after);
}
pub fn round_trip_arc<T>(input: Arc<T>) -> T
where
T: IntoDisk + FromDisk,
{
let bytes = input.as_bytes();
T::from_bytes(bytes)
}
pub fn assert_round_trip_arc<T>(input: Arc<T>)
where
T: IntoDisk + FromDisk + Clone + PartialEq + std::fmt::Debug,
{
let before = input.clone();
let after = round_trip_arc(input);
assert_eq!(*before, after);
}
pub fn assert_value_properties<T>(input: T)
where
T: IntoDisk + FromDisk + Clone + PartialEq + std::fmt::Debug,
{
assert_round_trip_ref(&input);
assert_round_trip_arc(Arc::new(input.clone()));
assert_round_trip(input);
}