Unverified Commit cff3b99a authored by Kian Paimani's avatar Kian Paimani Committed by GitHub
Browse files

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's avatarShawn Tabrizi <shawntabrizi@gmail.com>

* Fix build

* remove max

Co-authored-by: Shawn Tabrizi's avatarShawn Tabrizi <shawntabrizi@gmail.com>
parent 4e2d493f
Pipeline #131999 failed with stages
in 31 minutes and 5 seconds
...@@ -1484,4 +1484,30 @@ mod test_fees { ...@@ -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_000u128));
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_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));
}
} }
...@@ -1510,4 +1510,31 @@ mod test_fees { ...@@ -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_000u128));
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_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");
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment