@@ -359,25 +359,26 @@ impl<T: Config<I>, I: 'static> SortedListProvider<T::AccountId> for Pallet<T, I>
359359 List :: < T , I > :: unsafe_clear ( )
360360 }
361361
362- #[ cfg( feature = "runtime-benchmarks" ) ]
363- fn score_update_worst_case ( who : & T :: AccountId , is_increase : bool ) -> Self :: Score {
364- use frame_support:: traits:: Get as _;
365- let thresholds = T :: BagThresholds :: get ( ) ;
366- let node = list:: Node :: < T , I > :: get ( who) . unwrap ( ) ;
367- let current_bag_idx = thresholds
368- . iter ( )
369- . chain ( sp_std:: iter:: once ( & T :: Score :: max_value ( ) ) )
370- . position ( |w| w == & node. bag_upper ( ) )
371- . unwrap ( ) ;
372-
373- if is_increase {
374- let next_threshold_idx = current_bag_idx + 1 ;
375- assert ! ( thresholds. len( ) > next_threshold_idx) ;
376- thresholds[ next_threshold_idx]
377- } else {
378- assert ! ( current_bag_idx != 0 ) ;
379- let prev_threshold_idx = current_bag_idx - 1 ;
380- thresholds[ prev_threshold_idx]
362+ frame_election_provider_support:: runtime_benchmarks_enabled! {
363+ fn score_update_worst_case( who: & T :: AccountId , is_increase: bool ) -> Self :: Score {
364+ use frame_support:: traits:: Get as _;
365+ let thresholds = T :: BagThresholds :: get( ) ;
366+ let node = list:: Node :: <T , I >:: get( who) . unwrap( ) ;
367+ let current_bag_idx = thresholds
368+ . iter( )
369+ . chain( sp_std:: iter:: once( & T :: Score :: max_value( ) ) )
370+ . position( |w| w == & node. bag_upper)
371+ . unwrap( ) ;
372+
373+ if is_increase {
374+ let next_threshold_idx = current_bag_idx + 1 ;
375+ assert!( thresholds. len( ) > next_threshold_idx) ;
376+ thresholds[ next_threshold_idx]
377+ } else {
378+ assert!( current_bag_idx != 0 ) ;
379+ let prev_threshold_idx = current_bag_idx - 1 ;
380+ thresholds[ prev_threshold_idx]
381+ }
381382 }
382383 }
383384}
@@ -389,14 +390,15 @@ impl<T: Config<I>, I: 'static> ScoreProvider<T::AccountId> for Pallet<T, I> {
389390 Node :: < T , I > :: get ( id) . map ( |node| node. score ( ) ) . unwrap_or_default ( )
390391 }
391392
392- #[ cfg( any( feature = "runtime-benchmarks" , feature = "fuzz" , test) ) ]
393- fn set_score_of ( id : & T :: AccountId , new_score : T :: Score ) {
394- ListNodes :: < T , I > :: mutate ( id, |maybe_node| {
395- if let Some ( node) = maybe_node. as_mut ( ) {
396- node. set_score ( new_score)
397- } else {
398- panic ! ( "trying to mutate {:?} which does not exists" , id) ;
399- }
400- } )
393+ frame_election_provider_support:: runtime_benchmarks_or_fuzz_enabled! {
394+ fn set_score_of( id: & T :: AccountId , new_score: T :: Score ) {
395+ ListNodes :: <T , I >:: mutate( id, |maybe_node| {
396+ if let Some ( node) = maybe_node. as_mut( ) {
397+ node. score = new_score;
398+ } else {
399+ panic!( "trying to mutate {:?} which does not exists" , id) ;
400+ }
401+ } )
402+ }
401403 }
402404}
0 commit comments