Skip to content

Commit

Permalink
handle errs in staking
Browse files Browse the repository at this point in the history
  • Loading branch information
sekisamu committed Jul 24, 2019
1 parent 7c4e258 commit 47c627c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 0 additions & 2 deletions srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ decl_storage! {

if let (_, Some(validators)) = <Module<T>>::select_validators() {
<session::Validators<T>>::put(&validators);
// initialize current_elected
<CurrentElected<T>>::put(&validators);
}
});
});
Expand Down
15 changes: 13 additions & 2 deletions srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Default for ExtBuilder {
reward: 10,
validator_pool: false,
nominate: true,
validator_count: 2,
validator_count: 3,
minimum_validator_count: 0,
fair: true
}
Expand Down Expand Up @@ -249,7 +249,17 @@ impl ExtBuilder {
vesting: vec![],
}.assimilate_storage(&mut t, &mut c);
let _ = kton::GenesisConfig::<Test> {
balances : vec![],
ring_balances : vec![
(1, 10 * balance_factor, 12),
(2, 20 * balance_factor, 12),
(3, 300 * balance_factor, 12),
(4, 400 * balance_factor, 12),
// for initial validator set
(10, balance_factor, 12),
(11, balance_factor * 1000, 12),
(20, balance_factor, 12),
(21, balance_factor * 2000, 12),
],
vesting: vec![],
sys_acc: 42,
}.assimilate_storage(&mut t, &mut c);
Expand All @@ -265,6 +275,7 @@ impl ExtBuilder {
current_era: self.current_era,
current_era_total_reward: 1_600_000_000 * COIN / ErasPerEpoch::get() as u64,
stakers: vec![
(2, 1, 1 * COIN, StakerStatus::<AccountId>::Validator),
(11, 10, balance_factor * 1000, StakerStatus::<AccountId>::Validator),
(21, 20, stake_21, StakerStatus::<AccountId>::Validator),
(31, 30, stake_31, StakerStatus::<AccountId>::Validator),
Expand Down
7 changes: 5 additions & 2 deletions srml/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ fn test_env_build() {

System::set_block_number(1);
Session::on_initialize(System::block_number());
assert_eq!(Session::validators(), vec![10, 20]);
assert_eq!(Staking::current_elected(), vec![10, 20]);
// initial build storage should work
// controller in session.validators
assert_eq!(Session::validators(), vec![10, 1, 20]);
// stash in staking.current_elected
assert_eq!(Staking::current_elected(), vec![11, 2, 21]);
});
}

0 comments on commit 47c627c

Please sign in to comment.