Test block time validity for all block test vectors

This commit is contained in:
teor 2020-10-13 08:28:34 +10:00
parent ea284a4d56
commit d241e0b3fc
1 changed files with 22 additions and 19 deletions

View File

@ -230,25 +230,28 @@ fn founders_reward_validation_failure() -> Result<(), Report> {
} }
#[test] #[test]
fn time_check_past_block() { fn time_is_valid_for_historical_blocks() -> Result<(), Report> {
// This block is also verified as part of the BlockVerifier service let block_iter = zebra_test::vectors::BLOCKS.iter();
// tests.
let block =
Arc::<Block>::zcash_deserialize(&zebra_test::vectors::BLOCK_MAINNET_415000_BYTES[..])
.expect("block should deserialize");
let now = Utc::now(); let now = Utc::now();
// This check is non-deterministic, but BLOCK_MAINNET_415000 is for block in block_iter {
// a long time in the past. So it's unlikely that the test machine let block = block
// will have a clock that's far enough in the past for the test to .zcash_deserialize_into::<Block>()
// fail. .expect("block is structurally valid");
check::time_is_valid_at(
&block.header, // This check is non-deterministic, but the block test vectors are
now, // all in the past. So it's unlikely that the test machine will have
&block // a clock that's far enough in the past for the test to fail.
.coinbase_height() check::time_is_valid_at(
.expect("block test vector height should be valid"), &block.header,
&block.hash(), now,
) &block
.expect("the header time from a mainnet block should be valid"); .coinbase_height()
.expect("block test vector height should be valid"),
&block.hash(),
)
.expect("the header time from a historical block should be valid, based on the test machine's local clock. Hint: check the test machine's time, date, and timezone.");
}
Ok(())
} }