Fuzz testing for nomination pools (#12002)

* some additional tests and stuff

* make sanity public

* add some sort of fuzz test for pools

* breaks every now and then

* breaks every now and then

* IT WORKS AND PASSES 100k TESTS

* cleanup

* safe id addition

* fix assert_eq_error_rate

* Update frame/nomination-pools/src/tests.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/nomination-pools/src/tests.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* add some doc

* Fix

* ".git/.scripts/fmt.sh" 1

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: command-bot <>
This commit is contained in:
Kian Paimani
2022-09-12 15:27:11 +01:00
committed by GitHub
parent b356a5589a
commit 113727950b
8 changed files with 647 additions and 65 deletions
+20 -1
View File
@@ -36,6 +36,8 @@ pub use sp_std;
#[doc(hidden)]
pub use paste;
#[doc(hidden)]
pub use sp_arithmetic::traits::Saturating;
#[doc(hidden)]
pub use sp_application_crypto as app_crypto;
@@ -825,7 +827,24 @@ pub fn verify_encoded_lazy<V: Verify, T: codec::Encode>(
macro_rules! assert_eq_error_rate {
($x:expr, $y:expr, $error:expr $(,)?) => {
assert!(
($x) >= (($y) - ($error)) && ($x) <= (($y) + ($error)),
($x >= $crate::Saturating::saturating_sub($y, $error)) &&
($x <= $crate::Saturating::saturating_add($y, $error)),
"{:?} != {:?} (with error rate {:?})",
$x,
$y,
$error,
);
};
}
/// Same as [`assert_eq_error_rate`], but intended to be used with floating point number, or
/// generally those who do not have over/underflow potentials.
#[macro_export]
#[cfg(feature = "std")]
macro_rules! assert_eq_error_rate_float {
($x:expr, $y:expr, $error:expr $(,)?) => {
assert!(
($x >= $y - $error) && ($x <= $y + $error),
"{:?} != {:?} (with error rate {:?})",
$x,
$y,