1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::BlockTs;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Epoch {
pub size: u128,
pub time: BlockTs,
}
impl Epoch {
pub fn new(size: u128, time: BlockTs) -> Self {
Self { size, time }
}
}
impl Default for Epoch {
fn default() -> Self {
Self::new(400, 120_000_000)
}
}
impl std::fmt::Display for Epoch {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", serde_json::to_string(&self).unwrap())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_epoch() {
let a = Epoch::default();
let b = Epoch::new(400, 120_000_000);
assert_eq!(&a, &b)
}
}