consensus: add a (failing) verify round-trip test

This test doesn't work, because the futures are not used correctly.

Part of #428.
This commit is contained in:
teor 2020-06-11 22:14:07 +10:00 committed by Henry de Valence
parent c2590ce526
commit 15bc64aed9
3 changed files with 58 additions and 4 deletions

1
Cargo.lock generated
View File

@ -2128,6 +2128,7 @@ dependencies = [
"color-eyre",
"eyre",
"futures-util",
"spandoc",
"tokio",
"tower",
"tracing",

View File

@ -17,6 +17,7 @@ tower = "0.3.1"
zebra-test-vectors = { path = "../zebra-test-vectors/" }
color-eyre = "0.3.4"
eyre = "0.4.2"
spandoc = { git = "https://github.com/yaahc/spandoc.git" }
tokio = { version = "0.2.21", features = ["full"] }
tracing = "0.1.15"
tracing-error = "0.1.2"

View File

@ -110,7 +110,7 @@ where
mod tests {
use super::*;
use color_eyre::Report;
use eyre::{ensure, eyre};
use eyre::{bail, ensure, eyre};
use tower::{util::ServiceExt, Service};
use zebra_chain::serialization::ZcashDeserialize;
@ -131,10 +131,17 @@ mod tests {
.init();
}
#[tokio::test]
async fn verify() -> Result<(), Report> {
install_tracing();
/// Initialise and return an unwrapped `BlockVerifier`.
fn init_block_verifier<ZSF>(state_service: ZS<ZSF>) -> BlockVerifier<ZSF>
where
ZSF: Future<Output = Result<zebra_state::Response, ZSE>> + Send + 'static,
{
BlockVerifier::<ZSF> { state_service }
}
#[tokio::test]
#[spandoc::spandoc]
async fn verify() -> Result<(), Report> {
let block = Block::zcash_deserialize(&zebra_test_vectors::BLOCK_MAINNET_415000_BYTES[..])?;
// TODO(teor): why does rustc say that _hash is unused?
let _hash: BlockHeaderHash = (&block).into();
@ -158,4 +165,49 @@ mod tests {
Ok(())
}
#[tokio::test]
#[spandoc::spandoc]
async fn round_trip() -> Result<(), Report> {
install_tracing();
let block = Block::zcash_deserialize(&zebra_test_vectors::BLOCK_MAINNET_GENESIS_BYTES[..])?;
// TODO(teor): why does rustc say that _hash is unused?
let _hash: BlockHeaderHash = (&block).into();
let state_service = Box::new(zebra_state::in_memory::init());
let mut block_verifier = init_block_verifier(state_service);
let verify_response = block_verifier
.ready_and()
.await
.map_err(|e| eyre!(e))?
.call(block.clone())
.await
.map_err(|e| eyre!(e))?;
ensure!(
matches!(verify_response, _hash),
"unexpected response kind: {:?}",
verify_response
);
let state_response = block_verifier
.state_service
.ready_and()
.await
.map_err(|e| eyre!(e))?
.call(zebra_state::Request::GetBlock { hash: _hash })
.await
.map_err(|e| eyre!(e))?;
match state_response {
zebra_state::Response::Block {
block: returned_block,
} => assert_eq!(&block, returned_block.as_ref()),
_ => bail!("unexpected response kind: {:?}", state_response),
}
Ok(())
}
}