Skip to content

Commit

Permalink
TrustThresholdFraction: allow to be initialized with value 1 (#1209)
Browse files Browse the repository at this point in the history
* fix check in new

* changelog

* fix test

* update docs
  • Loading branch information
plafer committed Oct 25, 2022
1 parent f62a000 commit 5055884
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Allow a `TrustThresholdFraction` of 1
([#1208](https://github.com/informalsystems/tendermint-rs/issues/1208))
7 changes: 7 additions & 0 deletions tendermint/proptest-regressions/trust_threshold.txt
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions tendermint/src/trust_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Error> {
if numerator >= denominator {
if numerator > denominator {
return Err(Error::trust_threshold_too_large());
}
if denominator == 0 {
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}
}

0 comments on commit 5055884

Please sign in to comment.