Address grumbles in eras PR (#782)

* Address grumbles

* Fix hash
This commit is contained in:
Gav Wood
2018-09-20 23:18:47 +02:00
committed by GitHub
parent 67bf1a6eaa
commit ebb688f81f
10 changed files with 42 additions and 35 deletions
@@ -79,7 +79,7 @@ impl Era {
pub fn birth(self, current: u64) -> u64 {
match self {
Era::Immortal => 0,
Era::Mortal(period, phase) => (current - phase) / period * period + phase,
Era::Mortal(period, phase) => (current.max(phase) - phase) / period * period + phase,
}
}
@@ -189,4 +189,10 @@ mod tests {
assert_ne!(e.birth(10), 6);
assert_ne!(e.birth(5), 6);
}
#[test]
fn current_less_than_phase() {
// should not panic
Era::mortal(4, 3).birth(1);
}
}