Skip to content

Commit

Permalink
Add tests for TrustThresholdFraction
Browse files Browse the repository at this point in the history
  • Loading branch information
liamsi committed Jan 27, 2020
1 parent b2cc59a commit 31e0f00
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tendermint/src/lite/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,30 @@ impl TrustThreshold for TrustThresholdFraction {

impl Default for TrustThresholdFraction {
fn default() -> Self {
Self {
numerator: 1,
denominator: 3,
}
Self::new(1, 3)
}
}

mod tests {
use crate::lite::{TrustThreshold, TrustThresholdFraction};

#[test]
fn default_is_enough_power() {
let threshold = TrustThresholdFraction::default();

// 100% > 33%
assert!(threshold.is_enough_power(3, 3));

// 66% > 33%
assert!(threshold.is_enough_power(2, 3));

// 33% <= 33%
assert_eq!(threshold.is_enough_power(1, 3), false);

// 1% < 33%
assert_eq!(threshold.is_enough_power(1, 100), false);
}
}
/// Requester can be used to request [`SignedHeader`]s and [`ValidatorSet`]s for a
/// given height, e.g., by talking to a tendermint fullnode through RPC.
pub trait Requester<C, H>
Expand Down

0 comments on commit 31e0f00

Please sign in to comment.