time_primitives/
bounds.rs

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
use polkadot_sdk::sp_runtime::Perbill;

#[derive(Debug)]
pub struct Bounds {
	pub tasks: Perbill,
	pub batches: Perbill,
	pub heartbeats: Perbill,
	pub elections: Perbill,
}

pub const ON_INITIALIZE_BOUNDS: Bounds = Bounds {
	tasks: Perbill::from_percent(40),
	batches: Perbill::from_percent(20),
	heartbeats: Perbill::from_percent(10),
	elections: Perbill::from_percent(30),
};

#[test]
fn validate_on_initialize_bounds() {
	use polkadot_sdk::sp_runtime::Saturating;
	assert_eq!(
		ON_INITIALIZE_BOUNDS
			.tasks
			.saturating_add(ON_INITIALIZE_BOUNDS.batches)
			.saturating_add(ON_INITIALIZE_BOUNDS.heartbeats)
			.saturating_add(ON_INITIALIZE_BOUNDS.elections),
		Perbill::from_percent(100),
		"Total Bounds {:?} != 100%",
		ON_INITIALIZE_BOUNDS
	);
}