-
Notifications
You must be signed in to change notification settings - Fork 335
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
Refactor testing logic from macros to pure functions #624
Refactor testing logic from macros to pure functions #624
Conversation
49ef8a8
to
daa5dcd
Compare
093ef9d
to
c2e93c7
Compare
76ccf88
to
8de0e74
Compare
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 just reviewed the first two commits for now, the changes looks good, but I'd avoid saying that the first commit is "move only": you're also changing the logic (see txin
comment), and refactoring populate_test_db into a function.
It might be easier to review if the first commit really was move-only, as we could use --color-moved=dimmed-zebra
, but I understand that it might be a bit of a hassle...
74ef5e3
to
1220c99
Compare
Thanks for the look @danielabrozzoni ..
It didn't made much sense to just do a move and then change logic.. And as I am making it from macro to function, it won't be a pure move anyway even without the logic change.. Might get more confusing than what it is to review.. Reverted the commit message though.. |
#[cfg(test)] | ||
/// Return an mutable reference to the internal database | ||
pub(crate) fn database_mut(&self) -> impl std::ops::DerefMut<Target = D> + '_ { | ||
self.database.borrow_mut() | ||
} | ||
|
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 don't understand exactly why this is necessary
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.
Me neither.. But when I tried to directly use self.database.borrow_mut()
in the function calls the compiler got angry and threw lots of problems that I couldn't subvert, and the easiest thing I found was to have this redundant function.. This does bother me, as we should not need something like this.. But for time being this works.. And I will try to remove it again and see if it can work.. But would prefer to do it in a separate PR..
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.
Another problem faced is previously the populate_test_db
macro was in the database module.. Which made accessing database easy.. But now as it has been taken out into testutils::helper
we cannot just call wallet.db
as that's private variable and only exposed via the database()
api.. Which only gives immutable access.. So thats the major reason I had to make a mutable version of the same API.. But only for testing situations..
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 can make the Wallet::database
field pub(crate)
.
I tried it here: rajarshimaitra#8
5bb51a7
to
9047014
Compare
Hey @afilini I have updated the conftime calculation logic. I think now it is reverted as previous.. And it now expects the min_conf time to be lower than current height with a message. Also changed the blockchain tests to now run with a generic
But the user still needs to manually specify the test cases name in the macro.. I couldn't find a good way to automate that part too.. kept the update commit separate for easier review.. But it might also makes sense to squash them, because many stuffs of the previous commits are now redundant.. |
I am also wondering if we should document it somewhere that our blockchain tests are public and how to use them. Libraries don't usually expose their tests. So might be helpful for users.. |
606340f
to
1a573ee
Compare
1a573ee
to
5b27deb
Compare
Thanks @afilini @danielabrozzoni for the initial look. Pushed some updates
This PR is ready for a second look.. :) |
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, however it's really hard to read through all the changes of blockchain_tests.rs
, but I am trusting that nothing dodgy is added. Also added some comments here and there.
I would love to see this merged soon so we can get started on https://discord.com/channels/753336465005608961/753367451319926827/1012298169830354966 😄
) | ||
]; | ||
|
||
#[cfg(not(feature = "test-rpc-legacy"))] |
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.
Nit: IMO writing this as #[cfg(feature = "test-rpc")]
is better.
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.
Agreed..
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.
On further look, it seems the intention of test-rpc-legacy
is a to be a feature to disable certain tests.. So making it test-rpc
won't work, as all the rpc tests are by default in test-rpc
. This not
thing, makes these tests disabled when test-rpc-legacy
is turned on.. Maybe there was an easier way to do, but I won't mess with it in this PR..
Please don't trust. Verify! 😅 Ya the diff for the blockchain tests is pretty nasty.. Where as its just a single big move of all the tests out of the macro.. But for some reason that's how git is showing.. Let me know if breaking this diff into smaller pieces can help in review.. One thing most important to verify that we are playing all the previous tests.
Thanks for the review @evanlinjin I will update them in the next push.. |
Moving this one to the next milestone, as it seems that there is still some work to do :) |
Sorry I forgot about the last pending updates.. Yes this can wait for the next release.. There are few conflicts too.. I will resolve them after 0.23 is cut.. |
- Few test helpers and macros are scattered around `database/memory.rs` and `wallet/mod.rs`. These are collected in a single place `testutils/helpers.rs`. - the `populate_test_db` macro is changed into a function. Internal logic should remain same. - A new `run_tests_with_init` macro is added in `testutils.helpers.rs`, which can run database tests given an initializer function. Co-authored-by: SanthoshAnguluri <[email protected]> Co-authored-by: saikishore222 <[email protected]>
ff371ae
to
9ac9bcc
Compare
- in `keyvalue.rs`, `memory.rs`, `sqlite.rs` use the `run_tests_with_init` macro to run database tests. - in `wallet/mod.rs` update all the test calls from macro to function for `populate_test_db`. - some import fixes in `address_validator.rs` and `psbt/mod.rs`. Co-authored-by: SanthoshAnguluri <[email protected]> Co-authored-by: saikishore222 <[email protected]>
Similar to the database `run_test_with_init` another `make_blockchain_test` macro is added, which will run the blockchain tests given a initilizer function. These test functions are taken out of the macro and are placed as their own public functions. A doc comment explaining how to use the tests externally from bdk is added before the `blockchain_tests::test` module. Co-authored-by: SanthoshAnguluri <[email protected]> Co-authored-by: saikishore222 <[email protected]>
Apply the new `make_blockchain_test` macro to run the blockchain tests for rpc, electrum and esplora blockchain. Co-authored-by: SanthoshAnguluri <[email protected]> Co-authored-by: saikishore222 <[email protected]>
Co-authored-by: SanthoshAnguluri <[email protected]> Co-authored-by: saikishore222 <[email protected]>
9ac9bcc
to
2e7612d
Compare
Thanks for dealing with the mammoth this long everybody.. I think we are close to get this one in..
This is now ready for a second look.. :) |
Hey, we are in the process of releasing BDK 1.0, which will under the hood work quite differently from the current BDK. For this reason, I'm closing all the PRs that don't really apply anymore. If you think this is a mistake, feel free to rebase on master and re-open! |
Description
This finishes the Summer of Bitcoin Task #481 which aimed at refactoring the bvlockchain tests from macros to functions. This allows easier readability of the test logic using any kind of rust analysis tool and allows easy contribution by new contributors. Thanks to SoB particiapant @saikishore222 and @SanthoshAnguluri for the work.
This PR also refactors the same for database tests and moves the test artifacts into their own
helper
module.Notes to the reviewers
UPDATE: This PR now includes the fix for #719 . The fix is included here for easier review and to reduce duplicate review works. The last two commits includes the bug fix.
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committing