|
|
|
@ -157,6 +157,7 @@ impl FreezeMetadata
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// An immutable `State` image
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct Freeze
|
|
|
|
|
{
|
|
|
|
@ -189,7 +190,7 @@ impl Freeze
|
|
|
|
|
.with_section(|| format!("{:?}", unchecked_meta).header("Metadata was"))?;
|
|
|
|
|
|
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
|
|
|
if unchecked_meta.verify_hash_blocking(&body) {
|
|
|
|
|
if !unchecked_meta.verify_hash_blocking(&body) {
|
|
|
|
|
Err(eyre!("Failed to verify metadata hash"))
|
|
|
|
|
} else {
|
|
|
|
|
serde_cbor::from_slice(&body)
|
|
|
|
@ -353,3 +354,35 @@ impl From<Freeze> for State
|
|
|
|
|
from.into_state()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests
|
|
|
|
|
{
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn read_write()
|
|
|
|
|
{
|
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
|
let state = super::State::new();
|
|
|
|
|
let freeze = state.freeze().await;
|
|
|
|
|
|
|
|
|
|
freeze.write_async(&mut buffer).await.unwrap();
|
|
|
|
|
let freeze2 = super::Freeze::read_async(&mut &buffer[..]).await.unwrap();
|
|
|
|
|
assert_eq!(freeze, freeze2);
|
|
|
|
|
|
|
|
|
|
let mut buffer2 = Vec::new();
|
|
|
|
|
freeze2.into_write_async(&mut buffer2).await.unwrap();
|
|
|
|
|
assert_eq!(buffer, buffer2);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn creation()
|
|
|
|
|
{
|
|
|
|
|
let state = super::State::new();
|
|
|
|
|
let freeze = state.freeze().await;
|
|
|
|
|
let state2 = freeze.unfreeze();
|
|
|
|
|
let freeze2 = state2.freeze().await;
|
|
|
|
|
assert_eq!(freeze, freeze2);
|
|
|
|
|
let _state3 = freeze2.into_state();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|