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

use rstest to refactor unit tests #12440

Closed
ftupas opened this issue Nov 10, 2024 · 3 comments
Closed

use rstest to refactor unit tests #12440

ftupas opened this issue Nov 10, 2024 · 3 comments
Labels
C-enhancement New feature or request S-needs-triage This issue needs to be labelled S-stale This issue/PR is stale and will close with no further activity

Comments

@ftupas
Copy link
Contributor

ftupas commented Nov 10, 2024

Describe the feature

In #12379, the rstest framework is used to refactor unit tests.

It would be beneficial to apply this across the codebase for DRY and maintainable code without needing to create helper test utility functions like this.

/// Verifies [`ChainSpec`] configuration against expected data in given cases.
#[cfg(any(test, feature = "test-utils"))]
pub fn test_fork_ids(spec: &ChainSpec, cases: &[(Head, ForkId)]) {
for (block, expected_id) in cases {
let computed_id = spec.fork_id(block);
assert_eq!(
expected_id, &computed_id,
"Expected fork ID {:?}, computed fork ID {:?} at block {}",
expected_id, computed_id, block.number
);
}
}

Moreover, fixtures can be useful to remove boiler plate code

fn test_sync_target_update() {
let client = Arc::new(TestHeadersClient::default());
let genesis = SealedHeader::default();

fn test_head_update() {
let client = Arc::new(TestHeadersClient::default());
let header = SealedHeader::default();

Additional context

No response

@ftupas ftupas added C-enhancement New feature or request S-needs-triage This issue needs to be labelled labels Nov 10, 2024
@ftupas
Copy link
Contributor Author

ftupas commented Nov 10, 2024

@emhane issue created as per #12379 (review)_

Copy link
Contributor

github-actions bot commented Dec 2, 2024

This issue is stale because it has been open for 21 days with no activity.

@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label Dec 2, 2024
Copy link
Contributor

github-actions bot commented Dec 9, 2024

This issue was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Reth Tracker Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request S-needs-triage This issue needs to be labelled S-stale This issue/PR is stale and will close with no further activity
Projects
Archived in project
Development

No branches or pull requests

1 participant