Skip to content

Commit

Permalink
Use prop_assert in proptests
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 9, 2021
1 parent 9118c3c commit c371aa1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions zebra-chain/src/sprout/tests/preallocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ proptest! {
) = max_allocation_is_big_enough(joinsplit);

// Check that our smallest_disallowed_vec is only one item larger than the limit
assert!(((smallest_disallowed_vec_len - 1) as u64) == <JoinSplit<Bctv14Proof>>::max_allocation());
prop_assert!(((smallest_disallowed_vec_len - 1) as u64) == <JoinSplit<Bctv14Proof>>::max_allocation());
// Check that our smallest_disallowed_vec is too big to fit in a valid Zcash Block.
assert!(smallest_disallowed_serialized_len as u64 > MAX_BLOCK_BYTES);
prop_assert!(smallest_disallowed_serialized_len as u64 > MAX_BLOCK_BYTES);

// Check that our largest_allowed_vec contains the maximum number of JoinSplits
assert!((largest_allowed_vec_len as u64) == <JoinSplit<Bctv14Proof>>::max_allocation());
prop_assert!((largest_allowed_vec_len as u64) == <JoinSplit<Bctv14Proof>>::max_allocation());
// Check that our largest_allowed_vec is small enough to fit in a Zcash Block.
assert!(largest_allowed_serialized_len as u64 <= MAX_BLOCK_BYTES);
prop_assert!(largest_allowed_serialized_len as u64 <= MAX_BLOCK_BYTES);
}

/// Verify that...
Expand All @@ -67,13 +67,13 @@ proptest! {
) = max_allocation_is_big_enough(joinsplit);

// Check that our smallest_disallowed_vec is only one item larger than the limit
assert!(((smallest_disallowed_vec_len - 1) as u64) == <JoinSplit<Groth16Proof>>::max_allocation());
prop_assert!(((smallest_disallowed_vec_len - 1) as u64) == <JoinSplit<Groth16Proof>>::max_allocation());
// Check that our smallest_disallowed_vec is too big to fit in a valid Zcash Block.
assert!(smallest_disallowed_serialized_len as u64 > MAX_BLOCK_BYTES);
prop_assert!(smallest_disallowed_serialized_len as u64 > MAX_BLOCK_BYTES);

// Check that our largest_allowed_vec contains the maximum number of JoinSplits
assert!((largest_allowed_vec_len as u64) == <JoinSplit<Groth16Proof>>::max_allocation());
prop_assert!((largest_allowed_vec_len as u64) == <JoinSplit<Groth16Proof>>::max_allocation());
// Check that our largest_allowed_vec is small enough to fit in a Zcash Block.
assert!(largest_allowed_serialized_len as u64 <= MAX_BLOCK_BYTES);
prop_assert!(largest_allowed_serialized_len as u64 <= MAX_BLOCK_BYTES);
}
}
20 changes: 10 additions & 10 deletions zebra-network/src/protocol/external/tests/preallocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ proptest! {
InventoryHash::Wtx(_) => 32 + 32 + 4,
};

assert_eq!(serialized_inv.len(), expected_size);
prop_assert_eq!(serialized_inv.len(), expected_size);
}

/// Verifies that...
Expand All @@ -49,9 +49,9 @@ proptest! {
.zcash_serialize_to_vec()
.expect("Serialization to vec must succeed");
// Check that our smallest_disallowed_vec is only one item larger than the limit
assert!(((smallest_disallowed_vec.len() - 1) as u64) == InventoryHash::max_allocation());
prop_assert!(((smallest_disallowed_vec.len() - 1) as u64) == InventoryHash::max_allocation());
// Check that our smallest_disallowed_vec is too big to fit in a Zcash message.
assert!(smallest_disallowed_serialized.len() > MAX_PROTOCOL_MESSAGE_LEN);
prop_assert!(smallest_disallowed_serialized.len() > MAX_PROTOCOL_MESSAGE_LEN);

// Create largest_allowed_vec by removing one element from smallest_disallowed_vec without copying (for efficiency)
smallest_disallowed_vec.pop();
Expand All @@ -61,9 +61,9 @@ proptest! {
.expect("Serialization to vec must succeed");

// Check that our largest_allowed_vec contains the maximum number of InventoryHashes
assert!((largest_allowed_vec.len() as u64) == InventoryHash::max_allocation());
prop_assert!((largest_allowed_vec.len() as u64) == InventoryHash::max_allocation());
// Check that our largest_allowed_vec is small enough to fit in a Zcash message.
assert!(largest_allowed_serialized.len() <= MAX_PROTOCOL_MESSAGE_LEN);
prop_assert!(largest_allowed_serialized.len() <= MAX_PROTOCOL_MESSAGE_LEN);
}
}

Expand All @@ -83,7 +83,7 @@ proptest! {
let serialized = addr
.zcash_serialize_to_vec()
.expect("Serialization to vec must succeed");
assert!(serialized.len() == ADDR_V1_SIZE)
prop_assert!(serialized.len() == ADDR_V1_SIZE)
}

/// Verifies that...
Expand All @@ -107,13 +107,13 @@ proptest! {
) = max_allocation_is_big_enough(addr);

// Check that our smallest_disallowed_vec is only one item larger than the limit
assert!(((smallest_disallowed_vec_len - 1) as u64) == AddrV1::max_allocation());
prop_assert!(((smallest_disallowed_vec_len - 1) as u64) == AddrV1::max_allocation());
// Check that our smallest_disallowed_vec is too big to send in a valid Zcash message
assert!(smallest_disallowed_serialized_len > MAX_PROTOCOL_MESSAGE_LEN);
prop_assert!(smallest_disallowed_serialized_len > MAX_PROTOCOL_MESSAGE_LEN);

// Check that our largest_allowed_vec contains the maximum number of AddrV1s
assert!((largest_allowed_vec_len as u64) == AddrV1::max_allocation());
prop_assert!((largest_allowed_vec_len as u64) == AddrV1::max_allocation());
// Check that our largest_allowed_vec is small enough to fit in a Zcash message.
assert!(largest_allowed_serialized_len <= MAX_PROTOCOL_MESSAGE_LEN);
prop_assert!(largest_allowed_serialized_len <= MAX_PROTOCOL_MESSAGE_LEN);
}
}

0 comments on commit c371aa1

Please sign in to comment.