Era change can be forced on and forced off (#3374)

* Forcing can be on or off.

* Add a testcase.
This commit is contained in:
Gavin Wood
2019-08-12 18:14:16 +02:00
committed by GitHub
parent ebba5d1d3c
commit 9afd655d8b
6 changed files with 87 additions and 24 deletions
+39 -2
View File
@@ -108,7 +108,7 @@ fn no_offline_should_work() {
assert_eq!(Staking::slash_count(&10), 0);
assert_eq!(Balances::free_balance(&10), 1);
// New era is not being forced
assert!(!Staking::forcing_new_era());
assert_eq!(Staking::force_era(), Forcing::NotForcing);
});
}
@@ -163,7 +163,7 @@ fn invulnerability_should_work() {
assert!(<Validators<Test>>::exists(&11));
// New era not being forced
// NOTE: new era is always forced once slashing happens -> new validators need to be chosen.
assert!(!Staking::forcing_new_era());
assert_eq!(Staking::force_era(), Forcing::NotForcing);
});
}
@@ -884,6 +884,43 @@ fn session_and_eras_work() {
});
}
#[test]
fn forcing_new_era_works() {
with_externalities(&mut ExtBuilder::default().build(),|| {
// normal flow of session.
assert_eq!(Staking::current_era(), 0);
start_session(0);
assert_eq!(Staking::current_era(), 0);
start_session(1);
assert_eq!(Staking::current_era(), 0);
start_session(2);
assert_eq!(Staking::current_era(), 1);
// no era change.
ForceEra::put(Forcing::ForceNone);
start_session(3);
assert_eq!(Staking::current_era(), 1);
start_session(4);
assert_eq!(Staking::current_era(), 1);
start_session(5);
assert_eq!(Staking::current_era(), 1);
start_session(6);
assert_eq!(Staking::current_era(), 1);
// back to normal
ForceEra::put(Forcing::NotForcing);
start_session(7);
assert_eq!(Staking::current_era(), 1);
start_session(8);
assert_eq!(Staking::current_era(), 2);
// forceful change
ForceEra::put(Forcing::ForceNew);
start_session(9);
assert_eq!(Staking::current_era(), 3);
});
}
#[test]
fn cannot_transfer_staked_balance() {
// Tests that a stash account cannot transfer funds