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:
idky137 2024-03-05 14:12:25 +00:00 committed by GitHub
parent e64f3dcddd
commit 9b91d4bc0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 268 additions and 302 deletions

View File

@ -208,16 +208,7 @@ fn block_test_vectors_height_testnet() {
/// 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.
fn block_test_vectors_height(network: Network) {
let (block_iter, sapling_roots) = match network {
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(),
),
};
let (block_iter, sapling_roots) = network.block_sapling_roots_iter();
for (&height, block) in block_iter {
let block = block
@ -262,16 +253,7 @@ fn block_commitment_testnet() {
///
/// TODO: add chain history test vectors?
fn block_commitment(network: Network) {
let (block_iter, sapling_roots) = match network {
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(),
),
};
let (block_iter, sapling_roots) = network.block_sapling_roots_iter();
for (height, block) in block_iter {
let block = block

View File

@ -13,9 +13,6 @@ use crate::{
use color_eyre::eyre;
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
/// and its next block.
@ -36,10 +33,8 @@ fn push_and_prune_for_network_upgrade(
network: Network,
network_upgrade: NetworkUpgrade,
) -> Result<()> {
let (blocks, sapling_roots) = match network {
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
};
let (blocks, sapling_roots) = network.block_sapling_roots_map();
let height = network_upgrade.activation_height(network).unwrap().0;
// 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<()> {
let (blocks, sapling_roots) = match network {
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
};
let (blocks, sapling_roots) = network.block_sapling_roots_map();
let height = network_upgrade.activation_height(network).unwrap().0;
// Load previous block (the block before the activation block of the given network upgrade)

View File

@ -43,6 +43,9 @@ pub mod work;
#[cfg(any(test, feature = "proptest-impl"))]
pub use block::LedgerState;
#[cfg(any(test, feature = "proptest-impl"))]
pub mod tests;
/// Error type alias to make working with generic errors easier.
///
/// Note: the 'static lifetime bound means that the *type* cannot have any

View File

@ -6,9 +6,6 @@ use crate::{
use crate::primitives::zcash_history::*;
use color_eyre::eyre;
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
/// and its next block.
@ -22,10 +19,8 @@ fn tree() -> Result<()> {
}
fn tree_for_network_upgrade(network: Network, network_upgrade: NetworkUpgrade) -> Result<()> {
let (blocks, sapling_roots) = match network {
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
};
let (blocks, sapling_roots) = network.block_sapling_roots_map();
let height = network_upgrade.activation_height(network).unwrap().0;
// Load Block 0 (activation block of the given network upgrade)

View File

@ -9,9 +9,6 @@ use crate::parameters::NetworkUpgrade;
use crate::sapling::{self, tree::*};
use crate::serialization::ZcashDeserializeInto;
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]
fn empty_roots() {
@ -60,10 +57,8 @@ fn incremental_roots_with_blocks() -> Result<()> {
}
fn incremental_roots_with_blocks_for_network(network: Network) -> Result<()> {
let (blocks, sapling_roots) = match network {
Network::Mainnet => (&*MAINNET_BLOCKS, &*MAINNET_FINAL_SAPLING_ROOTS),
Network::Testnet => (&*TESTNET_BLOCKS, &*TESTNET_FINAL_SAPLING_ROOTS),
};
let (blocks, sapling_roots) = network.block_sapling_roots_map();
let height = NetworkUpgrade::Sapling
.activation_height(network)
.unwrap()

View File

@ -6,8 +6,6 @@ use color_eyre::eyre;
use eyre::Result;
use hex::FromHex;
use zebra_test::vectors;
use crate::{
block::Block,
parameters::{Network, NetworkUpgrade},
@ -88,25 +86,8 @@ fn incremental_roots_with_blocks() -> 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.
let (blocks, sprout_roots, next_height) = match network {
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,
),
};
let (blocks, sprout_roots, next_height) = network.block_sprout_roots_height();
// Load the Genesis height.
let genesis_height = NetworkUpgrade::Genesis

4
zebra-chain/src/tests.rs Normal file
View File

@ -0,0 +1,4 @@
//!Chain functionality for fetching test vectors.
//!
mod vectors;

View File

@ -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,
)
}
}
}

View File

@ -995,10 +995,7 @@ fn sapling_spend_v4_to_fake_v5(
pub fn test_transactions(
network: Network,
) -> impl DoubleEndedIterator<Item = (block::Height, Arc<Transaction>)> {
let blocks = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let blocks = network.block_iter();
transactions_from_blocks(blocks)
}

View File

@ -349,10 +349,7 @@ fn fake_v5_round_trip() {
}
fn fake_v5_round_trip_for_network(network: Network) {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
let overwinter_activation_height = NetworkUpgrade::Overwinter
.activation_height(network)
@ -500,10 +497,7 @@ fn fake_v5_librustzcash_round_trip() {
}
fn fake_v5_librustzcash_round_trip_for_network(network: Network) {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
let overwinter_activation_height = NetworkUpgrade::Overwinter
.activation_height(network)
@ -943,10 +937,7 @@ fn binding_signatures() {
}
fn binding_signatures_for_network(network: Network) {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
for (height, bytes) in block_iter {
let upgrade = NetworkUpgrade::current(network, Height(*height));

View File

@ -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,
/// and that each post-sapling block has a corresponding final sapling root.
fn get_transparent_output_address_with_blocks_for_network(network: Network) {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
let mut valid_addresses = 0;

View File

@ -273,10 +273,7 @@ fn block_difficulty() -> Result<(), Report> {
fn block_difficulty_for_network(network: Network) -> Result<(), Report> {
let _init_guard = zebra_test::init();
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
let diff_zero = ExpandedDifficulty(U256::zero());
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> {
let _init_guard = zebra_test::init();
let block = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.get(&0),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.get(&0),
};
let block = network.gen_block();
let block = block.expect("test vectors contain the genesis block");
let block = Block::zcash_deserialize(&block[..]).expect("block test vector should deserialize");

View File

@ -189,10 +189,7 @@ fn difficulty_is_valid_for_historical_blocks() -> Result<(), Report> {
}
fn difficulty_is_valid_for_network(network: Network) -> Result<(), Report> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
for (&height, block) in block_iter {
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> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
for (&height, block) in block_iter {
let block = block
@ -401,10 +395,7 @@ fn funding_stream_validation() -> Result<(), Report> {
}
fn funding_stream_validation_for_network(network: Network) -> Result<(), Report> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
let canopy_activation_height = NetworkUpgrade::Canopy
.activation_height(network)
@ -479,10 +470,7 @@ fn miner_fees_validation_success() -> Result<(), Report> {
}
fn miner_fees_validation_for_network(network: Network) -> Result<(), Report> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
for (&height, block) in block_iter {
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> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
for (_height, block) in block_iter {
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> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
for (height, block) in block_iter {
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> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
for (&height, block) in block_iter {
let block = Block::zcash_deserialize(&block[..]).expect("block should deserialize");

View File

@ -233,10 +233,8 @@ async fn continuous_blockchain(
let _init_guard = zebra_test::init();
// A continuous blockchain
let blockchain = match network {
Mainnet => zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS.iter(),
Testnet => zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS.iter(),
};
let blockchain = network.blockchain_iter();
let blockchain: Vec<_> = blockchain
.map(|(height, b)| {
let block = Arc::<Block>::zcash_deserialize(*b).unwrap();

View File

@ -909,11 +909,7 @@ fn v5_transaction_is_accepted_after_nu5_activation_for_network(network: Network)
let nu5_activation_height = nu5
.activation_height(network)
.expect("NU5 activation height is specified");
let blocks = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let blocks = network.block_iter();
let state_service = service_fn(|_| async { unreachable!("Service should not be called") });
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(
network: Network,
) -> Result<(), Report> {
let block_iter = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let block_iter = network.block_iter();
let mut tested_coinbase_txs = 0;
let mut tested_non_coinbase_txs = 0;

View File

@ -81,19 +81,16 @@ async fn test_mocked_getresults_for_network(
.1
.by_height
.len();
match network {
Network::Mainnet => {
assert_eq!(
transaction_heights, 3,
"there should be 3 transaction heights"
);
}
Network::Testnet => {
assert_eq!(
transaction_heights, 1,
"there should be 1 transaction height"
);
}
if network.is_mainnet() {
assert_eq!(
transaction_heights, 3,
"there should be 3 transaction heights"
);
} else {
assert_eq!(
transaction_heights, 1,
"there should be 1 transaction height"
);
}
// create request, fake empty results and get response
@ -150,13 +147,10 @@ async fn test_mocked_clear_results_for_network(
.1
.by_height
.len();
match network {
Network::Mainnet => {
assert_eq!(transaction_heights, 3);
}
Network::Testnet => {
assert_eq!(transaction_heights, 1);
}
if network.is_mainnet() {
assert_eq!(transaction_heights, 3);
} else {
assert_eq!(transaction_heights, 1)
}
// create request, fake results and get response
@ -210,13 +204,10 @@ async fn test_mocked_delete_keys_for_network(
.1
.by_height
.len();
match network {
Network::Mainnet => {
assert_eq!(transaction_heights, 3);
}
Network::Testnet => {
assert_eq!(transaction_heights, 1);
}
if network.is_mainnet() {
assert_eq!(transaction_heights, 3);
} else {
assert_eq!(transaction_heights, 1);
}
let delete_keys_response =
@ -282,9 +273,10 @@ async fn add_fake_populated_results(
tokio::spawn(async move {
let zec_pages_sapling_efvk = ZECPAGES_SAPLING_VIEWING_KEY.to_string();
let mut fake_results = BTreeMap::new();
let heights = match network {
Network::Mainnet => vec![Height::MIN, Height(1), Height::MAX],
Network::Testnet => vec![Height::MIN],
let heights = if network.is_mainnet() {
vec![Height::MIN, Height(1), Height::MAX]
} else {
vec![Height::MIN]
};
for fake_result_height in heights {
fake_results.insert(

View File

@ -44,10 +44,7 @@ async fn test_rpc_response_data() {
async fn test_rpc_response_data_for_network(network: Network) {
// Create a continuous chain of mainnet and testnet blocks from genesis
let block_data = match network {
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
};
let block_data = network.blockchain_map();
let blocks: Vec<Arc<Block>> = block_data
.iter()

View File

@ -413,9 +413,10 @@ pub async fn test_responses<State, ReadState>(
snapshot_rpc_submit_block_invalid(submit_block, &settings);
// `validateaddress`
let founder_address = match network {
Network::Mainnet => "t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR",
Network::Testnet => "t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi",
let founder_address = if network.is_mainnet() {
"t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR"
} else {
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
};
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);
// `z_validateaddress`
let founder_address = match network {
Network::Mainnet => "t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR",
Network::Testnet => "t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi",
let founder_address = if network.is_mainnet() {
"t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR"
} else {
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
};
let z_validate_address = get_block_template_rpc

View File

@ -9,20 +9,9 @@ use zebra_chain::{
serialization::ZcashDeserialize,
};
use 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> {
let (block, sapling_root) = match network {
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, sapling_root) = network.test_block_sapling_roots(1046400, 1116000).unwrap();
let block = Arc::<Block>::zcash_deserialize(block).expect("block should deserialize");
let first_sapling_root = Root::try_from(sapling_root).unwrap();

View File

@ -655,14 +655,11 @@ async fn rpc_getaddresstxids_response() {
let _init_guard = zebra_test::init();
for network in [Mainnet, Testnet] {
let blocks: Vec<Arc<Block>> = match network {
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
}
.iter()
.map(|(_height, block_bytes)| block_bytes.zcash_deserialize_into().unwrap())
.collect();
let blocks: Vec<Arc<Block>> = network
.blockchain_map()
.iter()
.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,
// in one output per coinbase transaction.
//

View File

@ -4,7 +4,7 @@ use std::{collections::BTreeMap, sync::Arc};
use zebra_chain::{
block::{Block, Height},
parameters::Network::{self, *},
parameters::Network::{self},
serialization::ZcashDeserializeInto,
transaction,
};
@ -45,10 +45,7 @@ pub fn add_fake_results(
height: Height,
add_progress_marker: bool,
) {
let blocks = match network {
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
};
let blocks = network.blockchain_map();
let block: Arc<Block> = blocks
.get(&height.0)

View File

@ -89,10 +89,7 @@ fn test_raw_rocksdb_column_families_with_network(network: Network) {
// Snapshot raw database data for:
// - mainnet and testnet
// - genesis, block 1, and block 2
let blocks = match network {
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
};
let blocks = network.blockchain_map();
// We limit the number of blocks, because the serialized data is a few kilobytes per block.
for height in 0..=2 {

View File

@ -181,10 +181,7 @@ fn test_block_and_transaction_data_with_network(network: Network) {
// Snapshot block and transaction database data for:
// - mainnet and testnet
// - genesis, block 1, and block 2
let blocks = match network {
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
};
let blocks = network.blockchain_map();
// We limit the number of blocks, because the serialized data is a few kilobytes per block.
//

View File

@ -141,17 +141,10 @@ fn best_chain_wins() -> 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
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
Network::Mainnet => {
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
}
Network::Testnet => {
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
}
};
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
let block2 = block1.make_fake_child().set_work(10);
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<()> {
let block1: Arc<Block> = match network {
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
Network::Mainnet => {
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
}
Network::Testnet => {
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
}
};
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
let block2 = block1.make_fake_child().set_work(10);
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(
network: Network,
) -> Result<()> {
let block1: Arc<Block> = match network {
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
Network::Mainnet => {
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
}
Network::Testnet => {
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
}
};
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
let block2 = block1.make_fake_child().set_work(10);
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<()> {
let block1: Arc<Block> = match network {
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
Network::Mainnet => {
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
}
Network::Testnet => {
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
}
};
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
let long_chain_block1 = 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<()> {
let block1: Arc<Block> = match network {
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
Network::Mainnet => {
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
}
Network::Testnet => {
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
}
};
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
let long_chain_block1 = 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(())
}
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
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
Network::Mainnet => {
zebra_test::vectors::BLOCK_MAINNET_653599_BYTES.zcash_deserialize_into()?
}
Network::Testnet => {
zebra_test::vectors::BLOCK_TESTNET_583999_BYTES.zcash_deserialize_into()?
}
};
// Since the brand new FinalizedState below will pass a None history tree
// to the NonFinalizedState, we must use pre-Heartwood blocks since
// they won't trigger the history tree update in the NonFinalizedState.
let block1: Arc<Block> = Arc::new(network.test_block(653599, 583999).unwrap());
let less_work_child = block1.make_fake_child().set_work(1);
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_upgrade: NetworkUpgrade,
) -> Result<()> {
let blocks = match network {
Network::Mainnet => &*zebra_test::vectors::MAINNET_BLOCKS,
Network::Testnet => &*zebra_test::vectors::TESTNET_BLOCKS,
};
let blocks = network.block_map();
let height = network_upgrade.activation_height(network).unwrap().0;
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) {
let blocks = match network {
Network::Mainnet => &*zebra_test::vectors::MAINNET_BLOCKS,
Network::Testnet => &*zebra_test::vectors::TESTNET_BLOCKS,
};
let blocks = network.block_map();
let height = network_upgrade.activation_height(network).unwrap().0;
let prev_block = Arc::new(

View File

@ -562,10 +562,7 @@ fn continuous_empty_blocks_from_test_vectors() -> impl Strategy<
any::<Network>()
.prop_flat_map(|network| {
// Select the test vector based on the network
let raw_blocks = match network {
Network::Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS,
Network::Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS,
};
let raw_blocks = network.blockchain_map();
// Transform the test vector's block bytes into a vector of `SemanticallyVerifiedBlock`s.
let blocks: Vec<_> = raw_blocks

View File

@ -73,10 +73,13 @@ async fn check_transcripts(network: Network) -> Result<(), Report> {
let mainnet_transcript = &[&COMMIT_FINALIZED_BLOCK_MAINNET];
let testnet_transcript = &[&COMMIT_FINALIZED_BLOCK_TESTNET];
for transcript_data in match network {
Network::Mainnet => mainnet_transcript,
Network::Testnet => testnet_transcript,
} {
let net_data = if network.is_mainnet() {
mainnet_transcript
} else {
testnet_transcript
};
for transcript_data in net_data {
// We're not verifying UTXOs here.
let (service, _, _, _) = zebra_state::init(Config::ephemeral(), network, Height::MAX, 0);
let transcript = Transcript::from(transcript_data.iter().cloned());

View File

@ -17,10 +17,7 @@ pub fn unmined_transactions_in_blocks(
block_height_range: impl RangeBounds<u32>,
network: Network,
) -> impl DoubleEndedIterator<Item = VerifiedUnminedTx> {
let blocks = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};
let blocks = network.block_iter();
// Deserialize the blocks that are selected based on the specified `block_height_range`.
let selected_blocks = blocks

View File

@ -8,7 +8,6 @@ use zebra_chain::{
amount::Amount,
block::{Block, Height},
parameters::Network,
serialization::ZcashDeserializeInto,
transaction::{UnminedTxId, VerifiedUnminedTx},
};
@ -252,14 +251,7 @@ fn mempool_expired_basic_for_network(network: Network) -> Result<()> {
..Default::default()
});
let block: Block = match network {
Network::Mainnet => {
zebra_test::vectors::BLOCK_MAINNET_982681_BYTES.zcash_deserialize_into()?
}
Network::Testnet => {
zebra_test::vectors::BLOCK_TESTNET_925483_BYTES.zcash_deserialize_into()?
}
};
let block: Block = network.test_block(982681, 925483).unwrap();
// Get a test transaction
let tx = &*(block.transactions[1]).clone();