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

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

@kianenigma

Description

@kianenigma

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I5-testsTests need fixing, improving or augmenting.Z1-easyCan be fixed primarily by duplicating and adapting code by an intermediate coder

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions