Refactor out MaxPossibleReward, fix staking arithmetic (#4041)

* Refactor out MaxPossibleReward, fix staking arithmetic

* Fix rounding error in test
This commit is contained in:
Gavin Wood
2019-11-07 12:34:13 +01:00
committed by GitHub
parent dcee91412c
commit bb6b3db57e
6 changed files with 52 additions and 44 deletions
+5 -2
View File
@@ -23,7 +23,9 @@ use core::ops::Sub;
#[derive(PartialEq, Eq, primitives::RuntimeDebug)]
pub struct PiecewiseLinear<'a> {
/// Array of points. Must be in order from the lowest abscissas to the highest.
pub points: &'a [(Perbill, Perbill)]
pub points: &'a [(Perbill, Perbill)],
/// The maximum value that can be returned.
pub maximum: Perbill,
}
fn abs_sub<N: Ord + Sub<Output=N> + Clone>(a: N, b: N) -> N where {
@@ -135,7 +137,8 @@ fn test_calculate_for_fraction_times_denominator() {
(Perbill::from_parts(0_000_000_000), Perbill::from_parts(0_500_000_000)),
(Perbill::from_parts(0_500_000_000), Perbill::from_parts(1_000_000_000)),
(Perbill::from_parts(1_000_000_000), Perbill::from_parts(0_000_000_000)),
]
],
maximum: Perbill::from_parts(1_000_000_000),
};
pub fn formal_calculate_for_fraction_times_denominator(n: u64, d: u64) -> u64 {