Move zebra_state::service::check tests to their own module (#2483)
This commit is contained in:
parent
82696b150b
commit
e49f96caf7
|
|
@ -17,6 +17,8 @@ use super::check;
|
||||||
use difficulty::{AdjustedDifficulty, POW_MEDIAN_BLOCK_SPAN};
|
use difficulty::{AdjustedDifficulty, POW_MEDIAN_BLOCK_SPAN};
|
||||||
|
|
||||||
pub(crate) mod difficulty;
|
pub(crate) mod difficulty;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
/// Check that `block` is contextually valid for `network`, based on the
|
/// Check that `block` is contextually valid for `network`, based on the
|
||||||
/// `finalized_tip_height` and `relevant_chain`.
|
/// `finalized_tip_height` and `relevant_chain`.
|
||||||
|
|
@ -167,55 +169,3 @@ fn difficulty_threshold_is_valid(
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use zebra_chain::serialization::ZcashDeserializeInto;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_orphan_consensus_check() {
|
|
||||||
zebra_test::init();
|
|
||||||
|
|
||||||
let height = zebra_test::vectors::BLOCK_MAINNET_347499_BYTES
|
|
||||||
.zcash_deserialize_into::<Arc<Block>>()
|
|
||||||
.unwrap()
|
|
||||||
.coinbase_height()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
block_is_not_orphaned(block::Height(0), height).expect("tip is lower so it should be fine");
|
|
||||||
block_is_not_orphaned(block::Height(347498), height)
|
|
||||||
.expect("tip is lower so it should be fine");
|
|
||||||
block_is_not_orphaned(block::Height(347499), height)
|
|
||||||
.expect_err("tip is equal so it should error");
|
|
||||||
block_is_not_orphaned(block::Height(500000), height)
|
|
||||||
.expect_err("tip is higher so it should error");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_sequential_height_check() {
|
|
||||||
zebra_test::init();
|
|
||||||
|
|
||||||
let height = zebra_test::vectors::BLOCK_MAINNET_347499_BYTES
|
|
||||||
.zcash_deserialize_into::<Arc<Block>>()
|
|
||||||
.unwrap()
|
|
||||||
.coinbase_height()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
height_one_more_than_parent_height(block::Height(0), height)
|
|
||||||
.expect_err("block is much lower, should panic");
|
|
||||||
height_one_more_than_parent_height(block::Height(347497), height)
|
|
||||||
.expect_err("parent height is 2 less, should panic");
|
|
||||||
height_one_more_than_parent_height(block::Height(347498), height)
|
|
||||||
.expect("parent height is 1 less, should be good");
|
|
||||||
height_one_more_than_parent_height(block::Height(347499), height)
|
|
||||||
.expect_err("parent height is equal, should panic");
|
|
||||||
height_one_more_than_parent_height(block::Height(347500), height)
|
|
||||||
.expect_err("parent height is way more, should panic");
|
|
||||||
height_one_more_than_parent_height(block::Height(500000), height)
|
|
||||||
.expect_err("parent height is way more, should panic");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
//! Tests for state contextual validation checks.
|
||||||
|
|
||||||
|
mod vectors;
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
//! Fixed test vectors for state contextual validation checks.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use zebra_chain::serialization::ZcashDeserializeInto;
|
||||||
|
|
||||||
|
use super::super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_orphan_consensus_check() {
|
||||||
|
zebra_test::init();
|
||||||
|
|
||||||
|
let height = zebra_test::vectors::BLOCK_MAINNET_347499_BYTES
|
||||||
|
.zcash_deserialize_into::<Arc<Block>>()
|
||||||
|
.unwrap()
|
||||||
|
.coinbase_height()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
block_is_not_orphaned(block::Height(0), height).expect("tip is lower so it should be fine");
|
||||||
|
block_is_not_orphaned(block::Height(347498), height)
|
||||||
|
.expect("tip is lower so it should be fine");
|
||||||
|
block_is_not_orphaned(block::Height(347499), height)
|
||||||
|
.expect_err("tip is equal so it should error");
|
||||||
|
block_is_not_orphaned(block::Height(500000), height)
|
||||||
|
.expect_err("tip is higher so it should error");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sequential_height_check() {
|
||||||
|
zebra_test::init();
|
||||||
|
|
||||||
|
let height = zebra_test::vectors::BLOCK_MAINNET_347499_BYTES
|
||||||
|
.zcash_deserialize_into::<Arc<Block>>()
|
||||||
|
.unwrap()
|
||||||
|
.coinbase_height()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
height_one_more_than_parent_height(block::Height(0), height)
|
||||||
|
.expect_err("block is much lower, should panic");
|
||||||
|
height_one_more_than_parent_height(block::Height(347497), height)
|
||||||
|
.expect_err("parent height is 2 less, should panic");
|
||||||
|
height_one_more_than_parent_height(block::Height(347498), height)
|
||||||
|
.expect("parent height is 1 less, should be good");
|
||||||
|
height_one_more_than_parent_height(block::Height(347499), height)
|
||||||
|
.expect_err("parent height is equal, should panic");
|
||||||
|
height_one_more_than_parent_height(block::Height(347500), height)
|
||||||
|
.expect_err("parent height is way more, should panic");
|
||||||
|
height_one_more_than_parent_height(block::Height(500000), height)
|
||||||
|
.expect_err("parent height is way more, should panic");
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue