2021-06-03 15:48:40 -07:00
|
|
|
// Standard lints
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
#![allow(clippy::try_err)]
|
|
|
|
#![deny(clippy::await_holding_lock)]
|
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
|
2020-06-22 21:31:44 -07:00
|
|
|
use color_eyre::eyre::Report;
|
|
|
|
use once_cell::sync::Lazy;
|
2020-06-24 11:30:20 -07:00
|
|
|
use std::sync::Arc;
|
2020-08-15 15:45:37 -07:00
|
|
|
use zebra_chain::{block::Block, parameters::Network, serialization::ZcashDeserialize};
|
2021-06-03 15:48:40 -07:00
|
|
|
use zebra_test::transcript::{ExpectedTranscriptError, Transcript};
|
2020-06-22 21:31:44 -07:00
|
|
|
|
|
|
|
use zebra_state::*;
|
|
|
|
|
2021-06-03 15:48:40 -07:00
|
|
|
static COMMIT_FINALIZED_BLOCK_MAINNET: Lazy<
|
|
|
|
Vec<(Request, Result<Response, ExpectedTranscriptError>)>,
|
|
|
|
> = Lazy::new(|| {
|
|
|
|
let block: Arc<_> =
|
|
|
|
Block::zcash_deserialize(&zebra_test::vectors::BLOCK_MAINNET_GENESIS_BYTES[..])
|
|
|
|
.unwrap()
|
|
|
|
.into();
|
|
|
|
let block2 = block.clone();
|
|
|
|
let hash = block.hash();
|
|
|
|
vec![
|
|
|
|
(
|
|
|
|
Request::CommitFinalizedBlock(block.into()),
|
|
|
|
Ok(Response::Committed(hash)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
Request::Block(hash.into()),
|
|
|
|
Ok(Response::Block(Some(block2))),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
});
|
2020-09-04 02:50:25 -07:00
|
|
|
|
2021-06-03 15:48:40 -07:00
|
|
|
static COMMIT_FINALIZED_BLOCK_TESTNET: Lazy<
|
|
|
|
Vec<(Request, Result<Response, ExpectedTranscriptError>)>,
|
|
|
|
> = Lazy::new(|| {
|
|
|
|
let block: Arc<_> =
|
|
|
|
Block::zcash_deserialize(&zebra_test::vectors::BLOCK_TESTNET_GENESIS_BYTES[..])
|
|
|
|
.unwrap()
|
|
|
|
.into();
|
|
|
|
let block2 = block.clone();
|
|
|
|
let hash = block.hash();
|
|
|
|
vec![
|
|
|
|
(
|
|
|
|
Request::CommitFinalizedBlock(block.into()),
|
|
|
|
Ok(Response::Committed(hash)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
Request::Block(hash.into()),
|
|
|
|
Ok(Response::Block(Some(block2))),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
});
|
2020-06-22 21:31:44 -07:00
|
|
|
|
|
|
|
#[tokio::test]
|
2020-07-26 16:57:18 -07:00
|
|
|
async fn check_transcripts_mainnet() -> Result<(), Report> {
|
2020-08-15 15:45:37 -07:00
|
|
|
check_transcripts(Network::Mainnet).await
|
2020-07-26 16:57:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn check_transcripts_testnet() -> Result<(), Report> {
|
2020-08-15 15:45:37 -07:00
|
|
|
check_transcripts(Network::Testnet).await
|
2020-07-23 04:12:20 -07:00
|
|
|
}
|
|
|
|
|
2020-07-17 15:19:00 -07:00
|
|
|
#[spandoc::spandoc]
|
2020-07-26 16:57:18 -07:00
|
|
|
async fn check_transcripts(network: Network) -> Result<(), Report> {
|
2020-06-24 11:30:20 -07:00
|
|
|
zebra_test::init();
|
2020-06-22 21:31:44 -07:00
|
|
|
|
2020-09-09 17:59:58 -07:00
|
|
|
let mainnet_transcript = &[&COMMIT_FINALIZED_BLOCK_MAINNET];
|
|
|
|
let testnet_transcript = &[&COMMIT_FINALIZED_BLOCK_TESTNET];
|
2020-08-04 13:39:32 -07:00
|
|
|
|
|
|
|
for transcript_data in match network {
|
2020-09-04 02:50:25 -07:00
|
|
|
Network::Mainnet => mainnet_transcript,
|
2020-08-04 13:39:32 -07:00
|
|
|
Network::Testnet => testnet_transcript,
|
|
|
|
} {
|
2021-09-01 15:31:16 -07:00
|
|
|
let (service, _, _) = zebra_state::init(Config::ephemeral(), network);
|
2020-06-22 21:31:44 -07:00
|
|
|
let transcript = Transcript::from(transcript_data.iter().cloned());
|
2020-07-17 15:19:00 -07:00
|
|
|
/// SPANDOC: check the on disk service against the transcript
|
2020-06-22 21:31:44 -07:00
|
|
|
transcript.check(service).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|