@@ -1633,115 +1633,49 @@ fn reward_to_stake_works() {
16331633}
16341634
16351635#[ test]
1636- fn on_free_balance_zero_stash_removes_validator ( ) {
1637- // Tests that validator storage items are cleaned up when stash is empty
1638- // Tests that storage items are untouched when controller is empty
1636+ fn reap_stash_works ( ) {
16391637 ExtBuilder :: default ( )
16401638 . existential_deposit ( 10 )
16411639 . balance_factor ( 10 )
16421640 . build_and_execute ( || {
1643- // Check the balance of the validator account
1641+ // given
16441642 assert_eq ! ( Balances :: free_balance( 10 ) , 10 ) ;
1645- // Check the balance of the stash account
1646- assert_eq ! ( Balances :: free_balance( 11 ) , 10 * 1000 ) ;
1647- // Check these two accounts are bonded
1648- assert_eq ! ( Staking :: bonded( & 11 ) , Some ( 10 ) ) ;
1649-
1650- // Set payee information
1651- assert_ok ! ( Staking :: set_payee( Origin :: signed( 10 ) , RewardDestination :: Stash ) ) ;
1652-
1653- // Check storage items that should be cleaned up
1654- assert ! ( <Ledger <Test >>:: contains_key( & 10 ) ) ;
1655- assert ! ( <Bonded <Test >>:: contains_key( & 11 ) ) ;
1656- assert ! ( <Validators <Test >>:: contains_key( & 11 ) ) ;
1657- assert ! ( <Payee <Test >>:: contains_key( & 11 ) ) ;
1658-
1659- // Reduce free_balance of controller to 0
1660- let _ = Balances :: slash ( & 10 , Balance :: max_value ( ) ) ;
1661-
1662- // Check the balance of the stash account has not been touched
16631643 assert_eq ! ( Balances :: free_balance( 11 ) , 10 * 1000 ) ;
1664- // Check these two accounts are still bonded
16651644 assert_eq ! ( Staking :: bonded( & 11 ) , Some ( 10 ) ) ;
16661645
1667- // Check storage items have not changed
16681646 assert ! ( <Ledger <Test >>:: contains_key( & 10 ) ) ;
16691647 assert ! ( <Bonded <Test >>:: contains_key( & 11 ) ) ;
16701648 assert ! ( <Validators <Test >>:: contains_key( & 11 ) ) ;
16711649 assert ! ( <Payee <Test >>:: contains_key( & 11 ) ) ;
16721650
1673- // Reduce free_balance of stash to 0
1674- let _ = Balances :: slash ( & 11 , Balance :: max_value ( ) ) ;
1675- // Check total balance of stash
1676- assert_eq ! ( Balances :: total_balance( & 11 ) , 10 ) ;
1677-
1678- // Reap the stash
1679- assert_ok ! ( Staking :: reap_stash( Origin :: none( ) , 11 , 0 ) ) ;
1680-
1681- // Check storage items do not exist
1682- assert ! ( !<Ledger <Test >>:: contains_key( & 10 ) ) ;
1683- assert ! ( !<Bonded <Test >>:: contains_key( & 11 ) ) ;
1684- assert ! ( !<Validators <Test >>:: contains_key( & 11 ) ) ;
1685- assert ! ( !<Nominators <Test >>:: contains_key( & 11 ) ) ;
1686- assert ! ( !<Payee <Test >>:: contains_key( & 11 ) ) ;
1687- } ) ;
1688- }
1689-
1690- #[ test]
1691- fn on_free_balance_zero_stash_removes_nominator ( ) {
1692- // Tests that nominator storage items are cleaned up when stash is empty
1693- // Tests that storage items are untouched when controller is empty
1694- ExtBuilder :: default ( )
1695- . existential_deposit ( 10 )
1696- . balance_factor ( 10 )
1697- . build_and_execute ( || {
1698- // Make 10 a nominator
1699- assert_ok ! ( Staking :: nominate( Origin :: signed( 10 ) , vec![ 20 ] ) ) ;
1700- // Check that account 10 is a nominator
1701- assert ! ( <Nominators <Test >>:: contains_key( 11 ) ) ;
1702- // Check the balance of the nominator account
1703- assert_eq ! ( Balances :: free_balance( 10 ) , 10 ) ;
1704- // Check the balance of the stash account
1705- assert_eq ! ( Balances :: free_balance( 11 ) , 10_000 ) ;
1706-
1707- // Set payee information
1708- assert_ok ! ( Staking :: set_payee( Origin :: signed( 10 ) , RewardDestination :: Stash ) ) ;
1709-
1710- // Check storage items that should be cleaned up
1711- assert ! ( <Ledger <Test >>:: contains_key( & 10 ) ) ;
1712- assert ! ( <Bonded <Test >>:: contains_key( & 11 ) ) ;
1713- assert ! ( <Nominators <Test >>:: contains_key( & 11 ) ) ;
1714- assert ! ( <Payee <Test >>:: contains_key( & 11 ) ) ;
1715-
1716- // Reduce free_balance of controller to 0
1717- let _ = Balances :: slash ( & 10 , Balance :: max_value ( ) ) ;
1718- // Check total balance of account 10
1719- assert_eq ! ( Balances :: total_balance( & 10 ) , 0 ) ;
1720-
1721- // Check the balance of the stash account has not been touched
1722- assert_eq ! ( Balances :: free_balance( 11 ) , 10_000 ) ;
1723- // Check these two accounts are still bonded
1724- assert_eq ! ( Staking :: bonded( & 11 ) , Some ( 10 ) ) ;
1725-
1726- // Check storage items have not changed
1727- assert ! ( <Ledger <Test >>:: contains_key( & 10 ) ) ;
1728- assert ! ( <Bonded <Test >>:: contains_key( & 11 ) ) ;
1729- assert ! ( <Nominators <Test >>:: contains_key( & 11 ) ) ;
1730- assert ! ( <Payee <Test >>:: contains_key( & 11 ) ) ;
1651+ // stash is not reapable
1652+ assert_noop ! (
1653+ Staking :: reap_stash( Origin :: signed( 20 ) , 11 , 0 ) ,
1654+ Error :: <Test >:: FundedTarget
1655+ ) ;
1656+ // controller or any other account is not reapable
1657+ assert_noop ! ( Staking :: reap_stash( Origin :: signed( 20 ) , 10 , 0 ) , Error :: <Test >:: NotStash ) ;
17311658
1732- // Reduce free_balance of stash to 0
1733- let _ = Balances :: slash ( & 11 , Balance :: max_value ( ) ) ;
1734- // Check total balance of stash
1735- assert_eq ! ( Balances :: total_balance( & 11 ) , 10 ) ;
1659+ // no easy way to cause an account to go below ED, we tweak their staking ledger
1660+ // instead.
1661+ Ledger :: < Test > :: insert (
1662+ 10 ,
1663+ StakingLedger {
1664+ stash : 11 ,
1665+ total : 5 ,
1666+ active : 5 ,
1667+ unlocking : vec ! [ ] ,
1668+ claimed_rewards : vec ! [ ] ,
1669+ } ,
1670+ ) ;
17361671
1737- // Reap the stash
1738- assert_ok ! ( Staking :: reap_stash( Origin :: none ( ) , 11 , 0 ) ) ;
1672+ // reap-able
1673+ assert_ok ! ( Staking :: reap_stash( Origin :: signed ( 20 ) , 11 , 0 ) ) ;
17391674
1740- // Check storage items do not exist
1675+ // then
17411676 assert ! ( !<Ledger <Test >>:: contains_key( & 10 ) ) ;
17421677 assert ! ( !<Bonded <Test >>:: contains_key( & 11 ) ) ;
17431678 assert ! ( !<Validators <Test >>:: contains_key( & 11 ) ) ;
1744- assert ! ( !<Nominators <Test >>:: contains_key( & 11 ) ) ;
17451679 assert ! ( !<Payee <Test >>:: contains_key( & 11 ) ) ;
17461680 } ) ;
17471681}
@@ -2556,10 +2490,10 @@ fn garbage_collection_after_slashing() {
25562490
25572491 // reap_stash respects num_slashing_spans so that weight is accurate
25582492 assert_noop ! (
2559- Staking :: reap_stash( Origin :: none ( ) , 11 , 0 ) ,
2493+ Staking :: reap_stash( Origin :: signed ( 20 ) , 11 , 0 ) ,
25602494 Error :: <Test >:: IncorrectSlashingSpans
25612495 ) ;
2562- assert_ok ! ( Staking :: reap_stash( Origin :: none ( ) , 11 , 2 ) ) ;
2496+ assert_ok ! ( Staking :: reap_stash( Origin :: signed ( 20 ) , 11 , 2 ) ) ;
25632497
25642498 assert ! ( <Staking as crate :: Store >:: SlashingSpans :: get( & 11 ) . is_none( ) ) ;
25652499 assert_eq ! ( <Staking as crate :: Store >:: SpanSlash :: get( & ( 11 , 0 ) ) . amount_slashed( ) , & 0 ) ;
0 commit comments