Newer
Older
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
StakingLedger {
controller: None,
total: (10 + ctlr).into(),
active: (10 + ctlr).into(),
..StakingLedger::default_from(stash)
},
);
Bonded::<Test>::insert(stash, ctlr);
Payee::<Test>::insert(stash, RewardDestination::Staked);
controllers.push(ctlr);
}
// When:
let bounded_controllers: BoundedVec<
_,
<Test as Config>::MaxControllersInDeprecationBatch,
> = BoundedVec::try_from(controllers).unwrap();
// Only `AdminOrigin` can sign.
assert_noop!(
Staking::deprecate_controller_batch(
RuntimeOrigin::signed(2),
bounded_controllers.clone()
),
BadOrigin
);
let result =
Staking::deprecate_controller_batch(RuntimeOrigin::root(), bounded_controllers);
assert_ok!(result);
assert_eq!(
result.unwrap().actual_weight.unwrap(),
<Test as Config>::WeightInfo::deprecate_controller_batch(
<Test as Config>::MaxControllersInDeprecationBatch::get()
)
);
// Then:
for n in start..(start + MaxControllersInDeprecationBatch::get()).into() {
let ctlr: u64 = n.into();
let stash: u64 = (n + 10000).into();
// Ledger no longer keyed by controller.
assert_eq!(Ledger::<Test>::get(ctlr), None);
// Bonded now maps to the stash.
assert_eq!(Bonded::<Test>::get(stash), Some(stash));
// Ledger is now keyed by stash.
let ledger_updated = Ledger::<Test>::get(stash).unwrap();
assert_eq!(ledger_updated.stash, stash);
// Check `active` and `total` values match the original ledger set by controller.
assert_eq!(ledger_updated.active, (10 + ctlr).into());
assert_eq!(ledger_updated.total, (10 + ctlr).into());
}
})
}
#[test]
fn deprecate_controller_batch_works_half_weight() {
ExtBuilder::default().build_and_execute(|| {
// Given:
let start = 1001;
let mut controllers: Vec<_> = vec![];
for n in start..(start + MaxControllersInDeprecationBatch::get()).into() {
let ctlr: u64 = n.into();
// Only half of entries are unique pairs.
let stash: u64 = if n % 2 == 0 { (n + 10000).into() } else { ctlr };
Ledger::<Test>::insert(
ctlr,
StakingLedger { controller: None, ..StakingLedger::default_from(stash) },
);
Bonded::<Test>::insert(stash, ctlr);
Payee::<Test>::insert(stash, RewardDestination::Staked);
controllers.push(ctlr);
}
// When:
let bounded_controllers: BoundedVec<
_,
<Test as Config>::MaxControllersInDeprecationBatch,
> = BoundedVec::try_from(controllers.clone()).unwrap();
let result =
Staking::deprecate_controller_batch(RuntimeOrigin::root(), bounded_controllers);
assert_ok!(result);
assert_eq!(
result.unwrap().actual_weight.unwrap(),
<Test as Config>::WeightInfo::deprecate_controller_batch(controllers.len() as u32)
);
// Then:
for n in start..(start + MaxControllersInDeprecationBatch::get()).into() {
let unique_pair = n % 2 == 0;
let ctlr: u64 = n.into();
let stash: u64 = if unique_pair { (n + 10000).into() } else { ctlr };
// Side effect of migration for unique pair.
if unique_pair {
assert_eq!(Ledger::<Test>::get(ctlr), None);
}
// Bonded maps to the stash.
assert_eq!(Bonded::<Test>::get(stash), Some(stash));
// Ledger is keyed by stash.
let ledger_updated = Ledger::<Test>::get(stash).unwrap();
assert_eq!(ledger_updated.stash, stash);
}
})
}
#[test]
fn deprecate_controller_batch_skips_unmigrated_controller_payees() {
ExtBuilder::default().try_state(false).build_and_execute(|| {
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
// Given:
let stash: u64 = 1000;
let ctlr: u64 = 1001;
Ledger::<Test>::insert(
ctlr,
StakingLedger { controller: None, ..StakingLedger::default_from(stash) },
);
Bonded::<Test>::insert(stash, ctlr);
#[allow(deprecated)]
Payee::<Test>::insert(stash, RewardDestination::Controller);
// When:
let bounded_controllers: BoundedVec<
_,
<Test as Config>::MaxControllersInDeprecationBatch,
> = BoundedVec::try_from(vec![ctlr]).unwrap();
let result =
Staking::deprecate_controller_batch(RuntimeOrigin::root(), bounded_controllers);
assert_ok!(result);
assert_eq!(
result.unwrap().actual_weight.unwrap(),
<Test as Config>::WeightInfo::deprecate_controller_batch(1 as u32)
);
// Then:
// Esure deprecation did not happen.
assert_eq!(Ledger::<Test>::get(ctlr).is_some(), true);
// Bonded still keyed by controller.
assert_eq!(Bonded::<Test>::get(stash), Some(ctlr));
// Ledger is still keyed by controller.
let ledger_updated = Ledger::<Test>::get(ctlr).unwrap();
assert_eq!(ledger_updated.stash, stash);
})
}