Skip to content
tests.rs 75.6 KiB
Newer Older
			prefix + 19,
			prefix + 21,
			prefix + 23,
			prefix + 25]
		);

		System::set_block_number(1);
		Session::check_rotate_session(System::block_number());

		// For manual inspection
		println!("Validators are {:?}", Session::validators());
		println!("Validators are {:#?}",
			Session::validators()
				.iter()
				.map(|v| (v.clone(), Staking::stakers(v+1)))
				.collect::<Vec<(u64, Exposure<u64, u64>)>>()
		);

		// Each exposure => total == own + sum(others)
		check_exposure_all();

		// aside from some error, stake must be divided correctly
		let individual_expo_sum: u128 = Session::validators()
			.iter()
			.map(|v| Staking::stakers(v+1))
			.fold(0u128, |s, v| if v.others.len() > 0 { s + v.others[0].value as u128 } else { s });
			990000000000000000 - individual_expo_sum < 100,
			format!(
				"Nominator stake = {} / SUM(individual expo) = {} / diff = {}",
				990000000000000000u64,
				individual_expo_sum,
				990000000000000000 - individual_expo_sum
			)
#[test]
fn phragmen_large_scale_test_2() {
	with_externalities(&mut ExtBuilder::default()
		.nominate(false)
		.minimum_validator_count(1)
		.validator_count(2)
		.build(),
	|| {
		let _ = Staking::chill(Origin::signed(10));
		let _ = Staking::chill(Origin::signed(20));
		let nom_budget: u64 = 1_000_000_000_000_000_000;
		let c_budget: u64 = 4_000_000;

		bond_validator(2, c_budget as u64);
		bond_validator(4, c_budget as u64);

		bond_nominator(50, nom_budget, vec![3, 5]);

		System::set_block_number(1);
		Session::check_rotate_session(System::block_number());

		// Each exposure => total == own + sum(others)
		check_exposure_all();

		assert_total_expo(3, nom_budget / 2 + c_budget);
		assert_total_expo(5, nom_budget / 2 + c_budget);