Run the equihash tests on every block test vector
This commit is contained in:
parent
bcb027ebc5
commit
456842aa86
|
@ -29,7 +29,10 @@ pub struct Solution(#[serde(with = "serde_helpers::BigArray")] pub [u8; SOLUTION
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
/// The length of the portion of the header used as input when verifying
|
/// The length of the portion of the header used as input when verifying
|
||||||
/// equihash solutions, in bytes
|
/// equihash solutions, in bytes.
|
||||||
|
///
|
||||||
|
/// Excludes the 32-byte nonce, which is passed as a separate argument
|
||||||
|
/// to the verification function.
|
||||||
pub const INPUT_LENGTH: usize = 4 + 32 * 3 + 4 * 2;
|
pub const INPUT_LENGTH: usize = 4 + 32 * 3 + 4 * 2;
|
||||||
|
|
||||||
/// Returns `Ok(())` if `EquihashSolution` is valid for `header`
|
/// Returns `Ok(())` if `EquihashSolution` is valid for `header`
|
||||||
|
|
|
@ -5,13 +5,18 @@ use crate::{
|
||||||
serialization::{ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize},
|
serialization::{ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Includes the 32-byte nonce.
|
||||||
const EQUIHASH_SOLUTION_BLOCK_OFFSET: usize = equihash::Solution::INPUT_LENGTH + 32;
|
const EQUIHASH_SOLUTION_BLOCK_OFFSET: usize = equihash::Solution::INPUT_LENGTH + 32;
|
||||||
|
|
||||||
|
/// Includes the 3-byte equihash length field.
|
||||||
|
const BLOCK_HEADER_LENGTH: usize = EQUIHASH_SOLUTION_BLOCK_OFFSET + 3 + equihash::SOLUTION_SIZE;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn equihash_solution_test_vector() {
|
fn equihash_solution_test_vectors() {
|
||||||
zebra_test::init();
|
zebra_test::init();
|
||||||
let solution_bytes =
|
|
||||||
&zebra_test::vectors::HEADER_MAINNET_415000_BYTES[EQUIHASH_SOLUTION_BLOCK_OFFSET..];
|
for block in zebra_test::vectors::BLOCKS.iter() {
|
||||||
|
let solution_bytes = &block[EQUIHASH_SOLUTION_BLOCK_OFFSET..BLOCK_HEADER_LENGTH];
|
||||||
|
|
||||||
let solution = solution_bytes
|
let solution = solution_bytes
|
||||||
.zcash_deserialize_into::<equihash::Solution>()
|
.zcash_deserialize_into::<equihash::Solution>()
|
||||||
|
@ -22,16 +27,21 @@ fn equihash_solution_test_vector() {
|
||||||
.zcash_serialize(&mut data)
|
.zcash_serialize(&mut data)
|
||||||
.expect("Test vector EquihashSolution should serialize");
|
.expect("Test vector EquihashSolution should serialize");
|
||||||
|
|
||||||
|
assert_eq!(solution_bytes.len(), data.len());
|
||||||
assert_eq!(solution_bytes, data.as_slice());
|
assert_eq!(solution_bytes, data.as_slice());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn equihash_solution_test_vector_is_valid() -> color_eyre::eyre::Result<()> {
|
fn equihash_solution_test_vectors_are_valid() -> color_eyre::eyre::Result<()> {
|
||||||
zebra_test::init();
|
zebra_test::init();
|
||||||
|
|
||||||
let block = Block::zcash_deserialize(&zebra_test::vectors::BLOCK_MAINNET_415000_BYTES[..])
|
for block in zebra_test::vectors::BLOCKS.iter() {
|
||||||
.expect("block test vector should deserialize");
|
let block =
|
||||||
|
Block::zcash_deserialize(&block[..]).expect("block test vector should deserialize");
|
||||||
|
|
||||||
block.header.solution.check(&block.header)?;
|
block.header.solution.check(&block.header)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue