Cleanup a few arbitrary impls (#2222)
This commit is contained in:
parent
0b611eb770
commit
4c276dae64
|
@ -313,7 +313,7 @@ pub enum Error {
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub struct NegativeAllowed {}
|
pub struct NegativeAllowed;
|
||||||
|
|
||||||
impl Constraint for NegativeAllowed {
|
impl Constraint for NegativeAllowed {
|
||||||
fn valid_range() -> RangeInclusive<i64> {
|
fn valid_range() -> RangeInclusive<i64> {
|
||||||
|
@ -331,7 +331,7 @@ impl Constraint for NegativeAllowed {
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||||
pub struct NonNegative {}
|
pub struct NonNegative;
|
||||||
|
|
||||||
impl Constraint for NonNegative {
|
impl Constraint for NonNegative {
|
||||||
fn valid_range() -> RangeInclusive<i64> {
|
fn valid_range() -> RangeInclusive<i64> {
|
||||||
|
|
|
@ -17,6 +17,9 @@ mod network;
|
||||||
mod network_upgrade;
|
mod network_upgrade;
|
||||||
mod transaction;
|
mod transaction;
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "proptest-impl"))]
|
||||||
|
pub mod arbitrary;
|
||||||
|
|
||||||
pub use genesis::*;
|
pub use genesis::*;
|
||||||
pub use network::Network;
|
pub use network::Network;
|
||||||
pub use network_upgrade::*;
|
pub use network_upgrade::*;
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -108,7 +108,7 @@ impl Transaction {
|
||||||
/// Generate a proptest strategy for V5 Transactions
|
/// Generate a proptest strategy for V5 Transactions
|
||||||
pub fn v5_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
|
pub fn v5_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
|
||||||
(
|
(
|
||||||
Self::branch_id_strategy(),
|
NetworkUpgrade::branch_id_strategy(),
|
||||||
any::<LockTime>(),
|
any::<LockTime>(),
|
||||||
any::<block::Height>(),
|
any::<block::Height>(),
|
||||||
transparent::Input::vec_strategy(ledger_state, 10),
|
transparent::Input::vec_strategy(ledger_state, 10),
|
||||||
|
@ -140,20 +140,6 @@ impl Transaction {
|
||||||
.boxed()
|
.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
|
/// Proptest Strategy for creating a Vector of transactions where the first
|
||||||
/// transaction is always the only coinbase transaction
|
/// transaction is always the only coinbase transaction
|
||||||
pub fn vec_strategy(
|
pub fn vec_strategy(
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
//! Property tests for transparent inputs and outputs.
|
||||||
|
//!
|
||||||
|
//! TODO: Move this module into a `tests` submodule.
|
||||||
|
|
||||||
use zebra_test::prelude::*;
|
use zebra_test::prelude::*;
|
||||||
|
|
||||||
use crate::{block, LedgerState};
|
use crate::{block, LedgerState};
|
||||||
|
|
|
@ -5,7 +5,10 @@ use zebra_chain::{block, transparent};
|
||||||
|
|
||||||
/// An unspent `transparent::Output`, with accompanying metadata.
|
/// An unspent `transparent::Output`, with accompanying metadata.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[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 {
|
pub struct Utxo {
|
||||||
/// The output itself.
|
/// The output itself.
|
||||||
pub output: transparent::Output,
|
pub output: transparent::Output,
|
||||||
|
|
Loading…
Reference in New Issue