change(tests): Remove Matches on Network From Tests (#8295)
* added functions for fetching block vectors * inserted new network methods for vector fetching into zebra-chain * changed tag back to test/feature=branch * changed tag back to test/feature=branch * changed tag back to test/feature=branch * changed feature tag to proptest-impl, started implementing in zebra-consensus tests * adding methods to zebra-consensus, lifetime error in src/transaction/tests.rs, needs refactoring * finished adding methods to zebra-consensus * finished adding new methods to zebrad * added new methods to zebra-rpc and zebra-scan * finished removing statements matching on Network from tests * updated new error message * changed get_block_bytes() and get_block_sapling_roots_bytes to return option and removed serialization error types as per requested changes in PR review * removed match statements from zebra_chain::transaction::arbitrary::test_transactions() and new zebra-grpc tests * moved zebra-chain::test_utils to zebra-chain::test * removed get_ prefix from getter methods * renamed zebra-chain::test to zebra-chain::tests * renamed zebra-chain::test to zebra-chain::tests * fixed clippy warnings * changed block_map to return clone
This commit is contained in:
parent
e64f3dcddd
commit
9b91d4bc0e
|
@ -208,16 +208,7 @@ fn block_test_vectors_height_testnet() {
|
||||||
/// Test that the block test vector indexes match the heights in the block data,
|
/// Test that the block test vector indexes match the heights in the block data,
|
||||||
/// and that each post-sapling block has a corresponding final sapling root.
|
/// and that each post-sapling block has a corresponding final sapling root.
|
||||||
fn block_test_vectors_height(network: Network) {
|
fn block_test_vectors_height(network: Network) {
|
||||||
let (block_iter, sapling_roots) = match network {
|
let (block_iter, sapling_roots) = network.block_sapling_roots_iter();
|
||||||
Mainnet => (
|
|
||||||
zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
zebra_test::vectors::MAINNET_FINAL_SAPLING_ROOTS.clone(),
|
|
||||||
),
|
|
||||||
Testnet => (
|
|
||||||
zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
zebra_test::vectors::TESTNET_FINAL_SAPLING_ROOTS.clone(),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (&height, block) in block_iter {
|
for (&height, block) in block_iter {
|
||||||
let block = block
|
let block = block
|
||||||
|
@ -262,16 +253,7 @@ fn block_commitment_testnet() {
|
||||||
///
|
///
|
||||||
/// TODO: add chain history test vectors?
|
/// TODO: add chain history test vectors?
|
||||||
fn block_commitment(network: Network) {
|
fn block_commitment(network: Network) {
|
||||||
let (block_iter, sapling_roots) = match network {
|
let (block_iter, sapling_roots) = network.block_sapling_roots_iter();
|
||||||
Mainnet => (
|
|
||||||
zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
zebra_test::vectors::MAINNET_FINAL_SAPLING_ROOTS.clone(),
|
|
||||||
),
|
|
||||||
Testnet => (
|
|
||||||
zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
zebra_test::vectors::TESTNET_FINAL_SAPLING_ROOTS.clone(),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (height, block) in block_iter {
|
for (height, block) in block_iter {
|
||||||
let block = block
|
let block = block
|
||||||
|
|
|
@ -13,9 +13,6 @@ use crate::{
|
||||||
|
|
||||||
use color_eyre::eyre;
|
use color_eyre::eyre;
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use zebra_test::vectors::{
|
|
||||||
MAINNET_BLOCKS, MAINNET_FINAL_SAPLING_ROOTS, TESTNET_BLOCKS, TESTNET_FINAL_SAPLING_ROOTS,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Test the history tree using the activation block of a network upgrade
|
/// Test the history tree using the activation block of a network upgrade
|
||||||
/// and its next block.
|
/// and its next block.
|
||||||
|
@ -36,10 +33,8 @@ fn push_and_prune_for_network_upgrade(
|
||||||
network: Network,
|
network: Network,
|
||||||
network_upgrade: NetworkUpgrade,
|
network_upgrade: NetworkUpgrade,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (blocks, sapling_roots) = match network {
|
let (blocks, sapling_roots) = network.block_sapling_roots_map();
|
||||||
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
|
|
||||||
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
|
|
||||||
};
|
|
||||||
let height = network_upgrade.activation_height(network).unwrap().0;
|
let height = network_upgrade.activation_height(network).unwrap().0;
|
||||||
|
|
||||||
// Load first block (activation block of the given network upgrade)
|
// Load first block (activation block of the given network upgrade)
|
||||||
|
@ -120,10 +115,8 @@ fn upgrade() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upgrade_for_network_upgrade(network: Network, network_upgrade: NetworkUpgrade) -> Result<()> {
|
fn upgrade_for_network_upgrade(network: Network, network_upgrade: NetworkUpgrade) -> Result<()> {
|
||||||
let (blocks, sapling_roots) = match network {
|
let (blocks, sapling_roots) = network.block_sapling_roots_map();
|
||||||
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
|
|
||||||
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
|
|
||||||
};
|
|
||||||
let height = network_upgrade.activation_height(network).unwrap().0;
|
let height = network_upgrade.activation_height(network).unwrap().0;
|
||||||
|
|
||||||
// Load previous block (the block before the activation block of the given network upgrade)
|
// Load previous block (the block before the activation block of the given network upgrade)
|
||||||
|
|
|
@ -43,6 +43,9 @@ pub mod work;
|
||||||
#[cfg(any(test, feature = "proptest-impl"))]
|
#[cfg(any(test, feature = "proptest-impl"))]
|
||||||
pub use block::LedgerState;
|
pub use block::LedgerState;
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "proptest-impl"))]
|
||||||
|
pub mod tests;
|
||||||
|
|
||||||
/// Error type alias to make working with generic errors easier.
|
/// Error type alias to make working with generic errors easier.
|
||||||
///
|
///
|
||||||
/// Note: the 'static lifetime bound means that the *type* cannot have any
|
/// Note: the 'static lifetime bound means that the *type* cannot have any
|
||||||
|
|
|
@ -6,9 +6,6 @@ use crate::{
|
||||||
use crate::primitives::zcash_history::*;
|
use crate::primitives::zcash_history::*;
|
||||||
use color_eyre::eyre;
|
use color_eyre::eyre;
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use zebra_test::vectors::{
|
|
||||||
MAINNET_BLOCKS, MAINNET_FINAL_SAPLING_ROOTS, TESTNET_BLOCKS, TESTNET_FINAL_SAPLING_ROOTS,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Test the MMR tree using the activation block of a network upgrade
|
/// Test the MMR tree using the activation block of a network upgrade
|
||||||
/// and its next block.
|
/// and its next block.
|
||||||
|
@ -22,10 +19,8 @@ fn tree() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tree_for_network_upgrade(network: Network, network_upgrade: NetworkUpgrade) -> Result<()> {
|
fn tree_for_network_upgrade(network: Network, network_upgrade: NetworkUpgrade) -> Result<()> {
|
||||||
let (blocks, sapling_roots) = match network {
|
let (blocks, sapling_roots) = network.block_sapling_roots_map();
|
||||||
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
|
|
||||||
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
|
|
||||||
};
|
|
||||||
let height = network_upgrade.activation_height(network).unwrap().0;
|
let height = network_upgrade.activation_height(network).unwrap().0;
|
||||||
|
|
||||||
// Load Block 0 (activation block of the given network upgrade)
|
// Load Block 0 (activation block of the given network upgrade)
|
||||||
|
|
|
@ -9,9 +9,6 @@ use crate::parameters::NetworkUpgrade;
|
||||||
use crate::sapling::{self, tree::*};
|
use crate::sapling::{self, tree::*};
|
||||||
use crate::serialization::ZcashDeserializeInto;
|
use crate::serialization::ZcashDeserializeInto;
|
||||||
use crate::{parameters::Network, sapling::tests::test_vectors};
|
use crate::{parameters::Network, sapling::tests::test_vectors};
|
||||||
use zebra_test::vectors::{
|
|
||||||
MAINNET_BLOCKS, MAINNET_FINAL_SAPLING_ROOTS, TESTNET_BLOCKS, TESTNET_FINAL_SAPLING_ROOTS,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_roots() {
|
fn empty_roots() {
|
||||||
|
@ -60,10 +57,8 @@ fn incremental_roots_with_blocks() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn incremental_roots_with_blocks_for_network(network: Network) -> Result<()> {
|
fn incremental_roots_with_blocks_for_network(network: Network) -> Result<()> {
|
||||||
let (blocks, sapling_roots) = match network {
|
let (blocks, sapling_roots) = network.block_sapling_roots_map();
|
||||||
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
|
|
||||||
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
|
|
||||||
};
|
|
||||||
let height = NetworkUpgrade::Sapling
|
let height = NetworkUpgrade::Sapling
|
||||||
.activation_height(network)
|
.activation_height(network)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -6,8 +6,6 @@ use color_eyre::eyre;
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use hex::FromHex;
|
use hex::FromHex;
|
||||||
|
|
||||||
use zebra_test::vectors;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
block::Block,
|
block::Block,
|
||||||
parameters::{Network, NetworkUpgrade},
|
parameters::{Network, NetworkUpgrade},
|
||||||
|
@ -88,25 +86,8 @@ fn incremental_roots_with_blocks() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn incremental_roots_with_blocks_for_network(network: Network) -> Result<()> {
|
fn incremental_roots_with_blocks_for_network(network: Network) -> Result<()> {
|
||||||
// The mainnet block height at which the first JoinSplit occurred.
|
|
||||||
const MAINNET_FIRST_JOINSPLIT_HEIGHT: u32 = 396;
|
|
||||||
|
|
||||||
// The testnet block height at which the first JoinSplit occurred.
|
|
||||||
const TESTNET_FIRST_JOINSPLIT_HEIGHT: u32 = 2259;
|
|
||||||
|
|
||||||
// Load the test data.
|
// Load the test data.
|
||||||
let (blocks, sprout_roots, next_height) = match network {
|
let (blocks, sprout_roots, next_height) = network.block_sprout_roots_height();
|
||||||
Network::Mainnet => (
|
|
||||||
&*vectors::MAINNET_BLOCKS,
|
|
||||||
&*vectors::MAINNET_FINAL_SPROUT_ROOTS,
|
|
||||||
MAINNET_FIRST_JOINSPLIT_HEIGHT,
|
|
||||||
),
|
|
||||||
Network::Testnet => (
|
|
||||||
&*vectors::TESTNET_BLOCKS,
|
|
||||||
&*vectors::TESTNET_FINAL_SPROUT_ROOTS,
|
|
||||||
TESTNET_FIRST_JOINSPLIT_HEIGHT,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Load the Genesis height.
|
// Load the Genesis height.
|
||||||
let genesis_height = NetworkUpgrade::Genesis
|
let genesis_height = NetworkUpgrade::Genesis
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
//!Chain functionality for fetching test vectors.
|
||||||
|
//!
|
||||||
|
|
||||||
|
mod vectors;
|
|
@ -0,0 +1,154 @@
|
||||||
|
//! Network methods for fetching blockchain vectors.
|
||||||
|
//!
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use crate::{block::Block, parameters::Network, serialization::ZcashDeserializeInto};
|
||||||
|
|
||||||
|
use zebra_test::vectors::{
|
||||||
|
BLOCK_MAINNET_1046400_BYTES, BLOCK_MAINNET_653599_BYTES, BLOCK_MAINNET_982681_BYTES,
|
||||||
|
BLOCK_TESTNET_1116000_BYTES, BLOCK_TESTNET_583999_BYTES, BLOCK_TESTNET_925483_BYTES,
|
||||||
|
CONTINUOUS_MAINNET_BLOCKS, CONTINUOUS_TESTNET_BLOCKS, MAINNET_BLOCKS,
|
||||||
|
MAINNET_FINAL_SAPLING_ROOTS, MAINNET_FINAL_SPROUT_ROOTS,
|
||||||
|
SAPLING_FINAL_ROOT_MAINNET_1046400_BYTES, SAPLING_FINAL_ROOT_TESTNET_1116000_BYTES,
|
||||||
|
TESTNET_BLOCKS, TESTNET_FINAL_SAPLING_ROOTS, TESTNET_FINAL_SPROUT_ROOTS,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Network methods for fetching blockchain vectors.
|
||||||
|
impl Network {
|
||||||
|
/// Returns true if network is of type Mainnet.
|
||||||
|
pub fn is_mainnet(&self) -> bool {
|
||||||
|
matches!(self, Network::Mainnet)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns iterator over blocks.
|
||||||
|
pub fn block_iter(&self) -> std::collections::btree_map::Iter<'static, u32, &'static [u8]> {
|
||||||
|
if self.is_mainnet() {
|
||||||
|
MAINNET_BLOCKS.iter()
|
||||||
|
} else {
|
||||||
|
TESTNET_BLOCKS.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
pub fn block_map(&self) -> BTreeMap<u32, &'static [u8]> {
|
||||||
|
if self.is_mainnet() {
|
||||||
|
zebra_test::vectors::MAINNET_BLOCKS.clone()
|
||||||
|
} else {
|
||||||
|
zebra_test::vectors::TESTNET_BLOCKS.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns genesis block for chain.
|
||||||
|
pub fn gen_block(&self) -> std::option::Option<&&[u8]> {
|
||||||
|
if self.is_mainnet() {
|
||||||
|
MAINNET_BLOCKS.get(&0)
|
||||||
|
} else {
|
||||||
|
TESTNET_BLOCKS.get(&0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns block bytes
|
||||||
|
pub fn test_block(&self, main_height: u32, test_height: u32) -> Option<Block> {
|
||||||
|
match (self.is_mainnet(), main_height, test_height) {
|
||||||
|
(true, 653_599, _) => BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into().ok(),
|
||||||
|
(true, 982_681, _) => BLOCK_MAINNET_982681_BYTES.zcash_deserialize_into().ok(),
|
||||||
|
(false, _, 583_999) => BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into().ok(),
|
||||||
|
(false, _, 925_483) => BLOCK_TESTNET_925483_BYTES.zcash_deserialize_into().ok(),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns iterator over blockchain.
|
||||||
|
pub fn blockchain_iter(&self) -> std::collections::btree_map::Iter<'_, u32, &[u8]> {
|
||||||
|
if self.is_mainnet() {
|
||||||
|
CONTINUOUS_MAINNET_BLOCKS.iter()
|
||||||
|
} else {
|
||||||
|
CONTINUOUS_TESTNET_BLOCKS.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns BTreemap of blockchain.
|
||||||
|
pub fn blockchain_map(&self) -> &BTreeMap<u32, &'static [u8]> {
|
||||||
|
if self.is_mainnet() {
|
||||||
|
&CONTINUOUS_MAINNET_BLOCKS
|
||||||
|
} else {
|
||||||
|
&CONTINUOUS_TESTNET_BLOCKS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns iterator over blocks and sapling roots.
|
||||||
|
pub fn block_sapling_roots_iter(
|
||||||
|
&self,
|
||||||
|
) -> (
|
||||||
|
std::collections::btree_map::Iter<'_, u32, &[u8]>,
|
||||||
|
std::collections::BTreeMap<u32, &[u8; 32]>,
|
||||||
|
) {
|
||||||
|
if self.is_mainnet() {
|
||||||
|
(MAINNET_BLOCKS.iter(), MAINNET_FINAL_SAPLING_ROOTS.clone())
|
||||||
|
} else {
|
||||||
|
(TESTNET_BLOCKS.iter(), TESTNET_FINAL_SAPLING_ROOTS.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns BTreemap of blocks and sapling roots.
|
||||||
|
pub fn block_sapling_roots_map(
|
||||||
|
&self,
|
||||||
|
) -> (
|
||||||
|
&std::collections::BTreeMap<u32, &'static [u8]>,
|
||||||
|
&std::collections::BTreeMap<u32, &'static [u8; 32]>,
|
||||||
|
) {
|
||||||
|
if self.is_mainnet() {
|
||||||
|
(&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS)
|
||||||
|
} else {
|
||||||
|
(&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns block and sapling root bytes
|
||||||
|
pub fn test_block_sapling_roots(
|
||||||
|
&self,
|
||||||
|
main_height: u32,
|
||||||
|
test_height: u32,
|
||||||
|
) -> Option<(&[u8], [u8; 32])> {
|
||||||
|
match (self.is_mainnet(), main_height, test_height) {
|
||||||
|
(true, 1_046_400, _) => Some((
|
||||||
|
&BLOCK_MAINNET_1046400_BYTES[..],
|
||||||
|
*SAPLING_FINAL_ROOT_MAINNET_1046400_BYTES,
|
||||||
|
)),
|
||||||
|
(false, _, 1_116_000) => Some((
|
||||||
|
&BLOCK_TESTNET_1116000_BYTES[..],
|
||||||
|
*SAPLING_FINAL_ROOT_TESTNET_1116000_BYTES,
|
||||||
|
)),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns BTreemap of blocks and sprout roots, and last split height.
|
||||||
|
pub fn block_sprout_roots_height(
|
||||||
|
&self,
|
||||||
|
) -> (
|
||||||
|
&std::collections::BTreeMap<u32, &'static [u8]>,
|
||||||
|
&std::collections::BTreeMap<u32, &'static [u8; 32]>,
|
||||||
|
u32,
|
||||||
|
) {
|
||||||
|
// The mainnet block height at which the first JoinSplit occurred.
|
||||||
|
const MAINNET_FIRST_JOINSPLIT_HEIGHT: u32 = 396;
|
||||||
|
|
||||||
|
// The testnet block height at which the first JoinSplit occurred.
|
||||||
|
const TESTNET_FIRST_JOINSPLIT_HEIGHT: u32 = 2259;
|
||||||
|
if self.is_mainnet() {
|
||||||
|
(
|
||||||
|
&*MAINNET_BLOCKS,
|
||||||
|
&*MAINNET_FINAL_SPROUT_ROOTS,
|
||||||
|
MAINNET_FIRST_JOINSPLIT_HEIGHT,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
&*TESTNET_BLOCKS,
|
||||||
|
&*TESTNET_FINAL_SPROUT_ROOTS,
|
||||||
|
TESTNET_FIRST_JOINSPLIT_HEIGHT,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -995,10 +995,7 @@ fn sapling_spend_v4_to_fake_v5(
|
||||||
pub fn test_transactions(
|
pub fn test_transactions(
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> impl DoubleEndedIterator<Item = (block::Height, Arc<Transaction>)> {
|
) -> impl DoubleEndedIterator<Item = (block::Height, Arc<Transaction>)> {
|
||||||
let blocks = match network {
|
let blocks = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
transactions_from_blocks(blocks)
|
transactions_from_blocks(blocks)
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,10 +349,7 @@ fn fake_v5_round_trip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fake_v5_round_trip_for_network(network: Network) {
|
fn fake_v5_round_trip_for_network(network: Network) {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let overwinter_activation_height = NetworkUpgrade::Overwinter
|
let overwinter_activation_height = NetworkUpgrade::Overwinter
|
||||||
.activation_height(network)
|
.activation_height(network)
|
||||||
|
@ -500,10 +497,7 @@ fn fake_v5_librustzcash_round_trip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fake_v5_librustzcash_round_trip_for_network(network: Network) {
|
fn fake_v5_librustzcash_round_trip_for_network(network: Network) {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let overwinter_activation_height = NetworkUpgrade::Overwinter
|
let overwinter_activation_height = NetworkUpgrade::Overwinter
|
||||||
.activation_height(network)
|
.activation_height(network)
|
||||||
|
@ -943,10 +937,7 @@ fn binding_signatures() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn binding_signatures_for_network(network: Network) {
|
fn binding_signatures_for_network(network: Network) {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (height, bytes) in block_iter {
|
for (height, bytes) in block_iter {
|
||||||
let upgrade = NetworkUpgrade::current(network, Height(*height));
|
let upgrade = NetworkUpgrade::current(network, Height(*height));
|
||||||
|
|
|
@ -92,10 +92,7 @@ fn get_transparent_output_address_with_blocks() {
|
||||||
/// Test that the block test vector indexes match the heights in the block data,
|
/// Test that the block test vector indexes match the heights in the block data,
|
||||||
/// and that each post-sapling block has a corresponding final sapling root.
|
/// and that each post-sapling block has a corresponding final sapling root.
|
||||||
fn get_transparent_output_address_with_blocks_for_network(network: Network) {
|
fn get_transparent_output_address_with_blocks_for_network(network: Network) {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut valid_addresses = 0;
|
let mut valid_addresses = 0;
|
||||||
|
|
||||||
|
|
|
@ -273,10 +273,7 @@ fn block_difficulty() -> Result<(), Report> {
|
||||||
fn block_difficulty_for_network(network: Network) -> Result<(), Report> {
|
fn block_difficulty_for_network(network: Network) -> Result<(), Report> {
|
||||||
let _init_guard = zebra_test::init();
|
let _init_guard = zebra_test::init();
|
||||||
|
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let diff_zero = ExpandedDifficulty(U256::zero());
|
let diff_zero = ExpandedDifficulty(U256::zero());
|
||||||
let diff_one = ExpandedDifficulty(U256::one());
|
let diff_one = ExpandedDifficulty(U256::one());
|
||||||
|
@ -362,10 +359,7 @@ fn genesis_block_difficulty() -> Result<(), Report> {
|
||||||
fn genesis_block_difficulty_for_network(network: Network) -> Result<(), Report> {
|
fn genesis_block_difficulty_for_network(network: Network) -> Result<(), Report> {
|
||||||
let _init_guard = zebra_test::init();
|
let _init_guard = zebra_test::init();
|
||||||
|
|
||||||
let block = match network {
|
let block = network.gen_block();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.get(&0),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.get(&0),
|
|
||||||
};
|
|
||||||
|
|
||||||
let block = block.expect("test vectors contain the genesis block");
|
let block = block.expect("test vectors contain the genesis block");
|
||||||
let block = Block::zcash_deserialize(&block[..]).expect("block test vector should deserialize");
|
let block = Block::zcash_deserialize(&block[..]).expect("block test vector should deserialize");
|
||||||
|
|
|
@ -189,10 +189,7 @@ fn difficulty_is_valid_for_historical_blocks() -> Result<(), Report> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn difficulty_is_valid_for_network(network: Network) -> Result<(), Report> {
|
fn difficulty_is_valid_for_network(network: Network) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (&height, block) in block_iter {
|
for (&height, block) in block_iter {
|
||||||
let block = block
|
let block = block
|
||||||
|
@ -296,10 +293,7 @@ fn subsidy_is_valid_for_historical_blocks() -> Result<(), Report> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subsidy_is_valid_for_network(network: Network) -> Result<(), Report> {
|
fn subsidy_is_valid_for_network(network: Network) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (&height, block) in block_iter {
|
for (&height, block) in block_iter {
|
||||||
let block = block
|
let block = block
|
||||||
|
@ -401,10 +395,7 @@ fn funding_stream_validation() -> Result<(), Report> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn funding_stream_validation_for_network(network: Network) -> Result<(), Report> {
|
fn funding_stream_validation_for_network(network: Network) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let canopy_activation_height = NetworkUpgrade::Canopy
|
let canopy_activation_height = NetworkUpgrade::Canopy
|
||||||
.activation_height(network)
|
.activation_height(network)
|
||||||
|
@ -479,10 +470,7 @@ fn miner_fees_validation_success() -> Result<(), Report> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn miner_fees_validation_for_network(network: Network) -> Result<(), Report> {
|
fn miner_fees_validation_for_network(network: Network) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (&height, block) in block_iter {
|
for (&height, block) in block_iter {
|
||||||
if Height(height) > SLOW_START_SHIFT {
|
if Height(height) > SLOW_START_SHIFT {
|
||||||
|
@ -568,10 +556,7 @@ fn merkle_root_is_valid() -> Result<(), Report> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merkle_root_is_valid_for_network(network: Network) -> Result<(), Report> {
|
fn merkle_root_is_valid_for_network(network: Network) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (_height, block) in block_iter {
|
for (_height, block) in block_iter {
|
||||||
let block = block
|
let block = block
|
||||||
|
@ -592,10 +577,7 @@ fn merkle_root_is_valid_for_network(network: Network) -> Result<(), Report> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merkle_root_fake_v5_for_network(network: Network) -> Result<(), Report> {
|
fn merkle_root_fake_v5_for_network(network: Network) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (height, block) in block_iter {
|
for (height, block) in block_iter {
|
||||||
let mut block = block
|
let mut block = block
|
||||||
|
@ -707,10 +689,7 @@ fn transaction_expiration_height_validation() -> Result<(), Report> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_expiration_height_for_network(network: Network) -> Result<(), Report> {
|
fn transaction_expiration_height_for_network(network: Network) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (&height, block) in block_iter {
|
for (&height, block) in block_iter {
|
||||||
let block = Block::zcash_deserialize(&block[..]).expect("block should deserialize");
|
let block = Block::zcash_deserialize(&block[..]).expect("block should deserialize");
|
||||||
|
|
|
@ -233,10 +233,8 @@ async fn continuous_blockchain(
|
||||||
let _init_guard = zebra_test::init();
|
let _init_guard = zebra_test::init();
|
||||||
|
|
||||||
// A continuous blockchain
|
// A continuous blockchain
|
||||||
let blockchain = match network {
|
let blockchain = network.blockchain_iter();
|
||||||
Mainnet => zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS.iter(),
|
|
||||||
Testnet => zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
let blockchain: Vec<_> = blockchain
|
let blockchain: Vec<_> = blockchain
|
||||||
.map(|(height, b)| {
|
.map(|(height, b)| {
|
||||||
let block = Arc::<Block>::zcash_deserialize(*b).unwrap();
|
let block = Arc::<Block>::zcash_deserialize(*b).unwrap();
|
||||||
|
|
|
@ -909,11 +909,7 @@ fn v5_transaction_is_accepted_after_nu5_activation_for_network(network: Network)
|
||||||
let nu5_activation_height = nu5
|
let nu5_activation_height = nu5
|
||||||
.activation_height(network)
|
.activation_height(network)
|
||||||
.expect("NU5 activation height is specified");
|
.expect("NU5 activation height is specified");
|
||||||
|
let blocks = network.block_iter();
|
||||||
let blocks = match network {
|
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let state_service = service_fn(|_| async { unreachable!("Service should not be called") });
|
let state_service = service_fn(|_| async { unreachable!("Service should not be called") });
|
||||||
let verifier = Verifier::new(network, state_service);
|
let verifier = Verifier::new(network, state_service);
|
||||||
|
@ -2772,10 +2768,7 @@ fn coinbase_outputs_are_decryptable_for_historical_blocks() -> Result<(), Report
|
||||||
fn coinbase_outputs_are_decryptable_for_historical_blocks_for_network(
|
fn coinbase_outputs_are_decryptable_for_historical_blocks_for_network(
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> Result<(), Report> {
|
) -> Result<(), Report> {
|
||||||
let block_iter = match network {
|
let block_iter = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut tested_coinbase_txs = 0;
|
let mut tested_coinbase_txs = 0;
|
||||||
let mut tested_non_coinbase_txs = 0;
|
let mut tested_non_coinbase_txs = 0;
|
||||||
|
|
|
@ -81,19 +81,16 @@ async fn test_mocked_getresults_for_network(
|
||||||
.1
|
.1
|
||||||
.by_height
|
.by_height
|
||||||
.len();
|
.len();
|
||||||
match network {
|
if network.is_mainnet() {
|
||||||
Network::Mainnet => {
|
assert_eq!(
|
||||||
assert_eq!(
|
transaction_heights, 3,
|
||||||
transaction_heights, 3,
|
"there should be 3 transaction heights"
|
||||||
"there should be 3 transaction heights"
|
);
|
||||||
);
|
} else {
|
||||||
}
|
assert_eq!(
|
||||||
Network::Testnet => {
|
transaction_heights, 1,
|
||||||
assert_eq!(
|
"there should be 1 transaction height"
|
||||||
transaction_heights, 1,
|
);
|
||||||
"there should be 1 transaction height"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create request, fake empty results and get response
|
// create request, fake empty results and get response
|
||||||
|
@ -150,13 +147,10 @@ async fn test_mocked_clear_results_for_network(
|
||||||
.1
|
.1
|
||||||
.by_height
|
.by_height
|
||||||
.len();
|
.len();
|
||||||
match network {
|
if network.is_mainnet() {
|
||||||
Network::Mainnet => {
|
assert_eq!(transaction_heights, 3);
|
||||||
assert_eq!(transaction_heights, 3);
|
} else {
|
||||||
}
|
assert_eq!(transaction_heights, 1)
|
||||||
Network::Testnet => {
|
|
||||||
assert_eq!(transaction_heights, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create request, fake results and get response
|
// create request, fake results and get response
|
||||||
|
@ -210,13 +204,10 @@ async fn test_mocked_delete_keys_for_network(
|
||||||
.1
|
.1
|
||||||
.by_height
|
.by_height
|
||||||
.len();
|
.len();
|
||||||
match network {
|
if network.is_mainnet() {
|
||||||
Network::Mainnet => {
|
assert_eq!(transaction_heights, 3);
|
||||||
assert_eq!(transaction_heights, 3);
|
} else {
|
||||||
}
|
assert_eq!(transaction_heights, 1);
|
||||||
Network::Testnet => {
|
|
||||||
assert_eq!(transaction_heights, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let delete_keys_response =
|
let delete_keys_response =
|
||||||
|
@ -282,9 +273,10 @@ async fn add_fake_populated_results(
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let zec_pages_sapling_efvk = ZECPAGES_SAPLING_VIEWING_KEY.to_string();
|
let zec_pages_sapling_efvk = ZECPAGES_SAPLING_VIEWING_KEY.to_string();
|
||||||
let mut fake_results = BTreeMap::new();
|
let mut fake_results = BTreeMap::new();
|
||||||
let heights = match network {
|
let heights = if network.is_mainnet() {
|
||||||
Network::Mainnet => vec![Height::MIN, Height(1), Height::MAX],
|
vec![Height::MIN, Height(1), Height::MAX]
|
||||||
Network::Testnet => vec![Height::MIN],
|
} else {
|
||||||
|
vec![Height::MIN]
|
||||||
};
|
};
|
||||||
for fake_result_height in heights {
|
for fake_result_height in heights {
|
||||||
fake_results.insert(
|
fake_results.insert(
|
||||||
|
|
|
@ -44,10 +44,7 @@ async fn test_rpc_response_data() {
|
||||||
|
|
||||||
async fn test_rpc_response_data_for_network(network: Network) {
|
async fn test_rpc_response_data_for_network(network: Network) {
|
||||||
// Create a continuous chain of mainnet and testnet blocks from genesis
|
// Create a continuous chain of mainnet and testnet blocks from genesis
|
||||||
let block_data = match network {
|
let block_data = network.blockchain_map();
|
||||||
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
|
|
||||||
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
|
|
||||||
};
|
|
||||||
|
|
||||||
let blocks: Vec<Arc<Block>> = block_data
|
let blocks: Vec<Arc<Block>> = block_data
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -413,9 +413,10 @@ pub async fn test_responses<State, ReadState>(
|
||||||
snapshot_rpc_submit_block_invalid(submit_block, &settings);
|
snapshot_rpc_submit_block_invalid(submit_block, &settings);
|
||||||
|
|
||||||
// `validateaddress`
|
// `validateaddress`
|
||||||
let founder_address = match network {
|
let founder_address = if network.is_mainnet() {
|
||||||
Network::Mainnet => "t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR",
|
"t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR"
|
||||||
Network::Testnet => "t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi",
|
} else {
|
||||||
|
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
|
||||||
};
|
};
|
||||||
|
|
||||||
let validate_address = get_block_template_rpc
|
let validate_address = get_block_template_rpc
|
||||||
|
@ -431,9 +432,10 @@ pub async fn test_responses<State, ReadState>(
|
||||||
snapshot_rpc_validateaddress("invalid", validate_address, &settings);
|
snapshot_rpc_validateaddress("invalid", validate_address, &settings);
|
||||||
|
|
||||||
// `z_validateaddress`
|
// `z_validateaddress`
|
||||||
let founder_address = match network {
|
let founder_address = if network.is_mainnet() {
|
||||||
Network::Mainnet => "t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR",
|
"t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR"
|
||||||
Network::Testnet => "t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi",
|
} else {
|
||||||
|
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
|
||||||
};
|
};
|
||||||
|
|
||||||
let z_validate_address = get_block_template_rpc
|
let z_validate_address = get_block_template_rpc
|
||||||
|
|
|
@ -9,20 +9,9 @@ use zebra_chain::{
|
||||||
serialization::ZcashDeserialize,
|
serialization::ZcashDeserialize,
|
||||||
};
|
};
|
||||||
|
|
||||||
use zebra_test::vectors;
|
|
||||||
|
|
||||||
/// Create a history tree with one single block for a network by using Zebra test vectors.
|
/// Create a history tree with one single block for a network by using Zebra test vectors.
|
||||||
pub fn fake_history_tree(network: Network) -> Arc<HistoryTree> {
|
pub fn fake_history_tree(network: Network) -> Arc<HistoryTree> {
|
||||||
let (block, sapling_root) = match network {
|
let (block, sapling_root) = network.test_block_sapling_roots(1046400, 1116000).unwrap();
|
||||||
Network::Mainnet => (
|
|
||||||
&vectors::BLOCK_MAINNET_1046400_BYTES[..],
|
|
||||||
*vectors::SAPLING_FINAL_ROOT_MAINNET_1046400_BYTES,
|
|
||||||
),
|
|
||||||
Network::Testnet => (
|
|
||||||
&vectors::BLOCK_TESTNET_1116000_BYTES[..],
|
|
||||||
*vectors::SAPLING_FINAL_ROOT_TESTNET_1116000_BYTES,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
let block = Arc::<Block>::zcash_deserialize(block).expect("block should deserialize");
|
let block = Arc::<Block>::zcash_deserialize(block).expect("block should deserialize");
|
||||||
let first_sapling_root = Root::try_from(sapling_root).unwrap();
|
let first_sapling_root = Root::try_from(sapling_root).unwrap();
|
||||||
|
|
|
@ -655,14 +655,11 @@ async fn rpc_getaddresstxids_response() {
|
||||||
let _init_guard = zebra_test::init();
|
let _init_guard = zebra_test::init();
|
||||||
|
|
||||||
for network in [Mainnet, Testnet] {
|
for network in [Mainnet, Testnet] {
|
||||||
let blocks: Vec<Arc<Block>> = match network {
|
let blocks: Vec<Arc<Block>> = network
|
||||||
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
|
.blockchain_map()
|
||||||
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
|
.iter()
|
||||||
}
|
.map(|(_height, block_bytes)| block_bytes.zcash_deserialize_into().unwrap())
|
||||||
.iter()
|
.collect();
|
||||||
.map(|(_height, block_bytes)| block_bytes.zcash_deserialize_into().unwrap())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// The first few blocks after genesis send funds to the same founders reward address,
|
// The first few blocks after genesis send funds to the same founders reward address,
|
||||||
// in one output per coinbase transaction.
|
// in one output per coinbase transaction.
|
||||||
//
|
//
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
|
||||||
use zebra_chain::{
|
use zebra_chain::{
|
||||||
block::{Block, Height},
|
block::{Block, Height},
|
||||||
parameters::Network::{self, *},
|
parameters::Network::{self},
|
||||||
serialization::ZcashDeserializeInto,
|
serialization::ZcashDeserializeInto,
|
||||||
transaction,
|
transaction,
|
||||||
};
|
};
|
||||||
|
@ -45,10 +45,7 @@ pub fn add_fake_results(
|
||||||
height: Height,
|
height: Height,
|
||||||
add_progress_marker: bool,
|
add_progress_marker: bool,
|
||||||
) {
|
) {
|
||||||
let blocks = match network {
|
let blocks = network.blockchain_map();
|
||||||
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
|
|
||||||
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
|
|
||||||
};
|
|
||||||
|
|
||||||
let block: Arc<Block> = blocks
|
let block: Arc<Block> = blocks
|
||||||
.get(&height.0)
|
.get(&height.0)
|
||||||
|
|
|
@ -89,10 +89,7 @@ fn test_raw_rocksdb_column_families_with_network(network: Network) {
|
||||||
// Snapshot raw database data for:
|
// Snapshot raw database data for:
|
||||||
// - mainnet and testnet
|
// - mainnet and testnet
|
||||||
// - genesis, block 1, and block 2
|
// - genesis, block 1, and block 2
|
||||||
let blocks = match network {
|
let blocks = network.blockchain_map();
|
||||||
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
|
|
||||||
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
|
|
||||||
};
|
|
||||||
|
|
||||||
// We limit the number of blocks, because the serialized data is a few kilobytes per block.
|
// We limit the number of blocks, because the serialized data is a few kilobytes per block.
|
||||||
for height in 0..=2 {
|
for height in 0..=2 {
|
||||||
|
|
|
@ -181,10 +181,7 @@ fn test_block_and_transaction_data_with_network(network: Network) {
|
||||||
// Snapshot block and transaction database data for:
|
// Snapshot block and transaction database data for:
|
||||||
// - mainnet and testnet
|
// - mainnet and testnet
|
||||||
// - genesis, block 1, and block 2
|
// - genesis, block 1, and block 2
|
||||||
let blocks = match network {
|
let blocks = network.blockchain_map();
|
||||||
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
|
|
||||||
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
|
|
||||||
};
|
|
||||||
|
|
||||||
// We limit the number of blocks, because the serialized data is a few kilobytes per block.
|
// We limit the number of blocks, because the serialized data is a few kilobytes per block.
|
||||||
//
|
//
|
||||||
|
|
|
@ -141,17 +141,10 @@ fn best_chain_wins() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn best_chain_wins_for_network(network: Network) -> Result<()> {
|
fn best_chain_wins_for_network(network: Network) -> Result<()> {
|
||||||
let block1: Arc<Block> = match network {
|
// Since the brand new FinalizedState below will pass a None history tree
|
||||||
// Since the brand new FinalizedState below will pass a None history tree
|
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
||||||
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
// they won't trigger the history tree update in the NonFinalizedState.
|
||||||
// they won't trigger the history tree update in the NonFinalizedState.
|
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
|
||||||
Network::Mainnet => {
|
|
||||||
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
Network::Testnet => {
|
|
||||||
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let block2 = block1.make_fake_child().set_work(10);
|
let block2 = block1.make_fake_child().set_work(10);
|
||||||
let child = block1.make_fake_child().set_work(1);
|
let child = block1.make_fake_child().set_work(1);
|
||||||
|
@ -186,17 +179,10 @@ fn finalize_pops_from_best_chain() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize_pops_from_best_chain_for_network(network: Network) -> Result<()> {
|
fn finalize_pops_from_best_chain_for_network(network: Network) -> Result<()> {
|
||||||
let block1: Arc<Block> = match network {
|
// Since the brand new FinalizedState below will pass a None history tree
|
||||||
// Since the brand new FinalizedState below will pass a None history tree
|
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
||||||
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
// they won't trigger the history tree update in the NonFinalizedState.
|
||||||
// they won't trigger the history tree update in the NonFinalizedState.
|
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
|
||||||
Network::Mainnet => {
|
|
||||||
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
Network::Testnet => {
|
|
||||||
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let block2 = block1.make_fake_child().set_work(10);
|
let block2 = block1.make_fake_child().set_work(10);
|
||||||
let child = block1.make_fake_child().set_work(1);
|
let child = block1.make_fake_child().set_work(1);
|
||||||
|
@ -242,17 +228,10 @@ fn commit_block_extending_best_chain_doesnt_drop_worst_chains() -> Result<()> {
|
||||||
fn commit_block_extending_best_chain_doesnt_drop_worst_chains_for_network(
|
fn commit_block_extending_best_chain_doesnt_drop_worst_chains_for_network(
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let block1: Arc<Block> = match network {
|
// Since the brand new FinalizedState below will pass a None history tree
|
||||||
// Since the brand new FinalizedState below will pass a None history tree
|
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
||||||
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
// they won't trigger the history tree update in the NonFinalizedState.
|
||||||
// they won't trigger the history tree update in the NonFinalizedState.
|
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
|
||||||
Network::Mainnet => {
|
|
||||||
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
Network::Testnet => {
|
|
||||||
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let block2 = block1.make_fake_child().set_work(10);
|
let block2 = block1.make_fake_child().set_work(10);
|
||||||
let child1 = block1.make_fake_child().set_work(1);
|
let child1 = block1.make_fake_child().set_work(1);
|
||||||
|
@ -293,17 +272,10 @@ fn shorter_chain_can_be_best_chain() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shorter_chain_can_be_best_chain_for_network(network: Network) -> Result<()> {
|
fn shorter_chain_can_be_best_chain_for_network(network: Network) -> Result<()> {
|
||||||
let block1: Arc<Block> = match network {
|
// Since the brand new FinalizedState below will pass a None history tree
|
||||||
// Since the brand new FinalizedState below will pass a None history tree
|
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
||||||
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
// they won't trigger the history tree update in the NonFinalizedState.
|
||||||
// they won't trigger the history tree update in the NonFinalizedState.
|
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
|
||||||
Network::Mainnet => {
|
|
||||||
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
Network::Testnet => {
|
|
||||||
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let long_chain_block1 = block1.make_fake_child().set_work(1);
|
let long_chain_block1 = block1.make_fake_child().set_work(1);
|
||||||
let long_chain_block2 = long_chain_block1.make_fake_child().set_work(1);
|
let long_chain_block2 = long_chain_block1.make_fake_child().set_work(1);
|
||||||
|
@ -343,17 +315,10 @@ fn longer_chain_with_more_work_wins() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn longer_chain_with_more_work_wins_for_network(network: Network) -> Result<()> {
|
fn longer_chain_with_more_work_wins_for_network(network: Network) -> Result<()> {
|
||||||
let block1: Arc<Block> = match network {
|
// Since the brand new FinalizedState below will pass a None history tree
|
||||||
// Since the brand new FinalizedState below will pass a None history tree
|
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
||||||
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
// they won't trigger the history tree update in the NonFinalizedState.
|
||||||
// they won't trigger the history tree update in the NonFinalizedState.
|
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
|
||||||
Network::Mainnet => {
|
|
||||||
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
Network::Testnet => {
|
|
||||||
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let long_chain_block1 = block1.make_fake_child().set_work(1);
|
let long_chain_block1 = block1.make_fake_child().set_work(1);
|
||||||
let long_chain_block2 = long_chain_block1.make_fake_child().set_work(1);
|
let long_chain_block2 = long_chain_block1.make_fake_child().set_work(1);
|
||||||
|
@ -396,17 +361,10 @@ fn equal_length_goes_to_more_work() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn equal_length_goes_to_more_work_for_network(network: Network) -> Result<()> {
|
fn equal_length_goes_to_more_work_for_network(network: Network) -> Result<()> {
|
||||||
let block1: Arc<Block> = match network {
|
// Since the brand new FinalizedState below will pass a None history tree
|
||||||
// Since the brand new FinalizedState below will pass a None history tree
|
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
||||||
// to the NonFinalizedState, we must use pre-Heartwood blocks since
|
// they won't trigger the history tree update in the NonFinalizedState.
|
||||||
// they won't trigger the history tree update in the NonFinalizedState.
|
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
|
||||||
Network::Mainnet => {
|
|
||||||
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
Network::Testnet => {
|
|
||||||
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let less_work_child = block1.make_fake_child().set_work(1);
|
let less_work_child = block1.make_fake_child().set_work(1);
|
||||||
let more_work_child = block1.make_fake_child().set_work(3);
|
let more_work_child = block1.make_fake_child().set_work(3);
|
||||||
|
@ -447,10 +405,8 @@ fn history_tree_is_updated_for_network_upgrade(
|
||||||
network: Network,
|
network: Network,
|
||||||
network_upgrade: NetworkUpgrade,
|
network_upgrade: NetworkUpgrade,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let blocks = match network {
|
let blocks = network.block_map();
|
||||||
Network::Mainnet => &*zebra_test::vectors::MAINNET_BLOCKS,
|
|
||||||
Network::Testnet => &*zebra_test::vectors::TESTNET_BLOCKS,
|
|
||||||
};
|
|
||||||
let height = network_upgrade.activation_height(network).unwrap().0;
|
let height = network_upgrade.activation_height(network).unwrap().0;
|
||||||
|
|
||||||
let prev_block = Arc::new(
|
let prev_block = Arc::new(
|
||||||
|
@ -548,10 +504,7 @@ fn commitment_is_validated() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commitment_is_validated_for_network_upgrade(network: Network, network_upgrade: NetworkUpgrade) {
|
fn commitment_is_validated_for_network_upgrade(network: Network, network_upgrade: NetworkUpgrade) {
|
||||||
let blocks = match network {
|
let blocks = network.block_map();
|
||||||
Network::Mainnet => &*zebra_test::vectors::MAINNET_BLOCKS,
|
|
||||||
Network::Testnet => &*zebra_test::vectors::TESTNET_BLOCKS,
|
|
||||||
};
|
|
||||||
let height = network_upgrade.activation_height(network).unwrap().0;
|
let height = network_upgrade.activation_height(network).unwrap().0;
|
||||||
|
|
||||||
let prev_block = Arc::new(
|
let prev_block = Arc::new(
|
||||||
|
|
|
@ -562,10 +562,7 @@ fn continuous_empty_blocks_from_test_vectors() -> impl Strategy<
|
||||||
any::<Network>()
|
any::<Network>()
|
||||||
.prop_flat_map(|network| {
|
.prop_flat_map(|network| {
|
||||||
// Select the test vector based on the network
|
// Select the test vector based on the network
|
||||||
let raw_blocks = match network {
|
let raw_blocks = network.blockchain_map();
|
||||||
Network::Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
|
|
||||||
Network::Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Transform the test vector's block bytes into a vector of `SemanticallyVerifiedBlock`s.
|
// Transform the test vector's block bytes into a vector of `SemanticallyVerifiedBlock`s.
|
||||||
let blocks: Vec<_> = raw_blocks
|
let blocks: Vec<_> = raw_blocks
|
||||||
|
|
|
@ -73,10 +73,13 @@ async fn check_transcripts(network: Network) -> Result<(), Report> {
|
||||||
let mainnet_transcript = &[&COMMIT_FINALIZED_BLOCK_MAINNET];
|
let mainnet_transcript = &[&COMMIT_FINALIZED_BLOCK_MAINNET];
|
||||||
let testnet_transcript = &[&COMMIT_FINALIZED_BLOCK_TESTNET];
|
let testnet_transcript = &[&COMMIT_FINALIZED_BLOCK_TESTNET];
|
||||||
|
|
||||||
for transcript_data in match network {
|
let net_data = if network.is_mainnet() {
|
||||||
Network::Mainnet => mainnet_transcript,
|
mainnet_transcript
|
||||||
Network::Testnet => testnet_transcript,
|
} else {
|
||||||
} {
|
testnet_transcript
|
||||||
|
};
|
||||||
|
|
||||||
|
for transcript_data in net_data {
|
||||||
// We're not verifying UTXOs here.
|
// We're not verifying UTXOs here.
|
||||||
let (service, _, _, _) = zebra_state::init(Config::ephemeral(), network, Height::MAX, 0);
|
let (service, _, _, _) = zebra_state::init(Config::ephemeral(), network, Height::MAX, 0);
|
||||||
let transcript = Transcript::from(transcript_data.iter().cloned());
|
let transcript = Transcript::from(transcript_data.iter().cloned());
|
||||||
|
|
|
@ -17,10 +17,7 @@ pub fn unmined_transactions_in_blocks(
|
||||||
block_height_range: impl RangeBounds<u32>,
|
block_height_range: impl RangeBounds<u32>,
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> impl DoubleEndedIterator<Item = VerifiedUnminedTx> {
|
) -> impl DoubleEndedIterator<Item = VerifiedUnminedTx> {
|
||||||
let blocks = match network {
|
let blocks = network.block_iter();
|
||||||
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
|
|
||||||
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Deserialize the blocks that are selected based on the specified `block_height_range`.
|
// Deserialize the blocks that are selected based on the specified `block_height_range`.
|
||||||
let selected_blocks = blocks
|
let selected_blocks = blocks
|
||||||
|
|
|
@ -8,7 +8,6 @@ use zebra_chain::{
|
||||||
amount::Amount,
|
amount::Amount,
|
||||||
block::{Block, Height},
|
block::{Block, Height},
|
||||||
parameters::Network,
|
parameters::Network,
|
||||||
serialization::ZcashDeserializeInto,
|
|
||||||
transaction::{UnminedTxId, VerifiedUnminedTx},
|
transaction::{UnminedTxId, VerifiedUnminedTx},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -252,14 +251,7 @@ fn mempool_expired_basic_for_network(network: Network) -> Result<()> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let block: Block = match network {
|
let block: Block = network.test_block(982681, 925483).unwrap();
|
||||||
Network::Mainnet => {
|
|
||||||
zebra_test::vectors::BLOCK_MAINNET_982681_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
Network::Testnet => {
|
|
||||||
zebra_test::vectors::BLOCK_TESTNET_925483_BYTES.zcash_deserialize_into()?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get a test transaction
|
// Get a test transaction
|
||||||
let tx = &*(block.transactions[1]).clone();
|
let tx = &*(block.transactions[1]).clone();
|
||||||
|
|
Loading…
Reference in New Issue