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

Improve TxPool tests and documentation #2327

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Conversation

AurelienFT
Copy link
Contributor

@AurelienFT AurelienFT commented Oct 10, 2024

Linked Issues/PRs

Closes #762

Description

This PR improves the tests to make sure all the structures that stores transactions/caches have the expected state after the execution of a test.

We also added an high level documentation for users and contributors at the root of the pool

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

@AurelienFT AurelienFT changed the title Prepare txpool testing Improve TxPool tests and documentation Oct 10, 2024
@AurelienFT AurelienFT self-assigned this Oct 10, 2024
@AurelienFT AurelienFT marked this pull request as ready for review October 10, 2024 19:28
@AurelienFT AurelienFT requested a review from a team October 11, 2024 13:39

#[cfg(test)]
/// Asserts the integrity of the collision manager.
fn assert_integrity(&self, expected_txs: &[ArcPoolTx]);
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be in the trait?
You are forcing all implementors of a CollisionManager to implement a test-only function to establish its integrity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pool is only defined with generics based on trait and so traits need to implements this for the pool to use it. Personally, I don't find this strange to have trait having test-only methods

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to keep traits only with business logic, if possible. In the case of tests, you always know the actual type. The TxPool can expose collision manager in the case of tests, in this case you can call assert_integrity directly on txpool.collision_manager.assert_integrity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okey I personally find it cool to have test methods on trait also. But ok to change as you prefer.

Copy link
Contributor

@acerone85 acerone85 left a comment

Choose a reason for hiding this comment

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

Some comments, but mostly minor things.
Overall looks good

acerone85
acerone85 previously approved these changes Oct 14, 2024
Copy link
Contributor

@acerone85 acerone85 left a comment

Choose a reason for hiding this comment

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

LGTM


#[cfg(test)]
/// Asserts the integrity of the collision manager.
fn assert_integrity(&self, expected_txs: &[ArcPoolTx]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to keep traits only with business logic, if possible. In the case of tests, you always know the actual type. The TxPool can expose collision manager in the case of tests, in this case you can call assert_integrity directly on txpool.collision_manager.assert_integrity.

#![deny(clippy::arithmetic_side_effects)]
#![deny(clippy::cast_possible_truncation)]
#![deny(unused_crate_dependencies)]
#![deny(warnings)]

// TODO: Rename the folder from `txpool_v2` to `txpool` after the migration is complete.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We still need to rename txpool_v2 to txpool =D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dunno why but in my mind I saw you did it in a PR but it seems it was in my dreams 😆 . Readded

pub fn assert_pool_integrity(&self, expected_txs: &[ArcPoolTx]) {
let pool = self.pool.as_ref().unwrap();
let pool = pool.read();
pool.assert_integrity(expected_txs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is the place were we can call assert_integrity for all internal fields of the TxPool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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.

4 participants