Cleanup a few arbitrary impls (#2222)

This commit is contained in:
teor 2021-05-28 22:49:28 +10:00 committed by GitHub
parent 0b611eb770
commit 4c276dae64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 18 deletions

View File

@ -313,7 +313,7 @@ pub enum Error {
/// );
/// ```
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct NegativeAllowed {}
pub struct NegativeAllowed;
impl Constraint for NegativeAllowed {
fn valid_range() -> RangeInclusive<i64> {
@ -331,7 +331,7 @@ impl Constraint for NegativeAllowed {
/// );
/// ```
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct NonNegative {}
pub struct NonNegative;
impl Constraint for NonNegative {
fn valid_range() -> RangeInclusive<i64> {

View File

@ -17,6 +17,9 @@ mod network;
mod network_upgrade;
mod transaction;
#[cfg(any(test, feature = "proptest-impl"))]
pub mod arbitrary;
pub use genesis::*;
pub use network::Network;
pub use network_upgrade::*;

View File

@ -0,0 +1,21 @@
//! Arbitrary implementations for network parameters
use proptest::prelude::*;
use super::NetworkUpgrade;
impl NetworkUpgrade {
/// Generates network upgrades with [`BranchId`]s
pub fn branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
prop_oneof![
Just(NetworkUpgrade::Overwinter),
Just(NetworkUpgrade::Sapling),
Just(NetworkUpgrade::Blossom),
Just(NetworkUpgrade::Heartwood),
Just(NetworkUpgrade::Canopy),
Just(NetworkUpgrade::Nu5),
// TODO: add future network upgrades (#1974)
]
.boxed()
}
}

View File

@ -108,7 +108,7 @@ impl Transaction {
/// Generate a proptest strategy for V5 Transactions
pub fn v5_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
(
Self::branch_id_strategy(),
NetworkUpgrade::branch_id_strategy(),
any::<LockTime>(),
any::<block::Height>(),
transparent::Input::vec_strategy(ledger_state, 10),
@ -140,20 +140,6 @@ impl Transaction {
.boxed()
}
// A custom strategy to use only some of the NetworkUpgrade values
fn branch_id_strategy() -> BoxedStrategy<NetworkUpgrade> {
prop_oneof![
Just(NetworkUpgrade::Overwinter),
Just(NetworkUpgrade::Sapling),
Just(NetworkUpgrade::Blossom),
Just(NetworkUpgrade::Heartwood),
Just(NetworkUpgrade::Canopy),
Just(NetworkUpgrade::Nu5),
// TODO: add future network upgrades
]
.boxed()
}
/// Proptest Strategy for creating a Vector of transactions where the first
/// transaction is always the only coinbase transaction
pub fn vec_strategy(

View File

@ -1,3 +1,7 @@
//! Property tests for transparent inputs and outputs.
//!
//! TODO: Move this module into a `tests` submodule.
use zebra_test::prelude::*;
use crate::{block, LedgerState};

View File

@ -5,7 +5,10 @@ use zebra_chain::{block, transparent};
/// An unspent `transparent::Output`, with accompanying metadata.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
#[cfg_attr(
any(test, feature = "proptest-impl"),
derive(proptest_derive::Arbitrary)
)]
pub struct Utxo {
/// The output itself.
pub output: transparent::Output,