Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test pack #3 for Hiring Module #20

Merged
merged 17 commits into from
Jan 23, 2020
Merged

Test pack #3 for Hiring Module #20

merged 17 commits into from
Jan 23, 2020

Conversation

shamil-gadelshin
Copy link
Contributor

@shamil-gadelshin shamil-gadelshin commented Jan 3, 2020

Contains tests for:

  • on_finalize()
  • cancel_opening()
  • fill_opening()

Code was refactored:

  • on_finalize()
  • cancel_opening()
  • fill_opening()

Bug fixes:

  • fill_opening(application counters)
  • on_finalize(review period)

Numerous comments were added.

- move code
- reduce type visibility
- add some comments
- move trait declaration
- fix ‘missing review period’ bug
- add tests for bug fix
- change fixed u64 type to BlockNumber type alias
- add on_finalize_should_deactivate_application_with_review_period_expired_cause() test
- update opening counters after modification
- add comment and #[allow(dead_code)] attribute to test::debug_print
- apply rustfmt
@bedeho bedeho self-requested a review January 8, 2020 20:27
Copy link
Member

@bedeho bedeho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, also on improving documentation.

I left some comments on one issue, please respond and let me know what you think.

} else {
panic!("should be Active")
}
<Module<Test> as OnFinalize<BlockNumber>>::on_finalize(3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be slightly strengthened, so that you actually call with arguments 1...N-1 first, and ensure that nothing happens in those steps, only in step N there is actual processing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this is really opening_fixture.max_review_period_length+1, right? is more clear, rather than what may seem like arbitrary constant.

panic!("should be Active")
}

<Module<Test> as OnFinalize<BlockNumber>>::on_finalize(3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment as in on_finalize_should_deactivate_application_with_review_period_expired_cause.

panic!("planned to be WaitingToBegin")
}

<Module<Test> as OnFinalize<BlockNumber>>::on_finalize(2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment as in on_finalize_should_deactivate_application_with_review_period_expired_cause.

- add on_finanlize() constant description
- add finalization all blocks prior the test
@shamil-gadelshin
Copy link
Contributor Author

Agree with both comments.

Found a Parity recommendation on how to test on_finalize():
https://substrate.dev/docs/en/next/development/module/tests

fn run_to_block(n: u64) {
    while System::block_number() < n {
        ExampleModule::on_finalize(System::block_number());
        System::on_finalize(System::block_number());
        System::set_block_number(System::block_number() + 1);
        System::on_initialize(System::block_number());
        ExampleModule::on_initialize(System::block_number());
    }
}

@bedeho
Copy link
Member

bedeho commented Jan 23, 2020

Excellent work, that was a really nice solution, could you add it to the conventions issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants