2020-08-15 00:14:07 -07:00
|
|
|
use super::super::*;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
block::Block,
|
|
|
|
serialization::{ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize},
|
|
|
|
};
|
|
|
|
|
2020-10-28 04:59:57 -07:00
|
|
|
/// Includes the 32-byte nonce.
|
2020-08-15 00:14:07 -07:00
|
|
|
const EQUIHASH_SOLUTION_BLOCK_OFFSET: usize = equihash::Solution::INPUT_LENGTH + 32;
|
|
|
|
|
2020-10-28 04:59:57 -07:00
|
|
|
/// Includes the 3-byte equihash length field.
|
|
|
|
const BLOCK_HEADER_LENGTH: usize = EQUIHASH_SOLUTION_BLOCK_OFFSET + 3 + equihash::SOLUTION_SIZE;
|
|
|
|
|
2020-08-15 00:14:07 -07:00
|
|
|
#[test]
|
2020-10-28 04:59:57 -07:00
|
|
|
fn equihash_solution_test_vectors() {
|
2020-08-15 00:14:07 -07:00
|
|
|
zebra_test::init();
|
|
|
|
|
2020-10-28 04:59:57 -07:00
|
|
|
for block in zebra_test::vectors::BLOCKS.iter() {
|
|
|
|
let solution_bytes = &block[EQUIHASH_SOLUTION_BLOCK_OFFSET..BLOCK_HEADER_LENGTH];
|
|
|
|
|
|
|
|
let solution = solution_bytes
|
|
|
|
.zcash_deserialize_into::<equihash::Solution>()
|
|
|
|
.expect("Test vector EquihashSolution should deserialize");
|
2020-08-15 00:14:07 -07:00
|
|
|
|
2020-10-28 04:59:57 -07:00
|
|
|
let mut data = Vec::new();
|
|
|
|
solution
|
|
|
|
.zcash_serialize(&mut data)
|
|
|
|
.expect("Test vector EquihashSolution should serialize");
|
2020-08-15 00:14:07 -07:00
|
|
|
|
2020-10-28 04:59:57 -07:00
|
|
|
assert_eq!(solution_bytes.len(), data.len());
|
|
|
|
assert_eq!(solution_bytes, data.as_slice());
|
|
|
|
}
|
2020-08-15 00:14:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-10-28 04:59:57 -07:00
|
|
|
fn equihash_solution_test_vectors_are_valid() -> color_eyre::eyre::Result<()> {
|
2020-08-15 00:14:07 -07:00
|
|
|
zebra_test::init();
|
|
|
|
|
2020-10-28 04:59:57 -07:00
|
|
|
for block in zebra_test::vectors::BLOCKS.iter() {
|
|
|
|
let block =
|
|
|
|
Block::zcash_deserialize(&block[..]).expect("block test vector should deserialize");
|
|
|
|
|
|
|
|
block.header.solution.check(&block.header)?;
|
|
|
|
}
|
2020-08-15 00:14:07 -07:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|