@@ -45,14 +45,17 @@ fn add_slashing_spans<T: Trait>(who: &T::AccountId, spans: u32) {
45
45
SlashingSpans :: < T > :: insert ( who, slashing_spans) ;
46
46
}
47
47
48
- // This function generates one validator being nominated by n nominators, and returns the validator
49
- // stash account and the nominators' stash and controller. It also starts an era and creates pending payouts.
48
+ // This function clears all existing validators and nominators from the set, and generates one new
49
+ // validator being nominated by n nominators, and returns the validator stash account and the
50
+ // nominators' stash and controller. It also starts an era and creates pending payouts.
50
51
pub fn create_validator_with_nominators < T : Trait > (
51
52
n : u32 ,
52
53
upper_bound : u32 ,
53
54
dead : bool ,
54
55
destination : RewardDestination < T :: AccountId >
55
56
) -> Result < ( T :: AccountId , Vec < ( T :: AccountId , T :: AccountId ) > ) , & ' static str > {
57
+ // Clean up any existing state.
58
+ clear_validators_and_nominators :: < T > ( ) ;
56
59
let mut points_total = 0 ;
57
60
let mut points_individual = Vec :: new ( ) ;
58
61
@@ -286,8 +289,6 @@ benchmarks! {
286
289
287
290
payout_stakers_dead_controller {
288
291
let n in 1 .. T :: MaxNominatorRewardedPerValidator :: get( ) as u32 ;
289
- // Clean up existing validators
290
- Validators :: <T >:: remove_all( ) ;
291
292
let ( validator, nominators) = create_validator_with_nominators:: <T >(
292
293
n,
293
294
T :: MaxNominatorRewardedPerValidator :: get( ) as u32 ,
@@ -321,8 +322,6 @@ benchmarks! {
321
322
322
323
payout_stakers_alive_staked {
323
324
let n in 1 .. T :: MaxNominatorRewardedPerValidator :: get( ) as u32 ;
324
- // Clean up existing validators
325
- Validators :: <T >:: remove_all( ) ;
326
325
let ( validator, nominators) = create_validator_with_nominators:: <T >(
327
326
n,
328
327
T :: MaxNominatorRewardedPerValidator :: get( ) as u32 ,
@@ -708,7 +707,7 @@ mod tests {
708
707
709
708
#[ test]
710
709
fn create_validators_with_nominators_for_era_works ( ) {
711
- ExtBuilder :: default ( ) . has_stakers ( false ) . build ( ) . execute_with ( || {
710
+ ExtBuilder :: default ( ) . has_stakers ( true ) . build ( ) . execute_with ( || {
712
711
let v = 10 ;
713
712
let n = 100 ;
714
713
@@ -725,7 +724,7 @@ mod tests {
725
724
726
725
#[ test]
727
726
fn create_validator_with_nominators_works ( ) {
728
- ExtBuilder :: default ( ) . has_stakers ( false ) . build ( ) . execute_with ( || {
727
+ ExtBuilder :: default ( ) . has_stakers ( true ) . build ( ) . execute_with ( || {
729
728
let n = 10 ;
730
729
731
730
let ( validator_stash, nominators) = create_validator_with_nominators :: < Test > (
@@ -749,7 +748,7 @@ mod tests {
749
748
750
749
#[ test]
751
750
fn add_slashing_spans_works ( ) {
752
- ExtBuilder :: default ( ) . has_stakers ( false ) . build ( ) . execute_with ( || {
751
+ ExtBuilder :: default ( ) . has_stakers ( true ) . build ( ) . execute_with ( || {
753
752
let n = 10 ;
754
753
755
754
let ( validator_stash, _nominators) = create_validator_with_nominators :: < Test > (
@@ -780,7 +779,7 @@ mod tests {
780
779
781
780
#[ test]
782
781
fn test_payout_all ( ) {
783
- ExtBuilder :: default ( ) . has_stakers ( false ) . build ( ) . execute_with ( || {
782
+ ExtBuilder :: default ( ) . has_stakers ( true ) . build ( ) . execute_with ( || {
784
783
let v = 10 ;
785
784
let n = 100 ;
786
785
@@ -799,7 +798,7 @@ mod tests {
799
798
800
799
#[ test]
801
800
fn test_benchmarks ( ) {
802
- ExtBuilder :: default ( ) . has_stakers ( false ) . build ( ) . execute_with ( || {
801
+ ExtBuilder :: default ( ) . has_stakers ( true ) . build ( ) . execute_with ( || {
803
802
assert_ok ! ( test_benchmark_bond:: <Test >( ) ) ;
804
803
assert_ok ! ( test_benchmark_bond_extra:: <Test >( ) ) ;
805
804
assert_ok ! ( test_benchmark_unbond:: <Test >( ) ) ;
0 commit comments