Call `zebra_test::init` where needed. (#1227)

* Add missing `zebra_test::init()` to zebra-chain
* Add missing `zebra_test::init()` to zebra-consensus
* Add missing `zebra_test::init()` to zebra-network
* Add missing `zebra_test::init()` to zebra-state
* Add missing `zebra_test::init()` to zebra-test
* Add missing `zebra_test::init()` to zebrad
This commit is contained in:
Alfredo Garcia 2020-11-09 21:29:25 -03:00 committed by GitHub
parent 34f50d7ebb
commit 128643d81e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 210 additions and 0 deletions

View File

@ -403,6 +403,7 @@ mod test {
#[test]
fn test_add_bare() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let neg_one: Amount = (-1).try_into()?;
@ -417,6 +418,7 @@ mod test {
#[test]
fn test_add_opt_lhs() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let one = Ok(one);
let neg_one: Amount = (-1).try_into()?;
@ -432,6 +434,7 @@ mod test {
#[test]
fn test_add_opt_rhs() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let neg_one: Amount = (-1).try_into()?;
let neg_one = Ok(neg_one);
@ -447,6 +450,7 @@ mod test {
#[test]
fn test_add_opt_both() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let one = Ok(one);
let neg_one: Amount = (-1).try_into()?;
@ -463,6 +467,7 @@ mod test {
#[test]
fn test_add_assign() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let neg_one: Amount = (-1).try_into()?;
let mut neg_one = Ok(neg_one);
@ -479,6 +484,7 @@ mod test {
#[test]
fn test_sub_bare() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let zero: Amount = 0.try_into()?;
@ -493,6 +499,7 @@ mod test {
#[test]
fn test_sub_opt_lhs() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let one = Ok(one);
let zero: Amount = 0.try_into()?;
@ -508,6 +515,7 @@ mod test {
#[test]
fn test_sub_opt_rhs() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let zero: Amount = 0.try_into()?;
let zero = Ok(zero);
@ -523,6 +531,7 @@ mod test {
#[test]
fn test_sub_assign() -> Result<()> {
zebra_test::init();
let one: Amount = 1.try_into()?;
let zero: Amount = 0.try_into()?;
let mut zero = Ok(zero);
@ -538,6 +547,8 @@ mod test {
#[test]
fn add_with_diff_constraints() -> Result<()> {
zebra_test::init();
let one = Amount::<NonNegative>::try_from(1)?;
let zero = Amount::<NegativeAllowed>::try_from(0)?;
@ -549,6 +560,8 @@ mod test {
#[test]
fn deserialize_checks_bounds() -> Result<()> {
zebra_test::init();
let big = MAX_MONEY * 2;
let neg = -10;
@ -572,6 +585,8 @@ mod test {
#[test]
fn hash() -> Result<()> {
zebra_test::init();
let one = Amount::<NonNegative>::try_from(1)?;
let another_one = Amount::<NonNegative>::try_from(1)?;
let zero = Amount::<NonNegative>::try_from(0)?;
@ -601,6 +616,8 @@ mod test {
#[test]
fn ordering_constraints() -> Result<()> {
zebra_test::init();
ordering::<NonNegative, NonNegative>()?;
ordering::<NonNegative, NegativeAllowed>()?;
ordering::<NegativeAllowed, NonNegative>()?;

View File

@ -132,6 +132,8 @@ impl Arbitrary for Height {
#[test]
fn operator_tests() {
zebra_test::init();
assert_eq!(Some(Height(2)), Height(1) + Height(1));
assert_eq!(None, Height::MAX + Height(1));
// Bad heights aren't caught at compile-time or runtime, until we add or subtract

View File

@ -12,6 +12,8 @@ use super::super::{serialize::MAX_BLOCK_BYTES, *};
proptest! {
#[test]
fn block_hash_roundtrip(hash in any::<Hash>()) {
zebra_test::init();
let bytes = hash.zcash_serialize_to_vec()?;
let other_hash: Hash = bytes.zcash_deserialize_into()?;
@ -20,6 +22,8 @@ proptest! {
#[test]
fn block_hash_display_fromstr_roundtrip(hash in any::<Hash>()) {
zebra_test::init();
let display = format!("{}", hash);
let parsed = display.parse::<Hash>().expect("hash should parse");
prop_assert_eq!(hash, parsed);
@ -27,6 +31,8 @@ proptest! {
#[test]
fn blockheader_roundtrip(header in any::<Header>()) {
zebra_test::init();
let bytes = header.zcash_serialize_to_vec()?;
let other_header = bytes.zcash_deserialize_into()?;
@ -39,6 +45,8 @@ proptest! {
network in any::<Network>(),
block_height in any::<Height>()
) {
zebra_test::init();
let root_hash = RootHash::from_bytes(bytes, network, block_height);
let other_bytes = root_hash.to_bytes();
@ -56,6 +64,8 @@ proptest! {
#[test]
fn block_roundtrip(block in any::<Block>(), network in any::<Network>()) {
zebra_test::init();
let bytes = block.zcash_serialize_to_vec()?;
let bytes = &mut bytes.as_slice();

View File

@ -11,6 +11,8 @@ use super::generate; // XXX this should be rewritten as strategies
#[test]
fn blockheaderhash_debug() {
zebra_test::init();
let preimage = b"foo bar baz";
let mut sha_writer = sha256d::Writer::default();
let _ = sha_writer.write_all(preimage);
@ -25,6 +27,8 @@ fn blockheaderhash_debug() {
#[test]
fn blockheaderhash_from_blockheader() {
zebra_test::init();
let blockheader = generate::block_header();
let hash = Hash::from(&blockheader);
@ -69,6 +73,8 @@ fn deserialize_blockheader() {
#[test]
fn deserialize_block() {
zebra_test::init();
// this one has a bad version field
zebra_test::vectors::BLOCK_MAINNET_434873_BYTES
.zcash_deserialize_into::<Block>()
@ -83,6 +89,8 @@ fn deserialize_block() {
#[test]
fn block_test_vectors_unique() {
zebra_test::init();
let block_count = zebra_test::vectors::BLOCKS.len();
let block_hashes: HashSet<_> = zebra_test::vectors::BLOCKS
.iter()
@ -103,11 +111,15 @@ fn block_test_vectors_unique() {
#[test]
fn block_test_vectors_height_mainnet() {
zebra_test::init();
block_test_vectors_height(Network::Mainnet);
}
#[test]
fn block_test_vectors_height_testnet() {
zebra_test::init();
block_test_vectors_height(Network::Testnet);
}
@ -131,6 +143,8 @@ fn block_test_vectors_height(network: Network) {
#[test]
fn block_limits_multi_tx() {
zebra_test::init();
// Test multiple small transactions to fill a block max size
// Create a block just below the limit
@ -166,6 +180,8 @@ fn block_limits_multi_tx() {
#[test]
fn block_limits_single_tx() {
zebra_test::init();
// Test block limit with a big single transaction
// Create a block just below the limit
@ -213,6 +229,8 @@ fn node_time_check(
#[test]
fn time_check_now() {
zebra_test::init();
// These checks are deteministic, because all the times are offset
// from the current time.
let now = Utc::now();
@ -273,6 +291,8 @@ static BLOCK_HEADER_INVALID_TIMESTAMPS: &[i64] = &[
#[test]
fn time_check_fixed() {
zebra_test::init();
// These checks are non-deterministic, but the times are all in the
// distant past or far future. So it's unlikely that the test
// machine will have a clock that makes these tests fail.

View File

@ -12,6 +12,8 @@ use NetworkUpgrade::*;
/// Check that the activation heights and network upgrades are unique.
#[test]
fn activation_bijective() {
zebra_test::init();
let mainnet_activations = NetworkUpgrade::activation_list(Mainnet);
let mainnet_heights: HashSet<&block::Height> = mainnet_activations.keys().collect();
assert_eq!(MAINNET_ACTIVATION_HEIGHTS.len(), mainnet_heights.len());
@ -29,11 +31,13 @@ fn activation_bijective() {
#[test]
fn activation_extremes_mainnet() {
zebra_test::init();
activation_extremes(Mainnet)
}
#[test]
fn activation_extremes_testnet() {
zebra_test::init();
activation_extremes(Testnet)
}
@ -84,11 +88,13 @@ fn activation_extremes(network: Network) {
#[test]
fn activation_consistent_mainnet() {
zebra_test::init();
activation_consistent(Mainnet)
}
#[test]
fn activation_consistent_testnet() {
zebra_test::init();
activation_consistent(Testnet)
}
@ -119,6 +125,8 @@ fn activation_consistent(network: Network) {
/// Check that the network upgrades and branch ids are unique.
#[test]
fn branch_id_bijective() {
zebra_test::init();
let branch_id_list = NetworkUpgrade::branch_id_list();
let nus: HashSet<&NetworkUpgrade> = branch_id_list.keys().collect();
assert_eq!(CONSENSUS_BRANCH_IDS.len(), nus.len());
@ -129,11 +137,13 @@ fn branch_id_bijective() {
#[test]
fn branch_id_extremes_mainnet() {
zebra_test::init();
branch_id_extremes(Mainnet)
}
#[test]
fn branch_id_extremes_testnet() {
zebra_test::init();
branch_id_extremes(Testnet)
}
@ -165,11 +175,13 @@ fn branch_id_extremes(network: Network) {
#[test]
fn branch_id_consistent_mainnet() {
zebra_test::init();
branch_id_consistent(Mainnet)
}
#[test]
fn branch_id_consistent_testnet() {
zebra_test::init();
branch_id_consistent(Testnet)
}

View File

@ -119,6 +119,8 @@ mod tests {
#[test]
fn from_str_display() {
zebra_test::init();
let zs_addr: Address =
"zs1qqqqqqqqqqqqqqqqqrjq05nyfku05msvu49mawhg6kr0wwljahypwyk2h88z6975u563j8nfaxd"
.parse()
@ -132,6 +134,8 @@ mod tests {
#[test]
fn derive_keys_and_addresses() {
zebra_test::init();
let spending_key = keys::SpendingKey::new(&mut OsRng);
let spend_authorizing_key = keys::SpendAuthorizingKey::from(spending_key);
@ -158,6 +162,7 @@ proptest! {
#[test]
fn sapling_address_roundtrip(zaddr in any::<Address>()) {
zebra_test::init();
let string = zaddr.to_string();

View File

@ -288,6 +288,8 @@ mod tests {
#[test]
fn pedersen_hash_to_point_test_vectors() {
zebra_test::init();
const D: [u8; 8] = *b"Zcash_PH";
for test_vector in test_vectors::TEST_VECTORS.iter() {
@ -302,6 +304,8 @@ mod tests {
#[test]
fn add() {
zebra_test::init();
let identity = ValueCommitment(jubjub::AffinePoint::identity());
let g = ValueCommitment(jubjub::AffinePoint::from_raw_unchecked(
@ -324,6 +328,8 @@ mod tests {
#[test]
fn add_assign() {
zebra_test::init();
let mut identity = ValueCommitment(jubjub::AffinePoint::identity());
let g = ValueCommitment(jubjub::AffinePoint::from_raw_unchecked(
@ -349,6 +355,8 @@ mod tests {
#[test]
fn sub() {
zebra_test::init();
let g_point = jubjub::AffinePoint::from_raw_unchecked(
jubjub::Fq::from_raw([
0xe4b3_d35d_f1a7_adfe,
@ -373,6 +381,8 @@ mod tests {
#[test]
fn sub_assign() {
zebra_test::init();
let g_point = jubjub::AffinePoint::from_raw_unchecked(
jubjub::Fq::from_raw([
0xe4b3_d35d_f1a7_adfe,
@ -400,6 +410,8 @@ mod tests {
#[test]
fn sum() {
zebra_test::init();
let g_point = jubjub::AffinePoint::from_raw_unchecked(
jubjub::Fq::from_raw([
0xe4b3_d35d_f1a7_adfe,

View File

@ -37,6 +37,8 @@ mod tests {
#[test]
fn derive_for_each_test_vector() {
zebra_test::init();
for test_vector in test_vectors::TEST_VECTORS.iter() {
let spending_key = SpendingKey::from(test_vector.sk);
@ -76,6 +78,8 @@ proptest! {
#[test]
fn string_roundtrips(spending_key in any::<SpendingKey>()) {
zebra_test::init();
let sk_string = spending_key.to_string();
let spending_key_2: SpendingKey = sk_string.parse().unwrap();
prop_assert_eq![spending_key, spending_key_2];

View File

@ -107,6 +107,7 @@ proptest! {
#[test]
fn encrypted_ciphertext_roundtrip(ec in any::<EncryptedNote>()) {
zebra_test::init();
let mut data = Vec::new();
@ -119,6 +120,7 @@ proptest! {
#[test]
fn out_ciphertext_roundtrip(oc in any::<WrappedNoteKey>()) {
zebra_test::init();
let mut data = Vec::new();

View File

@ -161,6 +161,8 @@ mod tests {
#[test]
fn empty_roots() {
zebra_test::init();
// From https://github.com/zcash/librustzcash/blob/master/zcash_primitives/src/merkle_tree.rs#L512
const HEX_EMPTY_ROOTS: [&str; 33] = [
"0100000000000000000000000000000000000000000000000000000000000000",
@ -205,6 +207,7 @@ mod tests {
#[test]
fn incremental_roots() {
zebra_test::init();
// From https://github.com/zcash/zcash/blob/master/src/test/data/merkle_commitments_sapling.json
// Byte-reversed from those ones because the original test vectors are loaded using uint256S()
let commitments = [

View File

@ -11,6 +11,8 @@ proptest! {
#[test]
fn compactsize_write_then_read_round_trip(s in 0u64..0x2_0000u64) {
zebra_test::init();
// Maximum encoding size of a compactsize is 9 bytes.
let mut buf = [0u8; 8+1];
Cursor::new(&mut buf[..]).write_compactsize(s).unwrap();
@ -20,6 +22,8 @@ proptest! {
#[test]
fn compactsize_read_then_write_round_trip(bytes in prop::array::uniform9(0u8..)) {
zebra_test::init();
// Only do the test if the bytes were valid.
if let Ok(s) = Cursor::new(&bytes[..]).read_compactsize() {
// The compactsize encoding is variable-length, so we may not even

View File

@ -60,6 +60,8 @@ mod tests {
#[test]
fn sha256d_checksum() {
zebra_test::init();
// https://en.bitcoin.it/wiki/Protocol_documentation#Hashes
let input = b"hello";
let checksum = Checksum::from(&input[..]);
@ -69,6 +71,8 @@ mod tests {
#[test]
fn sha256d_checksum_debug() {
zebra_test::init();
let input = b"hello";
let checksum = Checksum::from(&input[..]);

View File

@ -138,6 +138,8 @@ mod tests {
#[test]
fn from_string_debug() {
zebra_test::init();
let string = "zcU1Cd6zYyZCd2VJF8yKgmzjxdiiU1rgTTjEwoN1CGUWCziPkUTXUjXmX7TMqdMNsTfuiGN1jQoVN4kGxUR4sAPN4XZ7pxb";
let zc_addr = string.parse::<SproutShieldedAddress>().unwrap();
@ -150,6 +152,7 @@ proptest! {
#[test]
fn zcash_de_serialize_roundtrip(zaddr in any::<SproutShieldedAddress>()) {
zebra_test::init();
let mut data = Vec::new();
@ -163,6 +166,7 @@ proptest! {
#[test]
fn zcash_base58check_roundtrip(zaddr in any::<SproutShieldedAddress>()) {
zebra_test::init();
let string = zaddr.to_string();

View File

@ -344,6 +344,8 @@ mod tests {
#[test]
// TODO: test vectors, not just random data
fn derive_keys() {
zebra_test::init();
let spending_key = SpendingKey::new(&mut OsRng);
let receiving_key = ReceivingKey::from(spending_key);
@ -357,6 +359,7 @@ proptest! {
#[test]
fn spending_key_roundtrip(sk in any::<SpendingKey>()) {
zebra_test::init();
let mut data = Vec::new();
@ -370,6 +373,7 @@ proptest! {
#[test]
fn spending_key_string_roundtrip(sk in any::<SpendingKey>()) {
zebra_test::init();
let string = sk.to_string();
@ -381,6 +385,7 @@ proptest! {
#[test]
fn incoming_viewing_key_roundtrip(ivk in any::<IncomingViewingKey>()) {
zebra_test::init();
let mut data = Vec::new();
@ -394,6 +399,7 @@ proptest! {
#[test]
fn incoming_viewing_key_string_roundtrip(ivk in any::<IncomingViewingKey>()) {
zebra_test::init();
let string = ivk.to_string();

View File

@ -60,6 +60,7 @@ proptest! {
#[test]
fn encrypted_ciphertext_roundtrip(ec in any::<EncryptedNote>()) {
zebra_test::init();
let mut data = Vec::new();

View File

@ -176,6 +176,8 @@ mod tests {
#[test]
fn empty_roots() {
zebra_test::init();
// From https://github.com/zcash/zcash/blob/master/src/zcash/IncrementalMerkleTree.cpp#L439
let hex_empty_roots = [
"0000000000000000000000000000000000000000000000000000000000000000",
@ -217,6 +219,8 @@ mod tests {
#[test]
fn incremental_roots() {
zebra_test::init();
// From https://github.com/zcash/zcash/blob/master/src/test/data/merkle_commitments.json
//
// Byte-reversed from those ones because the original test vectors are

View File

@ -65,6 +65,8 @@ mod tests {
#[test]
fn transactionhash_from_str() {
zebra_test::init();
let hash: Hash = "3166411bd5343e0b284a108f39a929fbbb62619784f8c6dafe520703b5b446bf"
.parse()
.unwrap();

View File

@ -50,6 +50,8 @@ impl fmt::Debug for Memo {
#[test]
fn memo_fmt() {
zebra_test::init();
let memo = Memo(Box::new(
*b"thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis \
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis \
@ -74,6 +76,8 @@ fn memo_fmt() {
#[test]
fn memo_from_string() {
zebra_test::init();
let memo = Memo::try_from("foo bar baz".as_ref()).unwrap();
let mut bytes = [0; 512];

View File

@ -8,6 +8,8 @@ use crate::serialization::{ZcashDeserialize, ZcashDeserializeInto, ZcashSerializ
proptest! {
#[test]
fn transaction_roundtrip(tx in any::<Transaction>()) {
zebra_test::init();
let data = tx.zcash_serialize_to_vec().expect("tx should serialize");
let tx2 = data.zcash_deserialize_into().expect("randomized tx should deserialize");
@ -16,6 +18,8 @@ proptest! {
#[test]
fn transaction_hash_display_fromstr_roundtrip(hash in any::<Hash>()) {
zebra_test::init();
let display = format!("{}", hash);
let parsed = display.parse::<Hash>().expect("hash should parse");
prop_assert_eq!(hash, parsed);
@ -23,6 +27,8 @@ proptest! {
#[test]
fn locktime_roundtrip(locktime in any::<LockTime>()) {
zebra_test::init();
let mut bytes = Cursor::new(Vec::new());
locktime.zcash_serialize(&mut bytes)?;

View File

@ -4,6 +4,8 @@ use crate::serialization::{ZcashDeserialize, ZcashSerialize};
#[test]
fn librustzcash_tx_deserialize_and_round_trip() {
zebra_test::init();
let tx = Transaction::zcash_deserialize(&zebra_test::vectors::GENERIC_TESTNET_TX[..])
.expect("transaction test vector from librustzcash should deserialize");
@ -15,6 +17,8 @@ fn librustzcash_tx_deserialize_and_round_trip() {
#[test]
fn librustzcash_tx_hash() {
zebra_test::init();
let tx = Transaction::zcash_deserialize(&zebra_test::vectors::GENERIC_TESTNET_TX[..])
.expect("transaction test vector from librustzcash should deserialize");
@ -29,6 +33,8 @@ fn librustzcash_tx_hash() {
#[test]
fn zip143_deserialize_and_round_trip() {
zebra_test::init();
let tx1 = Transaction::zcash_deserialize(&zebra_test::vectors::ZIP143_1[..])
.expect("transaction test vector from ZIP143 should deserialize");
@ -50,6 +56,8 @@ fn zip143_deserialize_and_round_trip() {
#[test]
fn zip243_deserialize_and_round_trip() {
zebra_test::init();
let tx1 = Transaction::zcash_deserialize(&zebra_test::vectors::ZIP243_1[..])
.expect("transaction test vector from ZIP243 should deserialize");

View File

@ -257,6 +257,8 @@ mod tests {
#[test]
fn pubkey_mainnet() {
zebra_test::init();
let pub_key = PublicKey::from_slice(&[
3, 23, 183, 225, 206, 31, 159, 148, 195, 42, 67, 115, 146, 41, 248, 140, 11, 3, 51, 41,
111, 180, 110, 143, 114, 134, 88, 73, 198, 174, 52, 184, 78,
@ -270,6 +272,8 @@ mod tests {
#[test]
fn pubkey_testnet() {
zebra_test::init();
let pub_key = PublicKey::from_slice(&[
3, 23, 183, 225, 206, 31, 159, 148, 195, 42, 67, 115, 146, 41, 248, 140, 11, 3, 51, 41,
111, 180, 110, 143, 114, 134, 88, 73, 198, 174, 52, 184, 78,
@ -283,6 +287,8 @@ mod tests {
#[test]
fn empty_script_mainnet() {
zebra_test::init();
let script = Script(vec![0; 20]);
let t_addr = script.to_address(Network::Mainnet);
@ -292,6 +298,8 @@ mod tests {
#[test]
fn empty_script_testnet() {
zebra_test::init();
let script = Script(vec![0; 20]);
let t_addr = script.to_address(Network::Testnet);
@ -301,6 +309,8 @@ mod tests {
#[test]
fn from_string() {
zebra_test::init();
let t_addr: Address = "t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd".parse().unwrap();
assert_eq!(format!("{}", t_addr), "t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd");
@ -308,6 +318,8 @@ mod tests {
#[test]
fn debug() {
zebra_test::init();
let t_addr: Address = "t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd".parse().unwrap();
assert_eq!(
@ -322,6 +334,7 @@ proptest! {
#[test]
fn transparent_address_roundtrip(taddr in any::<Address>()) {
zebra_test::init();
let mut data = Vec::new();

View File

@ -53,6 +53,8 @@ mod proptests {
proptest! {
#[test]
fn script_roundtrip(script in any::<Script>()) {
zebra_test::init();
let mut bytes = Cursor::new(Vec::new());
script.zcash_serialize(&mut bytes)?;

View File

@ -9,6 +9,8 @@ use super::super::*;
#[test]
fn equihash_solution_roundtrip() {
zebra_test::init();
proptest!(|(solution in any::<equihash::Solution>())| {
let data = solution
.zcash_serialize_to_vec()

View File

@ -33,6 +33,8 @@ mod test {
use zebra_chain::parameters::NetworkUpgrade::*;
#[test]
fn test_founders_reward() -> Result<(), Report> {
zebra_test::init();
let network = Network::Mainnet;
let blossom_height = Blossom.activation_height(network).unwrap();
let canopy_height = Canopy.activation_height(network).unwrap();

View File

@ -109,6 +109,8 @@ mod test {
#[test]
fn halving_test() -> Result<(), Report> {
zebra_test::init();
halving_for_network(Network::Mainnet)?;
halving_for_network(Network::Testnet)?;
@ -194,6 +196,8 @@ mod test {
#[test]
fn block_subsidy_test() -> Result<(), Report> {
zebra_test::init();
block_subsidy_for_network(Network::Mainnet)?;
block_subsidy_for_network(Network::Testnet)?;
@ -283,6 +287,8 @@ mod test {
#[test]
fn miner_subsidy_test() -> Result<(), Report> {
zebra_test::init();
miner_subsidy_for_network(Network::Mainnet)?;
miner_subsidy_for_network(Network::Testnet)?;

View File

@ -135,6 +135,8 @@ async fn check_transcripts() -> Result<(), Report> {
#[test]
fn coinbase_is_first_for_historical_blocks() -> Result<(), Report> {
zebra_test::init();
let block_iter = zebra_test::vectors::BLOCKS.iter();
for block in block_iter {
@ -151,6 +153,8 @@ fn coinbase_is_first_for_historical_blocks() -> Result<(), Report> {
#[test]
fn difficulty_is_valid_for_historical_blocks() -> Result<(), Report> {
zebra_test::init();
difficulty_is_valid_for_network(Network::Mainnet)?;
difficulty_is_valid_for_network(Network::Testnet)?;
@ -177,6 +181,7 @@ fn difficulty_is_valid_for_network(network: Network) -> Result<(), Report> {
#[test]
fn difficulty_validation_failure() -> Result<(), Report> {
zebra_test::init();
use crate::error::*;
// Get a block in the mainnet, and mangle its difficulty field
@ -237,6 +242,8 @@ fn difficulty_validation_failure() -> Result<(), Report> {
#[test]
fn equihash_is_valid_for_historical_blocks() -> Result<(), Report> {
zebra_test::init();
let block_iter = zebra_test::vectors::BLOCKS.iter();
for block in block_iter {
@ -253,6 +260,8 @@ fn equihash_is_valid_for_historical_blocks() -> Result<(), Report> {
#[test]
fn subsidy_is_valid_for_historical_blocks() -> Result<(), Report> {
zebra_test::init();
subsidy_is_valid_for_network(Network::Mainnet)?;
subsidy_is_valid_for_network(Network::Testnet)?;
@ -283,6 +292,7 @@ fn subsidy_is_valid_for_network(network: Network) -> Result<(), Report> {
#[test]
fn coinbase_validation_failure() -> Result<(), Report> {
zebra_test::init();
use crate::error::*;
let network = Network::Mainnet;
@ -355,6 +365,7 @@ fn coinbase_validation_failure() -> Result<(), Report> {
#[test]
fn founders_reward_validation_failure() -> Result<(), Report> {
zebra_test::init();
use crate::error::*;
use zebra_chain::transaction::Transaction;
@ -398,6 +409,8 @@ fn founders_reward_validation_failure() -> Result<(), Report> {
#[test]
fn time_is_valid_for_historical_blocks() -> Result<(), Report> {
zebra_test::init();
let block_iter = zebra_test::vectors::BLOCKS.iter();
let now = Utc::now();

View File

@ -19,6 +19,7 @@ fn minimum_difficulty_testnet() {
/// Test MinimumDifficulty
fn minimum_difficulty(network: Network) {
zebra_test::init();
use block::Height;
use MinimumDifficulty::*;

View File

@ -113,6 +113,8 @@ mod tests {
/// relies on.
#[test]
fn ensure_live_peer_duration_value_matches_others() {
zebra_test::init();
let constructed_live_peer_duration =
HEARTBEAT_INTERVAL + REQUEST_TIMEOUT + REQUEST_TIMEOUT + REQUEST_TIMEOUT;
@ -122,6 +124,8 @@ mod tests {
/// Make sure that the timeout values are consistent with each other.
#[test]
fn ensure_timeouts_consistent() {
zebra_test::init();
assert!(HANDSHAKE_TIMEOUT <= REQUEST_TIMEOUT,
"Handshakes are requests, so the handshake timeout can't be longer than the timeout for all requests.");
// This check is particularly important on testnet, which has a small

View File

@ -92,6 +92,8 @@ mod tests {
// XXX remove this test and replace it with a proptest instance.
#[test]
fn sanitize_truncates_timestamps() {
zebra_test::init();
let entry = MetaAddr {
services: PeerServices::default(),
addr: "127.0.0.1:8233".parse().unwrap(),

View File

@ -582,6 +582,7 @@ mod tests {
#[test]
fn version_message_round_trip() {
zebra_test::init();
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let services = PeerServices::NODE_NETWORK;
let timestamp = Utc.timestamp(1_568_000_000, 0);
@ -631,6 +632,8 @@ mod tests {
#[test]
fn filterload_message_round_trip() {
zebra_test::init();
let mut rt = Runtime::new().unwrap();
let v = Message::FilterLoad {
@ -665,6 +668,8 @@ mod tests {
#[test]
fn filterload_message_too_large_round_trip() {
zebra_test::init();
let mut rt = Runtime::new().unwrap();
let v = Message::FilterLoad {

View File

@ -122,6 +122,8 @@ mod proptest {
#[test]
fn magic_debug() {
zebra_test::init();
assert_eq!(format!("{:?}", magics::MAINNET), "Magic(\"24e92764\")");
assert_eq!(format!("{:?}", magics::TESTNET), "Magic(\"fa1af9bf\")");
}
@ -130,6 +132,8 @@ mod proptest {
#[test]
fn proptest_magic_from_array(data in any::<[u8; 4]>()) {
zebra_test::init();
assert_eq!(format!("{:?}", Magic(data)), format!("Magic({:x?})", hex::encode(data)));
}
}
@ -152,6 +156,8 @@ mod test {
/// Test the min_for_upgrade and current_min functions for `network` with
/// extreme values.
fn version_extremes(network: Network) {
zebra_test::init();
assert_eq!(
Version::current_min(network, block::Height(0)),
Version::min_for_upgrade(network, BeforeOverwinter),
@ -178,6 +184,8 @@ mod test {
/// Check that the min_for_upgrade and current_min functions
/// are consistent for `network`.
fn version_consistent(network: Network) {
zebra_test::init();
let highest_network_upgrade = NetworkUpgrade::current(network, block::Height::MAX);
assert!(highest_network_upgrade == Canopy || highest_network_upgrade == Heartwood,
"expected coverage of all network upgrades: add the new network upgrade to the list in this test");

View File

@ -18,6 +18,8 @@ static BLOCK_LOCATOR_CASES: &[(u32, u32)] = &[
/// Check that the block locator heights are sensible.
#[test]
fn test_block_locator_heights() {
zebra_test::init();
for (height, min_height) in BLOCK_LOCATOR_CASES.iter().cloned() {
let locator = util::block_locator_heights(block::Height(height));

View File

@ -404,8 +404,12 @@ mod test {
use std::collections::HashSet;
use crate::init;
#[test]
fn block_test_vectors_unique() {
init();
let block_count = BLOCKS.len();
let block_set: HashSet<_> = BLOCKS.iter().collect();
@ -422,6 +426,8 @@ mod test {
/// We're using lazy_static! and combinators, so it would be easy to make this mistake.
#[test]
fn block_test_vectors_count() {
init();
assert!(
BLOCKS.len() > 50,
"there should be a reasonable number of block test vectors"

View File

@ -588,6 +588,8 @@ mod test {
/// Make sure the timeout values are consistent with each other.
#[test]
fn ensure_timeouts_consistent() {
zebra_test::init();
let max_download_retry_time =
BLOCK_DOWNLOAD_TIMEOUT.as_secs() * (BLOCK_DOWNLOAD_RETRY_LIMIT as u64);
assert!(

View File

@ -134,6 +134,7 @@ where
#[test]
fn generate_no_args() -> Result<()> {
zebra_test::init();
let child = testdir()?
.with_config(default_test_config()?)?
.spawn_child(&["generate"])?;
@ -165,6 +166,7 @@ macro_rules! assert_with_context {
#[test]
fn generate_args() -> Result<()> {
zebra_test::init();
let testdir = testdir()?;
let testdir = &testdir;
@ -205,6 +207,7 @@ fn generate_args() -> Result<()> {
#[test]
fn help_no_args() -> Result<()> {
zebra_test::init();
let testdir = testdir()?.with_config(default_test_config()?)?;
let child = testdir.spawn_child(&["help"])?;
@ -223,6 +226,7 @@ fn help_no_args() -> Result<()> {
#[test]
fn help_args() -> Result<()> {
zebra_test::init();
let testdir = testdir()?;
let testdir = &testdir;
@ -242,6 +246,7 @@ fn help_args() -> Result<()> {
#[test]
fn start_no_args() -> Result<()> {
zebra_test::init();
// start caches state, so run one of the start tests with persistent state
let testdir = testdir()?.with_config(persistent_test_config()?)?;
@ -265,6 +270,7 @@ fn start_no_args() -> Result<()> {
#[test]
fn start_args() -> Result<()> {
zebra_test::init();
let testdir = testdir()?.with_config(default_test_config()?)?;
let testdir = &testdir;
@ -291,6 +297,7 @@ fn start_args() -> Result<()> {
#[test]
fn persistent_mode() -> Result<()> {
zebra_test::init();
let testdir = testdir()?.with_config(persistent_test_config()?)?;
let testdir = &testdir;
@ -314,6 +321,7 @@ fn persistent_mode() -> Result<()> {
#[test]
fn ephemeral_mode() -> Result<()> {
zebra_test::init();
let testdir = testdir()?.with_config(default_test_config()?)?;
let testdir = &testdir;
@ -378,6 +386,7 @@ fn misconfigured_ephemeral_mode() -> Result<()> {
#[test]
fn app_no_args() -> Result<()> {
zebra_test::init();
let testdir = testdir()?.with_config(default_test_config()?)?;
let child = testdir.spawn_child(&[])?;
@ -392,6 +401,7 @@ fn app_no_args() -> Result<()> {
#[test]
fn version_no_args() -> Result<()> {
zebra_test::init();
let testdir = testdir()?.with_config(default_test_config()?)?;
let child = testdir.spawn_child(&["version"])?;
@ -406,6 +416,7 @@ fn version_no_args() -> Result<()> {
#[test]
fn version_args() -> Result<()> {
zebra_test::init();
let testdir = testdir()?.with_config(default_test_config()?)?;
let testdir = &testdir;
@ -434,6 +445,7 @@ fn valid_generated_config_test() -> Result<()> {
fn valid_generated_config(command: &str, expected_output: &str) -> Result<()> {
zebra_test::init();
let testdir = testdir()?;
let testdir = &testdir;