Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Clean Staking <-> Session tests and Use a Realistic Scenario #5244

Closed
kianenigma opened this issue Mar 13, 2020 · 2 comments · Fixed by #7719
Closed

Clean Staking <-> Session tests and Use a Realistic Scenario #5244

kianenigma opened this issue Mar 13, 2020 · 2 comments · Fixed by #7719
Labels
I5-tests Tests need fixing, improving or augmenting. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder

Comments

@kianenigma
Copy link
Contributor

Currently, almost all staking tests use this function

pub fn start_session(session_index: SessionIndex) {
assert_eq!(<Period as Get<BlockNumber>>::get(), 1, "start_session can only be used with session length 1.");
for i in Session::current_index()..session_index {
Staking::on_finalize(System::block_number());
System::set_block_number((i + 1).into());
Timestamp::set_timestamp(System::block_number() * 1000);
Session::on_initialize(System::block_number());
Staking::on_initialize(System::block_number());
}

To which I have added the assertion that demonstrates the issues; Up until this commit, staking's mock didn't even have a configuration to set the session length and it was always 1. The assert should prevent us from creating a bug here, but ideally the assumption should be removed and tests that use it should be revised. There should be tests that check staking's session rotation with session/era lengths of N and M, where both of them are greater than 1.

@kianenigma kianenigma added I5-tests Tests need fixing, improving or augmenting. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder labels Mar 13, 2020
@kianenigma
Copy link
Contributor Author

Also, the first era contains session 0, which has length 0. A test should properly demonstrate this.

@kianenigma
Copy link
Contributor Author

long term i'd really like to see a revamp of staking tests so that:
1- active_era and current_era are actually different.
2- sessions is actually queuing the receiving validators (same as all of our real chains).

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I5-tests Tests need fixing, improving or augmenting. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant