From 50558845bd2a42d6b2738f6545bd33d867d1e8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Laferri=C3=A8re?= Date: Tue, 25 Oct 2022 10:37:35 -0400 Subject: [PATCH] `TrustThresholdFraction`: allow to be initialized with value 1 (#1209) * fix check in new * changelog * fix test * update docs --- .../1208-trustthresholdfraction-check.md | 2 ++ .../proptest-regressions/trust_threshold.txt | 7 +++++++ tendermint/src/trust_threshold.rs | 16 ++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 .changelog/unreleased/bug-fixes/1208-trustthresholdfraction-check.md create mode 100644 tendermint/proptest-regressions/trust_threshold.txt diff --git a/.changelog/unreleased/bug-fixes/1208-trustthresholdfraction-check.md b/.changelog/unreleased/bug-fixes/1208-trustthresholdfraction-check.md new file mode 100644 index 000000000..24b0e4cc6 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1208-trustthresholdfraction-check.md @@ -0,0 +1,2 @@ +- Allow a `TrustThresholdFraction` of 1 + ([#1208](https://github.com/informalsystems/tendermint-rs/issues/1208)) diff --git a/tendermint/proptest-regressions/trust_threshold.txt b/tendermint/proptest-regressions/trust_threshold.txt new file mode 100644 index 000000000..cb7a1a107 --- /dev/null +++ b/tendermint/proptest-regressions/trust_threshold.txt @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 5f12a01ebfd5d2efb4e16c1267e4d876465cfa3294d159abf2051d5aba03f74c # shrinks to num = 1 diff --git a/tendermint/src/trust_threshold.rs b/tendermint/src/trust_threshold.rs index bf60042b4..8a75166cd 100644 --- a/tendermint/src/trust_threshold.rs +++ b/tendermint/src/trust_threshold.rs @@ -51,10 +51,10 @@ impl TrustThresholdFraction { /// Instantiate a TrustThresholdFraction if the given denominator and /// numerator are valid. /// - /// The parameters are valid iff `1/3 <= numerator/denominator < 1`. + /// The parameters are valid iff `1/3 <= numerator/denominator <= 1`. /// In any other case we return an error. pub fn new(numerator: u64, denominator: u64) -> Result { - if numerator >= denominator { + if numerator > denominator { return Err(Error::trust_threshold_too_large()); } if denominator == 0 { @@ -159,12 +159,6 @@ mod test { assert!(from_json(num, denom).is_err()); } - #[test] - fn cannot_be_one(num in 1..1000u64) { - assert!(TrustThresholdFraction::new(num, num).is_err()); - assert!(from_json(num, num).is_err()); - } - #[test] fn undefined(num in 1..1000u64) { // Numerator should be irrelevant @@ -191,5 +185,11 @@ mod test { assert_eq!(frac.numerator(), num); assert_eq!(frac.denominator(), denom); } + + #[test] + fn can_be_one(num in 1..1000u64) { + assert!(TrustThresholdFraction::new(num, num).is_ok()); + assert!(from_json(num, num).is_ok()); + } } }