Newer
Older
// // If 10 gets slashed now, despite having +1000 in stash, it will be slashed byt 79, which is the slot stake
Staking::on_offline_validator(10, 4);
// // Confirm user has been reported
assert_eq!(Staking::slash_count(&10), 4);
// // check the balance of 10 (slash will be deducted from free balance.)
assert_eq!(Balances::free_balance(&10), 1000 - 79);
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
#[test]
fn on_free_balance_zero_stash_removes_validator() {
// Tests that validator storage items are cleaned up when stash is empty
// Tests that storage items are untouched when controller is empty
with_externalities(&mut ExtBuilder::default()
.existential_deposit(10)
.build(),
|| {
// Check that account 10 is a validator
assert!(<Validators<Test>>::exists(10));
// Check the balance of the validator account
assert_eq!(Balances::free_balance(&10), 256);
// Check the balance of the stash account
assert_eq!(Balances::free_balance(&11), 256000);
// Check these two accounts are bonded
assert_eq!(Staking::bonded(&11), Some(10));
// Set some storage items which we expect to be cleaned up
// Initiate slash count storage item
Staking::on_offline_validator(10, 1);
// Set payee information
assert_ok!(Staking::set_payee(Origin::signed(10), RewardDestination::Stash));
// Check storage items that should be cleaned up
assert!(<Ledger<Test>>::exists(&10));
assert!(<Validators<Test>>::exists(&10));
assert!(<SlashCount<Test>>::exists(&10));
assert!(<Payee<Test>>::exists(&10));
// Reduce free_balance of controller to 0
Balances::set_free_balance(&10, 0);
// Check total balance of account 10
assert_eq!(Balances::total_balance(&10), 0);
// Check the balance of the stash account has not been touched
assert_eq!(Balances::free_balance(&11), 256000);
// Check these two accounts are still bonded
assert_eq!(Staking::bonded(&11), Some(10));
// Check storage items have not changed
assert!(<Ledger<Test>>::exists(&10));
assert!(<Validators<Test>>::exists(&10));
assert!(<SlashCount<Test>>::exists(&10));
assert!(<Payee<Test>>::exists(&10));
// Reduce free_balance of stash to 0
Balances::set_free_balance(&11, 0);
// Check total balance of stash
assert_eq!(Balances::total_balance(&11), 0);
// Check storage items do not exist
assert!(!<Ledger<Test>>::exists(&10));
assert!(!<Validators<Test>>::exists(&10));
assert!(!<Nominators<Test>>::exists(&10));
assert!(!<SlashCount<Test>>::exists(&10));
assert!(!<Payee<Test>>::exists(&10));
assert!(!<Bonded<Test>>::exists(&11));
});
}
#[test]
fn on_free_balance_zero_stash_removes_nominator() {
// Tests that nominator storage items are cleaned up when stash is empty
// Tests that storage items are untouched when controller is empty
with_externalities(&mut ExtBuilder::default()
.existential_deposit(10)
.build(),
|| {
// Make 10 a nominator
assert_ok!(Staking::nominate(Origin::signed(10), vec![20]));
// Check that account 10 is a nominator
assert!(<Nominators<Test>>::exists(10));
// Check the balance of the nominator account
assert_eq!(Balances::free_balance(&10), 256);
// Check the balance of the stash account
assert_eq!(Balances::free_balance(&11), 256000);
// Check these two accounts are bonded
assert_eq!(Staking::bonded(&11), Some(10));
// Set payee information
assert_ok!(Staking::set_payee(Origin::signed(10), RewardDestination::Stash));
// Check storage items that should be cleaned up
assert!(<Ledger<Test>>::exists(&10));
assert!(<Nominators<Test>>::exists(&10));
assert!(<Payee<Test>>::exists(&10));
// Reduce free_balance of controller to 0
Balances::set_free_balance(&10, 0);
// Check total balance of account 10
assert_eq!(Balances::total_balance(&10), 0);
// Check the balance of the stash account has not been touched
assert_eq!(Balances::free_balance(&11), 256000);
// Check these two accounts are still bonded
assert_eq!(Staking::bonded(&11), Some(10));
// Check storage items have not changed
assert!(<Ledger<Test>>::exists(&10));
assert!(<Nominators<Test>>::exists(&10));
assert!(<Payee<Test>>::exists(&10));
// Reduce free_balance of stash to 0
Balances::set_free_balance(&11, 0);
// Check total balance of stash
assert_eq!(Balances::total_balance(&11), 0);
// Check storage items do not exist
assert!(!<Ledger<Test>>::exists(&10));
assert!(!<Validators<Test>>::exists(&10));
assert!(!<Nominators<Test>>::exists(&10));
assert!(!<SlashCount<Test>>::exists(&10));
assert!(!<Payee<Test>>::exists(&10));
assert!(!<Bonded<Test>>::exists(&11));
});
}