@@ -339,24 +339,8 @@ fn setup_bonding(amount_bonded_each_miner: u128, min_bonding_dhx_daily: u128) ->
339339 let pre_image_hash = BlakeTwo256 :: hash ( b"test" ) ;
340340 // params: end block, proposal hash, threshold, delay
341341 let r = Democracy :: inject_referendum ( 1 , pre_image_hash. clone ( ) , VoteThreshold :: SuperMajorityApprove , 2 ) ;
342- // lock the whole balance of account 1, 2, and 3 in voting
343- let v1a1 = AccountVote :: Standard { vote : AYE , balance : Balances :: free_balance ( 1 ) } ;
344- let v1a2 = AccountVote :: Standard { vote : AYE , balance : Balances :: free_balance ( 2 ) } ;
345- let v1a3 = AccountVote :: Standard { vote : AYE , balance : Balances :: free_balance ( 3 ) } ;
346- // vote on referenda using time-lock voting with a conviction to scale the vote power
347- // note: second parameter is the referendum index being voted on
348- assert_ok ! ( Democracy :: vote( Origin :: signed( 1 ) , r, v1a1) ) ;
349- assert_ok ! ( Democracy :: vote( Origin :: signed( 2 ) , r, v1a2) ) ;
350- assert_ok ! ( Democracy :: vote( Origin :: signed( 3 ) , r, v1a3) ) ;
351342
352- // // assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 });
353- assert_eq ! ( Balances :: locks( 1 ) [ 0 ] ,
354- BalanceLock {
355- id: [ 100 , 101 , 109 , 111 , 99 , 114 , 97 , 99 ] ,
356- amount: amount_bonded_each_miner,
357- reasons: Reasons :: Misc
358- }
359- ) ;
343+ bond_each_miner_by_voting_for_referendum ( amount_bonded_each_miner, r) ;
360344
361345 return r;
362346}
@@ -386,6 +370,63 @@ fn setup_treasury_balance() {
386370 assert_eq ! ( Balances :: usable_balance( & Treasury :: account_id( ) ) , INIT_DAO_BALANCE_DHX ) ;
387371}
388372
373+ fn bond_each_miner_by_voting_for_referendum ( amount_bonded_each_miner : u128 , referendum_index : u32 ) {
374+ // we're actually bonding with their entire account balance
375+ let b1 = Balances :: free_balance ( & 1 ) ;
376+ let b2 = Balances :: free_balance ( & 2 ) ;
377+ let b3 = Balances :: free_balance ( & 3 ) ;
378+
379+ // lock the whole balance of account 1, 2, and 3 in voting
380+ let v1a1 = AccountVote :: Standard { vote : AYE , balance : b1. clone ( ) } ;
381+ let v1a2 = AccountVote :: Standard { vote : AYE , balance : b2. clone ( ) } ;
382+ let v1a3 = AccountVote :: Standard { vote : AYE , balance : b3. clone ( ) } ;
383+ // vote on referenda using time-lock voting with a conviction to scale the vote power
384+ // note: second parameter is the referendum index being voted on
385+ assert_ok ! ( Democracy :: vote( Origin :: signed( 1 ) , referendum_index, v1a1) ) ;
386+ assert_ok ! ( Democracy :: vote( Origin :: signed( 2 ) , referendum_index, v1a2) ) ;
387+ assert_ok ! ( Democracy :: vote( Origin :: signed( 3 ) , referendum_index, v1a3) ) ;
388+
389+ assert_eq ! ( Balances :: locks( 1 ) [ 0 ] ,
390+ BalanceLock {
391+ id: [ 100 , 101 , 109 , 111 , 99 , 114 , 97 , 99 ] ,
392+ amount: b1. clone( ) ,
393+ reasons: Reasons :: Misc
394+ }
395+ ) ;
396+ assert_eq ! ( Balances :: locks( 2 ) [ 0 ] ,
397+ BalanceLock {
398+ id: [ 100 , 101 , 109 , 111 , 99 , 114 , 97 , 99 ] ,
399+ amount: b2. clone( ) ,
400+ reasons: Reasons :: Misc
401+ }
402+ ) ;
403+ assert_eq ! ( Balances :: locks( 3 ) [ 0 ] ,
404+ BalanceLock {
405+ id: [ 100 , 101 , 109 , 111 , 99 , 114 , 97 , 99 ] ,
406+ amount: b3. clone( ) ,
407+ reasons: Reasons :: Misc
408+ }
409+ ) ;
410+ }
411+
412+ fn unbond_each_miner_by_removing_their_referendum_vote ( referendum_index : u32 ) {
413+ // remove the votes and then unlock for each account
414+ // note: `remove_vote` must be done before `unlock`
415+ assert_ok ! ( Democracy :: remove_vote( Origin :: signed( 1 ) , referendum_index) ) ;
416+ assert_ok ! ( Democracy :: remove_vote( Origin :: signed( 2 ) , referendum_index) ) ;
417+ assert_ok ! ( Democracy :: remove_vote( Origin :: signed( 3 ) , referendum_index) ) ;
418+ // we removed their votes
419+ assert_eq ! ( Democracy :: referendum_status( referendum_index) . unwrap( ) . tally, Tally { ayes: 0 , nays: 0 , turnout: 0 } ) ;
420+ assert_ok ! ( Democracy :: unlock( Origin :: signed( 1 ) , 1 ) ) ;
421+ assert_ok ! ( Democracy :: unlock( Origin :: signed( 2 ) , 2 ) ) ;
422+ assert_ok ! ( Democracy :: unlock( Origin :: signed( 3 ) , 3 ) ) ;
423+
424+ // check that all accounts are unlocked
425+ assert_eq ! ( Balances :: locks( 1 ) , vec![ ] ) ;
426+ assert_eq ! ( Balances :: locks( 2 ) , vec![ ] ) ;
427+ assert_eq ! ( Balances :: locks( 3 ) , vec![ ] ) ;
428+ }
429+
389430fn check_eligible_for_rewards_after_cooling_off_period_if_suffient_bonded ( amount_bonded_each_miner : u128 ) {
390431 // since the timestamp is 0 (corresponds to 1970-01-01) at block number #1, we early exit from on_initialize in
391432 // that block in the implementation and do not set any storage values associated with the date until block #2.
@@ -528,21 +569,7 @@ fn check_ineligible_for_rewards_and_cooling_down_period_starts_if_insufficient_b
528569 // check that the referendum that we created earlier still exists
529570 assert_eq ! ( Democracy :: referendum_count( ) , 1 , "referenda not created" ) ;
530571
531- // remove the votes and then unlock for each account
532- // note: `remove_vote` must be done before `unlock`
533- assert_ok ! ( Democracy :: remove_vote( Origin :: signed( 1 ) , referendum_index) ) ;
534- assert_ok ! ( Democracy :: remove_vote( Origin :: signed( 2 ) , referendum_index) ) ;
535- assert_ok ! ( Democracy :: remove_vote( Origin :: signed( 3 ) , referendum_index) ) ;
536- // we removed their votes
537- assert_eq ! ( Democracy :: referendum_status( referendum_index) . unwrap( ) . tally, Tally { ayes: 0 , nays: 0 , turnout: 0 } ) ;
538- assert_ok ! ( Democracy :: unlock( Origin :: signed( 1 ) , 1 ) ) ;
539- assert_ok ! ( Democracy :: unlock( Origin :: signed( 2 ) , 2 ) ) ;
540- assert_ok ! ( Democracy :: unlock( Origin :: signed( 3 ) , 3 ) ) ;
541-
542- // check that all accounts are unlocked
543- assert_eq ! ( Balances :: locks( 1 ) , vec![ ] ) ;
544- assert_eq ! ( Balances :: locks( 2 ) , vec![ ] ) ;
545- assert_eq ! ( Balances :: locks( 3 ) , vec![ ] ) ;
572+ unbond_each_miner_by_removing_their_referendum_vote ( referendum_index. clone ( ) ) ;
546573
547574 // now wait for the next day when we iterate through the miner accounts and they should have no locks
548575 // 4th Sept 2021 @ ~7am is 1630738800000
@@ -581,4 +608,21 @@ fn check_ineligible_for_rewards_and_cooling_down_period_starts_if_insufficient_b
581608
582609 assert_eq ! ( MiningRewardsAllowanceTestModule :: rewards_allowance_dhx_for_date_remaining( 1630713600000 ) , Some ( FIVE_THOUSAND_DHX ) ) ;
583610 assert_eq ! ( MiningRewardsAllowanceTestModule :: rewards_allowance_dhx_for_date_remaining_distributed( 1630713600000 ) , Some ( false ) ) ;
611+
612+ check_cooling_off_period_starts_again_if_sufficient_bonded_again ( amount_bonded_each_miner. clone ( ) , referendum_index. clone ( ) ) ;
613+ }
614+
615+ fn check_cooling_off_period_starts_again_if_sufficient_bonded_again ( amount_bonded_each_miner : u128 , referendum_index : u32 ) {
616+
617+ bond_each_miner_by_voting_for_referendum ( amount_bonded_each_miner, referendum_index) ;
618+
619+ // now wait for the next day when we iterate through the miner accounts and they should have no locks
620+ // 5th Sept 2021 @ ~7am is 1630825200000
621+ // 5th Sept 2021 @ 12am is 1630800000000 (start of day)
622+ Timestamp :: set_timestamp ( 1630825200000u64 ) ;
623+ MiningRewardsAllowanceTestModule :: on_initialize ( 10 ) ;
624+
625+ // params: start of date, days remaining, bonding status
626+ // note: since they have the min. DHX bonded again their bonding status changes to `1`, which is bonding
627+ assert_eq ! ( MiningRewardsAllowanceTestModule :: cooling_off_period_days_remaining( 1 ) , Some ( ( 1630800000000 , 0 , 1 ) ) ) ;
584628}
0 commit comments