-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
base: master
Are you sure you want to change the base?
Conversation
|
||
#[cfg(test)] | ||
/// Asserts the integrity of the collision manager. | ||
fn assert_integrity(&self, expected_txs: &[ArcPoolTx]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
Co-authored-by: Andrea Cerone <[email protected]>
Co-authored-by: Andrea Cerone <[email protected]>
There was a problem hiding this 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]); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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
Before requesting review