Add some tests to demonstrate an estimate of the nominator limit (#2724)

* Add some tests to demonstrate an estimate of the nominator limit

* Update runtime/kusama/src/lib.rs

* Update runtime/polkadot/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Fix build

* remove max

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Kian Paimani
2021-03-31 11:13:46 +02:00
committed by GitHub
parent 02166f4e0c
commit da1f54a19d
2 changed files with 53 additions and 0 deletions
+26
View File
@@ -1484,4 +1484,30 @@ mod test_fees {
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000u128));
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000_000u128));
}
#[test]
fn nominator_limit() {
use pallet_election_provider_multi_phase::WeightInfo;
// starting point of the nominators.
let all_voters: u32 = 10_000;
// assuming we want around 5k candidates and 1k active validators.
let all_targets: u32 = 5_000;
let desired: u32 = 1_000;
let weight_with = |active| {
<Runtime as pallet_election_provider_multi_phase::Config>::WeightInfo::submit_unsigned(
all_voters.max(active),
all_targets,
active,
desired,
)
};
let mut active = 1;
while weight_with(active) <= OffchainSolutionWeightLimit::get() || active == all_voters {
active += 1;
}
println!("can support {} nominators to yield a weight of {}", active, weight_with(active));
}
}
+27
View File
@@ -1510,4 +1510,31 @@ mod test_fees {
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000u128));
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000_000u128));
}
#[test]
fn nominator_limit() {
use pallet_election_provider_multi_phase::WeightInfo;
// starting point of the nominators.
let target_voters: u32 = 50_000;
// assuming we want around 5k candidates and 1k active validators. (March 31, 2021)
let all_targets: u32 = 5_000;
let desired: u32 = 1_000;
let weight_with = |active| {
<Runtime as pallet_election_provider_multi_phase::Config>::WeightInfo::submit_unsigned(
active,
all_targets,
active,
desired,
)
};
let mut active = target_voters;
while weight_with(active) <= OffchainSolutionWeightLimit::get() || active == target_voters {
active += 1;
}
println!("can support {} nominators to yield a weight of {}", active, weight_with(active));
assert!(active > target_voters, "we need to reevaluate the weight of the election system");
}
}