Skip to content

Commit

Permalink
Updates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Mar 20, 2024
1 parent bf9cbf3 commit 4ed8a71
Show file tree
Hide file tree
Showing 33 changed files with 253 additions and 205 deletions.
4 changes: 2 additions & 2 deletions zebra-chain/src/block/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn block_test_vectors_height_mainnet() {
fn block_test_vectors_height_testnet() {
let _init_guard = zebra_test::init();

block_test_vectors_height(Testnet);
block_test_vectors_height(Network::new_default_testnet());
}

/// Test that the block test vector indexes match the heights in the block data,
Expand Down Expand Up @@ -245,7 +245,7 @@ fn block_commitment_mainnet() {
fn block_commitment_testnet() {
let _init_guard = zebra_test::init();

block_commitment(Testnet);
block_commitment(Network::new_default_testnet());
}

/// Check that the block commitment field parses without errors.
Expand Down
13 changes: 7 additions & 6 deletions zebra-chain/src/history_tree/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use eyre::Result;
/// higher level API.
#[test]
fn push_and_prune() -> Result<()> {
push_and_prune_for_network_upgrade(Network::Mainnet, NetworkUpgrade::Heartwood)?;
push_and_prune_for_network_upgrade(Network::Testnet, NetworkUpgrade::Heartwood)?;
push_and_prune_for_network_upgrade(Network::Mainnet, NetworkUpgrade::Canopy)?;
push_and_prune_for_network_upgrade(Network::Testnet, NetworkUpgrade::Canopy)?;
for network in Network::iter() {
push_and_prune_for_network_upgrade(network.clone(), NetworkUpgrade::Heartwood)?;
push_and_prune_for_network_upgrade(network, NetworkUpgrade::Canopy)?;
}
Ok(())
}

Expand Down Expand Up @@ -109,8 +109,9 @@ fn push_and_prune_for_network_upgrade(
fn upgrade() -> Result<()> {
// The history tree only exists Hearwood-onward, and the only upgrade for which
// we have vectors since then is Canopy. Therefore, only test the Heartwood->Canopy upgrade.
upgrade_for_network_upgrade(Network::Mainnet, NetworkUpgrade::Canopy)?;
upgrade_for_network_upgrade(Network::Testnet, NetworkUpgrade::Canopy)?;
for network in Network::iter() {
upgrade_for_network_upgrade(network, NetworkUpgrade::Canopy)?;
}
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/parameters/network/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ proptest! {
let _init_guard = zebra_test::init();

assert!(Network::Mainnet.is_max_block_time_enforced(height));
assert_eq!(Network::Testnet.is_max_block_time_enforced(height), TESTNET_MAX_TIME_START_HEIGHT <= height);
assert_eq!(Network::new_default_testnet().is_max_block_time_enforced(height), TESTNET_MAX_TIME_START_HEIGHT <= height);
}
}
10 changes: 5 additions & 5 deletions zebra-chain/src/parameters/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn activation_bijective() {
let mainnet_nus: HashSet<&NetworkUpgrade> = mainnet_activations.values().collect();
assert_eq!(MAINNET_ACTIVATION_HEIGHTS.len(), mainnet_nus.len());

let testnet_activations = Testnet.activation_list();
let testnet_activations = Network::new_default_testnet().activation_list();
let testnet_heights: HashSet<&block::Height> = testnet_activations.keys().collect();
assert_eq!(TESTNET_ACTIVATION_HEIGHTS.len(), testnet_heights.len());

Expand All @@ -38,7 +38,7 @@ fn activation_extremes_mainnet() {
#[test]
fn activation_extremes_testnet() {
let _init_guard = zebra_test::init();
activation_extremes(Testnet)
activation_extremes(Network::new_default_testnet())
}

/// Test the activation_list, activation_height, current, and next functions
Expand Down Expand Up @@ -115,7 +115,7 @@ fn activation_consistent_mainnet() {
#[test]
fn activation_consistent_testnet() {
let _init_guard = zebra_test::init();
activation_consistent(Testnet)
activation_consistent(Network::new_default_testnet())
}

/// Check that the `activation_height`, `is_activation_height`,
Expand Down Expand Up @@ -178,7 +178,7 @@ fn branch_id_extremes_mainnet() {
#[test]
fn branch_id_extremes_testnet() {
let _init_guard = zebra_test::init();
branch_id_extremes(Testnet)
branch_id_extremes(Network::new_default_testnet())
}

/// Test the branch_id_list, branch_id, and current functions for `network` with
Expand Down Expand Up @@ -217,7 +217,7 @@ fn branch_id_consistent_mainnet() {
#[test]
fn branch_id_consistent_testnet() {
let _init_guard = zebra_test::init();
branch_id_consistent(Testnet)
branch_id_consistent(Network::new_default_testnet())
}

/// Check that the branch_id and current functions are consistent for `network`.
Expand Down
8 changes: 4 additions & 4 deletions zebra-chain/src/primitives/zcash_history/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use eyre::Result;
/// and its next block.
#[test]
fn tree() -> Result<()> {
tree_for_network_upgrade(&Network::Mainnet, NetworkUpgrade::Heartwood)?;
tree_for_network_upgrade(&Network::Testnet, NetworkUpgrade::Heartwood)?;
tree_for_network_upgrade(&Network::Mainnet, NetworkUpgrade::Canopy)?;
tree_for_network_upgrade(&Network::Testnet, NetworkUpgrade::Canopy)?;
for network in Network::iter() {
tree_for_network_upgrade(&network, NetworkUpgrade::Heartwood)?;
tree_for_network_upgrade(&network, NetworkUpgrade::Canopy)?;
}
Ok(())
}

Expand Down
5 changes: 3 additions & 2 deletions zebra-chain/src/sapling/tests/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ fn incremental_roots() {

#[test]
fn incremental_roots_with_blocks() -> Result<()> {
incremental_roots_with_blocks_for_network(Network::Mainnet)?;
incremental_roots_with_blocks_for_network(Network::Testnet)?;
for network in Network::iter() {
incremental_roots_with_blocks_for_network(network)?;
}
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions zebra-chain/src/sprout/tests/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ fn incremental_roots() {

#[test]
fn incremental_roots_with_blocks() -> Result<()> {
incremental_roots_with_blocks_for_network(Network::Mainnet)?;
incremental_roots_with_blocks_for_network(Network::Testnet)?;

for network in Network::iter() {
incremental_roots_with_blocks_for_network(network)?;
}
Ok(())
}

Expand Down
18 changes: 9 additions & 9 deletions zebra-chain/src/transaction/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ fn empty_v5_librustzcash_round_trip() {
#[test]
fn fake_v5_round_trip() {
let _init_guard = zebra_test::init();

fake_v5_round_trip_for_network(Network::Mainnet);
fake_v5_round_trip_for_network(Network::Testnet);
for network in Network::iter() {
fake_v5_round_trip_for_network(network);
}
}

fn fake_v5_round_trip_for_network(network: Network) {
Expand Down Expand Up @@ -491,9 +491,9 @@ fn invalid_orchard_nullifier() {
#[test]
fn fake_v5_librustzcash_round_trip() {
let _init_guard = zebra_test::init();

fake_v5_librustzcash_round_trip_for_network(Network::Mainnet);
fake_v5_librustzcash_round_trip_for_network(Network::Testnet);
for network in Network::iter() {
fake_v5_librustzcash_round_trip_for_network(network);
}
}

fn fake_v5_librustzcash_round_trip_for_network(network: Network) {
Expand Down Expand Up @@ -931,9 +931,9 @@ fn zip244_sighash() -> Result<()> {
#[test]
fn binding_signatures() {
let _init_guard = zebra_test::init();

binding_signatures_for_network(Network::Mainnet);
binding_signatures_for_network(Network::Testnet);
for network in Network::iter() {
binding_signatures_for_network(network);
}
}

fn binding_signatures_for_network(network: Network) {
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/transparent/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ mod tests {
])
.expect("A PublicKey from slice");

let t_addr = pub_key.to_address(Network::Testnet);
let t_addr = pub_key.to_address(Network::new_default_testnet());

assert_eq!(format!("{t_addr}"), "tmTc6trRhbv96kGfA99i7vrFwb5p7BVFwc3");
}
Expand All @@ -322,7 +322,7 @@ mod tests {

let script = Script::new(&[0; 20]);

let t_addr = script.to_address(Network::Testnet);
let t_addr = script.to_address(Network::new_default_testnet());

assert_eq!(format!("{t_addr}"), "t2L51LcmpA43UMvKTw2Lwtt9LMjwyqU2V1P");
}
Expand Down
16 changes: 9 additions & 7 deletions zebra-chain/src/transparent/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ fn get_transparent_output_address() -> Result<()> {
let addr = transparent_output_address(&transaction.outputs()[0], &Network::Mainnet)
.expect("should return address");
assert_eq!(addr.to_string(), "t3M5FDmPfWNRG3HRLddbicsuSCvKuk9hxzZ");
let addr = transparent_output_address(&transaction.outputs()[0], &Network::Testnet)
.expect("should return address");
let addr =
transparent_output_address(&transaction.outputs()[0], &Network::new_default_testnet())
.expect("should return address");
assert_eq!(addr.to_string(), "t294SGSVoNq2daz15ZNbmAW65KQZ5e3nN5G");
// Public key hash e4ff5512ffafe9287992a1cd177ca6e408e03003
let addr = transparent_output_address(&transaction.outputs()[1], &Network::Mainnet)
.expect("should return address");
assert_eq!(addr.to_string(), "t1ekRwsd4LaSsd6NXgsx66q2HxQWTLCF44y");
let addr = transparent_output_address(&transaction.outputs()[1], &Network::Testnet)
.expect("should return address");
let addr =
transparent_output_address(&transaction.outputs()[1], &Network::new_default_testnet())
.expect("should return address");
assert_eq!(addr.to_string(), "tmWbBGi7TjExNmLZyMcFpxVh3ZPbGrpbX3H");

Ok(())
Expand All @@ -84,9 +86,9 @@ fn get_transparent_output_address() -> Result<()> {
#[test]
fn get_transparent_output_address_with_blocks() {
let _init_guard = zebra_test::init();

get_transparent_output_address_with_blocks_for_network(Network::Mainnet);
get_transparent_output_address_with_blocks_for_network(Network::Testnet);
for network in Network::iter() {
get_transparent_output_address_with_blocks_for_network(network);
}
}

/// Test that the block test vector indexes match the heights in the block data,
Expand Down
19 changes: 12 additions & 7 deletions zebra-chain/src/work/difficulty/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ fn compact_bitcoin_test_vectors() {
/// Test blocks using CompactDifficulty.
#[test]
fn block_difficulty() -> Result<(), Report> {
block_difficulty_for_network(Network::Mainnet)?;
block_difficulty_for_network(Network::Testnet)?;
for network in Network::iter() {
block_difficulty_for_network(network)?;
}

Ok(())
}
Expand Down Expand Up @@ -349,8 +350,9 @@ fn block_difficulty_for_network(network: Network) -> Result<(), Report> {
/// Test that the genesis block threshold is PowLimit
#[test]
fn genesis_block_difficulty() -> Result<(), Report> {
genesis_block_difficulty_for_network(Network::Mainnet)?;
genesis_block_difficulty_for_network(Network::Testnet)?;
for network in Network::iter() {
genesis_block_difficulty_for_network(network)?;
}

Ok(())
}
Expand Down Expand Up @@ -454,7 +456,10 @@ fn check_testnet_minimum_difficulty_block(height: block::Height) -> Result<(), R
// threshold, as documented in ZIP-205 and ZIP-208:
// https://zips.z.cash/zip-0205#change-to-difficulty-adjustment-on-testnet
// https://zips.z.cash/zip-0208#minimum-difficulty-blocks-on-testnet
match NetworkUpgrade::minimum_difficulty_spacing_for_height(&Network::Testnet, height) {
match NetworkUpgrade::minimum_difficulty_spacing_for_height(
&Network::new_default_testnet(),
height,
) {
None => Err(eyre!("the minimum difficulty rule is not active"))?,
Some(spacing) if (time_gap <= spacing) => Err(eyre!(
"minimum difficulty block times must be more than 6 target spacing intervals apart"
Expand All @@ -477,12 +482,12 @@ fn check_testnet_minimum_difficulty_block(height: block::Height) -> Result<(), R

/// SPANDOC: Check that the testnet minimum difficulty is the PoWLimit {?height, ?threshold, ?hash}
{
assert_eq!(threshold, Network::Testnet.target_difficulty_limit(),
assert_eq!(threshold, Network::new_default_testnet().target_difficulty_limit(),
"testnet minimum difficulty thresholds should be equal to the PoWLimit. Hint: Blocks with large gaps are allowed to have the minimum difficulty, but it's not required.");
// all blocks pass the minimum difficulty threshold, even if they aren't minimum
// difficulty blocks, because it's the lowest permitted difficulty
assert!(
hash <= Network::Testnet.target_difficulty_limit(),
hash <= Network::new_default_testnet().target_difficulty_limit(),
"testnet minimum difficulty hashes must be less than the PoWLimit"
);
}
Expand Down
2 changes: 1 addition & 1 deletion zebra-consensus/src/block/subsidy/funding_streams/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn test_funding_stream_addresses() -> Result<(), Report> {
let address =
transparent::Address::from_str(address).expect("address should deserialize");
assert_eq!(
&address.network(),
&address.network().bip70_network_name(),
network,
"incorrect network for {receiver:?} funding stream address constant: {address}",
);
Expand Down
11 changes: 6 additions & 5 deletions zebra-consensus/src/block/subsidy/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ mod test {
#[test]
fn halving_test() -> Result<(), Report> {
let _init_guard = zebra_test::init();

halving_for_network(&Network::Mainnet)?;
halving_for_network(&Network::Testnet)?;
for network in Network::iter() {
halving_for_network(&network)?;
}

Ok(())
}
Expand Down Expand Up @@ -249,8 +249,9 @@ mod test {
fn block_subsidy_test() -> Result<(), Report> {
let _init_guard = zebra_test::init();

block_subsidy_for_network(&Network::Mainnet)?;
block_subsidy_for_network(&Network::Testnet)?;
for network in Network::iter() {
block_subsidy_for_network(&network)?;
}

Ok(())
}
Expand Down
39 changes: 21 additions & 18 deletions zebra-consensus/src/block/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ fn coinbase_is_first_for_historical_blocks() -> Result<(), Report> {
#[test]
fn difficulty_is_valid_for_historical_blocks() -> Result<(), Report> {
let _init_guard = zebra_test::init();

difficulty_is_valid_for_network(Network::Mainnet)?;
difficulty_is_valid_for_network(Network::Testnet)?;
for network in Network::iter() {
difficulty_is_valid_for_network(network)?;
}

Ok(())
}
Expand Down Expand Up @@ -285,9 +285,9 @@ fn equihash_is_valid_for_historical_blocks() -> Result<(), Report> {
#[test]
fn subsidy_is_valid_for_historical_blocks() -> Result<(), Report> {
let _init_guard = zebra_test::init();

subsidy_is_valid_for_network(Network::Mainnet)?;
subsidy_is_valid_for_network(Network::Testnet)?;
for network in Network::iter() {
subsidy_is_valid_for_network(network)?;
}

Ok(())
}
Expand Down Expand Up @@ -388,9 +388,9 @@ fn coinbase_validation_failure() -> Result<(), Report> {
#[test]
fn funding_stream_validation() -> Result<(), Report> {
let _init_guard = zebra_test::init();

funding_stream_validation_for_network(Network::Mainnet)?;
funding_stream_validation_for_network(Network::Testnet)?;
for network in Network::iter() {
funding_stream_validation_for_network(network)?;
}

Ok(())
}
Expand Down Expand Up @@ -463,9 +463,9 @@ fn funding_stream_validation_failure() -> Result<(), Report> {
#[test]
fn miner_fees_validation_success() -> Result<(), Report> {
let _init_guard = zebra_test::init();

miner_fees_validation_for_network(Network::Mainnet)?;
miner_fees_validation_for_network(Network::Testnet)?;
for network in Network::iter() {
miner_fees_validation_for_network(network)?;
}

Ok(())
}
Expand Down Expand Up @@ -546,12 +546,14 @@ fn merkle_root_is_valid() -> Result<(), Report> {
let _init_guard = zebra_test::init();

// test all original blocks available, all blocks validate
merkle_root_is_valid_for_network(Network::Mainnet)?;
merkle_root_is_valid_for_network(Network::Testnet)?;
for network in Network::iter() {
merkle_root_is_valid_for_network(network)?;
}

// create and test fake blocks with v5 transactions, all blocks fail validation
merkle_root_fake_v5_for_network(Network::Mainnet)?;
merkle_root_fake_v5_for_network(Network::Testnet)?;
for network in Network::iter() {
merkle_root_fake_v5_for_network(network)?;
}

Ok(())
}
Expand Down Expand Up @@ -683,8 +685,9 @@ fn legacy_sigops_count_for_historic_blocks() {
fn transaction_expiration_height_validation() -> Result<(), Report> {
let _init_guard = zebra_test::init();

transaction_expiration_height_for_network(&Network::Mainnet)?;
transaction_expiration_height_for_network(&Network::Testnet)?;
for network in Network::iter() {
transaction_expiration_height_for_network(&network)?;
}

Ok(())
}
Expand Down
Loading

0 comments on commit 4ed8a71

Please sign in to comment.