Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrustThresholdFraction: allow to be initialized with value 1 #1209

Merged
merged 4 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 7 additions & 7 deletions tendermint/src/trust_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl TrustThresholdFraction {
/// The parameters are valid iff `1/3 <= numerator/denominator < 1`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc needs to be updated too, then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// 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());
}
}
}