mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 11:21:07 +00:00
Enforce MaxEncodedLen impl for NposSolution (#11103)
* Fail if `MaxVoters` too small * Fixing benchmarking test, better naming of error * reverting accidental change * use fully qualified syntax no need to interate to calculate len * Fail directly if too many voters
This commit is contained in:
@@ -91,6 +91,33 @@ mod solution_type {
|
||||
assert!(with_compact < without_compact);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_assignment_fail_too_many_voters() {
|
||||
let rng = rand::rngs::SmallRng::seed_from_u64(0);
|
||||
|
||||
// This will produce 24 voters..
|
||||
let (voters, assignments, candidates) = generate_random_votes(10, 25, rng);
|
||||
let voter_index = make_voter_fn(&voters);
|
||||
let target_index = make_target_fn(&candidates);
|
||||
|
||||
// Limit the voters to 20..
|
||||
generate_solution_type!(
|
||||
pub struct InnerTestSolution::<
|
||||
VoterIndex = u32,
|
||||
TargetIndex = u16,
|
||||
Accuracy = TestAccuracy,
|
||||
MaxVoters = frame_support::traits::ConstU32::<20>,
|
||||
>(16)
|
||||
);
|
||||
|
||||
// 24 > 20, so this should fail.
|
||||
assert_eq!(
|
||||
InnerTestSolution::from_assignment(&assignments, &voter_index, &target_index)
|
||||
.unwrap_err(),
|
||||
NposError::TooManyVoters,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn max_encoded_len_too_small() {
|
||||
generate_solution_type!(
|
||||
|
||||
Reference in New Issue
Block a user