Skip to content

Commit 2b6ebf0

Browse files
committed
More test_case usage
1 parent b1d90c9 commit 2b6ebf0

2 files changed

Lines changed: 174 additions & 325 deletions

File tree

interface/src/state.rs

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,117 +1988,6 @@ mod tests {
19881988
check_flag(StakeFlags::empty(), 0);
19891989
}
19901990

1991-
#[cfg(test)]
1992-
#[allow(deprecated)]
1993-
mod delegation_prop_tests {
1994-
use {
1995-
super::*,
1996-
crate::{
1997-
stake_history::{StakeHistory, StakeHistoryEntry},
1998-
ulp::max_ulp_tolerance,
1999-
},
2000-
proptest::prelude::*,
2001-
solana_pubkey::Pubkey,
2002-
};
2003-
2004-
prop_compose! {
2005-
fn arbitrary_delegation()(
2006-
// This tests is bounded to the range where `f64` can represent every integer exactly.
2007-
// Beyond this, integer math and float math diverge considerably.
2008-
// This case is covered in `warmup_cooldown_allowance.rs`.
2009-
stake in 0u64..=(1u64 << 53) - 1,
2010-
activation_epoch in 0u64..=50,
2011-
deactivation_offset in 0u64..=50,
2012-
) -> Delegation {
2013-
let deactivation_epoch = activation_epoch.saturating_add(deactivation_offset);
2014-
2015-
Delegation {
2016-
voter_pubkey: Pubkey::new_unique(),
2017-
stake,
2018-
activation_epoch,
2019-
deactivation_epoch,
2020-
..Delegation::default()
2021-
}
2022-
}
2023-
}
2024-
2025-
prop_compose! {
2026-
fn arbitrary_stake_history(max_epoch: Epoch)(
2027-
entries in prop::collection::vec(
2028-
(
2029-
0u64..=max_epoch,
2030-
0u64..=1_000_000_000_000, // effective
2031-
0u64..=1_000_000_000_000, // activating
2032-
0u64..=1_000_000_000_000, // deactivating
2033-
),
2034-
0..=((max_epoch + 1) as usize),
2035-
)
2036-
) -> StakeHistory {
2037-
let mut history = StakeHistory::default();
2038-
for (epoch, effective, activating, deactivating) in entries {
2039-
history.add(
2040-
epoch,
2041-
StakeHistoryEntry {
2042-
effective,
2043-
activating,
2044-
deactivating,
2045-
},
2046-
);
2047-
}
2048-
history
2049-
}
2050-
}
2051-
2052-
proptest! {
2053-
#![proptest_config(ProptestConfig::with_cases(10_000))]
2054-
2055-
#[test]
2056-
fn delegation_stake_matches_legacy_within_tolerance(
2057-
delegation in arbitrary_delegation(),
2058-
target_epoch in 0u64..=50,
2059-
new_rate_activation_epoch_option in prop::option::of(0u64..=50),
2060-
stake_history in arbitrary_stake_history(50),
2061-
) {
2062-
let new_stake = delegation.stake_v2(
2063-
target_epoch,
2064-
&stake_history,
2065-
new_rate_activation_epoch_option,
2066-
);
2067-
let legacy_stake = delegation.stake(
2068-
target_epoch,
2069-
&stake_history,
2070-
new_rate_activation_epoch_option,
2071-
);
2072-
2073-
// neither path should ever exceed the delegated amount.
2074-
prop_assert!(new_stake <= delegation.stake);
2075-
prop_assert!(legacy_stake <= delegation.stake);
2076-
2077-
// If the delegation has no stake, both must be zero.
2078-
if delegation.stake == 0 {
2079-
prop_assert_eq!(new_stake, 0);
2080-
prop_assert_eq!(legacy_stake, 0);
2081-
} else {
2082-
// Compare with a ULP-based tolerance to account for float vs integer math.
2083-
let diff = new_stake.abs_diff(legacy_stake);
2084-
let tolerance = max_ulp_tolerance(new_stake, legacy_stake);
2085-
2086-
prop_assert!(
2087-
diff <= tolerance,
2088-
"stake mismatch: new={}, legacy={}, diff={}, tol={}, delegation={:?}, target_epoch={}, new_rate_activation_epoch_option={:?}",
2089-
new_stake,
2090-
legacy_stake,
2091-
diff,
2092-
tolerance,
2093-
delegation,
2094-
target_epoch,
2095-
new_rate_activation_epoch_option,
2096-
);
2097-
}
2098-
}
2099-
}
2100-
}
2101-
21021991
mod deprecated {
21031992
use {
21041993
super::*,
@@ -2249,7 +2138,7 @@ mod tests {
22492138

22502139
let serialized_data = borsh::to_vec(&legacy_delegation).unwrap();
22512140

2252-
// Deserialize into the NEW Delegation struct
2141+
// Deserialize into the new `Delegation` struct
22532142
let new_delegation = Delegation::try_from_slice(&serialized_data).unwrap();
22542143

22552144
// Assert that the fields are identical

0 commit comments

Comments
 (0)