@@ -24,7 +24,7 @@ mod mock;
2424
2525use frame_benchmarking:: { account, frame_support:: traits:: Currency , vec, whitelist_account, Vec } ;
2626use frame_election_provider_support:: SortedListProvider ;
27- use frame_support:: { ensure, traits:: Get } ;
27+ use frame_support:: { assert_ok , ensure, traits:: Get } ;
2828use frame_system:: RawOrigin as Origin ;
2929use pallet_nomination_pools:: {
3030 BalanceOf , BondExtra , BondedPoolInner , BondedPools , ConfigOp , MaxPoolMembers ,
@@ -48,6 +48,12 @@ pub trait Config:
4848
4949pub struct Pallet < T : Config > ( Pools < T > ) ;
5050
51+ fn min_create_bond < T : Config > ( ) -> BalanceOf < T > {
52+ MinCreateBond :: < T > :: get ( )
53+ . max ( T :: StakingInterface :: minimum_bond ( ) )
54+ . max ( CurrencyOf :: < T > :: minimum_balance ( ) )
55+ }
56+
5157fn create_funded_user_with_balance < T : pallet_nomination_pools:: Config > (
5258 string : & ' static str ,
5359 n : u32 ,
@@ -209,9 +215,7 @@ impl<T: Config> ListScenario<T> {
209215
210216frame_benchmarking:: benchmarks! {
211217 join {
212- let origin_weight = pallet_nomination_pools:: MinCreateBond :: <T >:: get( )
213- . max( CurrencyOf :: <T >:: minimum_balance( ) )
214- * 2u32 . into( ) ;
218+ let origin_weight = min_create_bond:: <T >( ) * 2u32 . into( ) ;
215219
216220 // setup the worst case list scenario.
217221 let scenario = ListScenario :: <T >:: new( origin_weight, true ) ?;
@@ -237,9 +241,7 @@ frame_benchmarking::benchmarks! {
237241 }
238242
239243 bond_extra_transfer {
240- let origin_weight = pallet_nomination_pools:: MinCreateBond :: <T >:: get( )
241- . max( CurrencyOf :: <T >:: minimum_balance( ) )
242- * 2u32 . into( ) ;
244+ let origin_weight = min_create_bond:: <T >( ) * 2u32 . into( ) ;
243245 let scenario = ListScenario :: <T >:: new( origin_weight, true ) ?;
244246 let extra = scenario. dest_weight. clone( ) - origin_weight;
245247
@@ -254,9 +256,7 @@ frame_benchmarking::benchmarks! {
254256 }
255257
256258 bond_extra_reward {
257- let origin_weight = pallet_nomination_pools:: MinCreateBond :: <T >:: get( )
258- . max( CurrencyOf :: <T >:: minimum_balance( ) )
259- * 2u32 . into( ) ;
259+ let origin_weight = min_create_bond:: <T >( ) * 2u32 . into( ) ;
260260 let scenario = ListScenario :: <T >:: new( origin_weight, true ) ?;
261261 let extra = ( scenario. dest_weight. clone( ) - origin_weight) . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
262262
@@ -274,7 +274,7 @@ frame_benchmarking::benchmarks! {
274274 }
275275
276276 claim_payout {
277- let origin_weight = pallet_nomination_pools :: MinCreateBond :: <T >:: get ( ) . max ( CurrencyOf :: < T > :: minimum_balance ( ) ) * 2u32 . into( ) ;
277+ let origin_weight = min_create_bond :: <T >( ) * 2u32 . into( ) ;
278278 let ed = CurrencyOf :: <T >:: minimum_balance( ) ;
279279 let ( depositor, pool_account) = create_pool_account:: <T >( 0 , origin_weight) ;
280280 let reward_account = Pools :: <T >:: create_reward_account( 1 ) ;
@@ -304,9 +304,7 @@ frame_benchmarking::benchmarks! {
304304 unbond {
305305 // The weight the nominator will start at. The value used here is expected to be
306306 // significantly higher than the first position in a list (e.g. the first bag threshold).
307- let origin_weight = BalanceOf :: <T >:: try_from( 952_994_955_240_703u128 )
308- . map_err( |_| "balance expected to be a u128" )
309- . unwrap( ) ;
307+ let origin_weight = min_create_bond:: <T >( ) * 200u32 . into( ) ;
310308 let scenario = ListScenario :: <T >:: new( origin_weight, false ) ?;
311309 let amount = origin_weight - scenario. dest_weight. clone( ) ;
312310
@@ -336,9 +334,7 @@ frame_benchmarking::benchmarks! {
336334 pool_withdraw_unbonded {
337335 let s in 0 .. MAX_SPANS ;
338336
339- let min_create_bond = MinCreateBond :: <T >:: get( )
340- . max( T :: StakingInterface :: minimum_bond( ) )
341- . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
337+ let min_create_bond = min_create_bond:: <T >( ) ;
342338 let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond) ;
343339
344340 // Add a new member
@@ -380,9 +376,7 @@ frame_benchmarking::benchmarks! {
380376 withdraw_unbonded_update {
381377 let s in 0 .. MAX_SPANS ;
382378
383- let min_create_bond = MinCreateBond :: <T >:: get( )
384- . max( T :: StakingInterface :: minimum_bond( ) )
385- . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
379+ let min_create_bond = min_create_bond:: <T >( ) ;
386380 let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond) ;
387381
388382 // Add a new member
@@ -427,10 +421,7 @@ frame_benchmarking::benchmarks! {
427421 withdraw_unbonded_kill {
428422 let s in 0 .. MAX_SPANS ;
429423
430- let min_create_bond = MinCreateBond :: <T >:: get( )
431- . max( T :: StakingInterface :: minimum_bond( ) )
432- . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
433-
424+ let min_create_bond = min_create_bond:: <T >( ) ;
434425 let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond) ;
435426
436427 // We set the pool to the destroying state so the depositor can leave
@@ -494,9 +485,7 @@ frame_benchmarking::benchmarks! {
494485 }
495486
496487 create {
497- let min_create_bond = MinCreateBond :: <T >:: get( )
498- . max( T :: StakingInterface :: minimum_bond( ) )
499- . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
488+ let min_create_bond = min_create_bond:: <T >( ) ;
500489 let depositor: T :: AccountId = account( "depositor" , USER_SEED , 0 ) ;
501490
502491 // Give the depositor some balance to bond
@@ -542,9 +531,7 @@ frame_benchmarking::benchmarks! {
542531 let n in 1 .. T :: MaxNominations :: get( ) ;
543532
544533 // Create a pool
545- let min_create_bond = MinCreateBond :: <T >:: get( )
546- . max( T :: StakingInterface :: minimum_bond( ) )
547- . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
534+ let min_create_bond = min_create_bond:: <T >( ) * 2u32 . into( ) ;
548535 let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond) ;
549536
550537 // Create some accounts to nominate. For the sake of benchmarking they don't need to be
@@ -581,9 +568,7 @@ frame_benchmarking::benchmarks! {
581568
582569 set_state {
583570 // Create a pool
584- let min_create_bond = MinCreateBond :: <T >:: get( )
585- . max( T :: StakingInterface :: minimum_bond( ) )
586- . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
571+ let min_create_bond = min_create_bond:: <T >( ) ;
587572 let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond) ;
588573 BondedPools :: <T >:: mutate( & 1 , |maybe_pool| {
589574 // Force the pool into an invalid state
@@ -601,10 +586,7 @@ frame_benchmarking::benchmarks! {
601586 let n in 1 .. <T as pallet_nomination_pools:: Config >:: MaxMetadataLen :: get( ) ;
602587
603588 // Create a pool
604- let min_create_bond = MinCreateBond :: <T >:: get( )
605- . max( T :: StakingInterface :: minimum_bond( ) )
606- . max( CurrencyOf :: <T >:: minimum_balance( ) ) ;
607- let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond) ;
589+ let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond:: <T >( ) * 2u32 . into( ) ) ;
608590
609591 // Create metadata of the max possible size
610592 let metadata: Vec <u8 > = ( 0 ..n) . map( |_| 42 ) . collect( ) ;
@@ -633,7 +615,7 @@ frame_benchmarking::benchmarks! {
633615
634616 update_roles {
635617 let first_id = pallet_nomination_pools:: LastPoolId :: <T >:: get( ) + 1 ;
636- let ( root, _) = create_pool_account:: <T >( 0 , CurrencyOf :: <T >:: minimum_balance ( ) * 2u32 . into( ) ) ;
618+ let ( root, _) = create_pool_account:: <T >( 0 , min_create_bond :: <T >( ) * 2u32 . into( ) ) ;
637619 let random: T :: AccountId = account( "but is anything really random in computers..?" , 0 , USER_SEED ) ;
638620 } : _(
639621 Origin :: Signed ( root. clone( ) ) ,
@@ -653,6 +635,24 @@ frame_benchmarking::benchmarks! {
653635 )
654636 }
655637
638+ chill {
639+ // Create a pool
640+ let ( depositor, pool_account) = create_pool_account:: <T >( 0 , min_create_bond:: <T >( ) * 2u32 . into( ) ) ;
641+
642+ // Nominate with the pool.
643+ let validators: Vec <_> = ( 0 ..T :: MaxNominations :: get( ) )
644+ . map( |i| account( "stash" , USER_SEED , i) )
645+ . collect( ) ;
646+
647+ assert_ok!( Pools :: <T >:: nominate( Origin :: Signed ( depositor. clone( ) ) . into( ) , 1 , validators) ) ;
648+ assert!( T :: StakingInterface :: nominations( Pools :: <T >:: create_bonded_account( 1 ) ) . is_some( ) ) ;
649+
650+ whitelist_account!( depositor) ;
651+ } : _( Origin :: Signed ( depositor. clone( ) ) , 1 )
652+ verify {
653+ assert!( T :: StakingInterface :: nominations( Pools :: <T >:: create_bonded_account( 1 ) ) . is_none( ) ) ;
654+ }
655+
656656 impl_benchmark_test_suite!(
657657 Pallet ,
658658 crate :: mock:: new_test_ext( ) ,
0 commit comments