Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions prdoc/pr_9731.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: simulate `rank_to_votes` conversion in vote benchmark

doc:
- audience: Runtime Dev
description: |
Fixes benchmarking failures for the vote extrinsic in pallet-ranked-collective by properly
simulating the `rank_to_votes` conversion process. Previously used hardcoded vote values
which caused assertion failures when using custom VoteWeight converters (e.g., in
[Ambassador Collective configuration](https://github.com/polkadot-fellows/runtimes/pull/736)). The fix calculates vote weight based on member's
actual rank and minimum required rank for the class.

crates:
- name: pallet-ranked-collective
bump: patch
23 changes: 19 additions & 4 deletions substrate/frame/ranked-collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ fn make_member<T: Config<I>, I: 'static>(rank: Rank) -> T::AccountId {
}

#[instance_benchmarks(
where <<T as pallet::Config<I>>::Polls as frame_support::traits::Polling<Tally<T, I, pallet::Pallet<T, I>>>>::Index: From<u8>
where
<<T as pallet::Config<I>>::Polls as frame_support::traits::Polling<Tally<T, I, pallet::Pallet<T, I>>>>::Index: From<u8>,
<T as frame_system::Config>::RuntimeEvent: TryInto<pallet::Event<T, I>>,
)]
mod benchmarks {
use super::*;
Expand Down Expand Up @@ -227,9 +229,22 @@ mod benchmarks {

// If the class exists, verify the vote event and tally.
if let Some(_) = class {
let tally = Tally::from_parts(0, 0, 1);
let vote_event = Event::Voted { who: caller, poll, vote: VoteRecord::Nay(1), tally };
assert_last_event::<T, I>(vote_event.into());
// Get the actual vote weight from the latest event's VoteRecord::Nay
let mut events = frame_system::Pallet::<T>::events();
let last_event = events.pop().expect("At least one event should exist");
let event: Event<T, I> = last_event
.event
.try_into()
.unwrap_or_else(|_| panic!("Event conversion failed"));

match event {
Event::Voted { vote: VoteRecord::Nay(vote_weight), who, poll: poll2, tally } => {
assert_eq!(tally, Tally::from_parts(0, 0, vote_weight));
assert_eq!(caller, who);
assert_eq!(poll, poll2);
},
_ => panic!("Invalid event"),
};
}

Ok(())
Expand Down
Loading