-
Notifications
You must be signed in to change notification settings - Fork 311
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: Move transaction testing utilities from crates/chain/tests/common
to testenv
crate
#1612
Conversation
Hey @tvpeter thank you for taking this on! Please follow the [https://www.conventionalcommits.org/en/v1.0.0/](Conventional Commit Specification) for the commit messages. I'll review this properly soon! |
e26be1e
to
b571fb0
Compare
@evanlinjin thank you. |
crates/testenv/Cargo.toml
Outdated
@@ -18,6 +18,7 @@ workspace = true | |||
[dependencies] | |||
bdk_chain = { path = "../chain", version = "0.19.0", default-features = false } | |||
electrsd = { version = "0.28.0", features = [ "bitcoind_25_0", "esplora_a33e97e1", "legacy" ] } | |||
bitcoin = { version = "0.32.0", default-features = false } |
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.
Hello! Since bdk_chain
already re-exports bitcoin
, we don't need to add bitcoin
as a dependency here.
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.
Fixed. Thank you
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.
Concept ACK
I only wonder about naming/structure, maybe reword it to only utils.rs
or have both chain_utils.rs
and tx_utils.rs
, but I'm not sure about it.
Alright @oleonardolima. I initially thought that it will contain transaction related utilities only but on a second thought most of the utilities are not just for transactions. So I will rename it to just |
07d931f
to
fefd376
Compare
Please use the conventional commits format for commit messages. Looking at this now, maybe we should create a |
Another option that comes to mind is to have conditional compilation of testenv with something like a "full" feature flag, but I don't have a strong opinion on it at the moment. |
I think conditional compilation sounds like the better option here vs. having an additional crate to manage, since both crates would be primarily focused on testing. |
Edit: As discussed on dev call the current direction on the PR makes sense |
Nit: I think squashing the commits down to one would make the history a bit cleaner. |
fefd376
to
78d078a
Compare
Done |
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 did another review and left some comments. Overall, it's looking good!
I think you still need to change the commit message to lowercase.
@@ -9,6 +9,7 @@ use bdk_chain::{ | |||
}, | |||
BlockId, | |||
}; | |||
use bdk_testenv::{chain_update, h, local_chain}; |
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.
As we are importing this now from bdk_testenv, and deleted the macros from commond/mod.rs
I guess we can remove the code at L16-17.
#[macro_use]
mod common;
crates/testenv/src/utils.rs
Outdated
#[allow(unused_macros)] | ||
#[macro_export] | ||
macro_rules! h { | ||
($index:literal) => {{ | ||
bitcoin::hashes::Hash::hash($index.as_bytes()) | ||
}}; | ||
} |
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.
IIRC we discussed during the call that this could have a meaningful name, I would use hash
for instance.
You also probably need to rebase on top of the master, so the CI issues are fixed (in case you are curious, check: #1636). |
78d078a
to
e140f25
Compare
Done. Thank you |
crates/testenv/src/utils.rs
Outdated
macro_rules! local_chain { | ||
[ $(($height:expr, $block_hash:expr)), * ] => {{ | ||
#[allow(unused_mut)] | ||
bdk_chain::local_chain::LocalChain::from_blocks([$(($height, $block_hash).into()),*].into_iter().collect()) | ||
.expect("chain must have genesis block") | ||
}}; | ||
} |
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: I suggest renaming this expression to hash
for consistency with the other macros.
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.
The previous h!
macro has been renamed to hash!
, so it will conflict. Since it builds a LocalChain
, is it better to rename it new_local_chain
?
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.
Oops! Just to clarify: I meant to change block_hash
to hash
, not rename the local_chain
macro. Apologies for the confusion!
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
- add `utils` mod to testenv crate to keep all utilities moved from `crates/chain/test/common` - replace all test tx macros in `chain` crate with import from `testenv` crate - tests/test_indexed_tx_graph - tests/test_keychain_txout_index - tests/test_local_chain - tests/test_tx_graph - tests/test_tx_graph_conflicts - deleted all moved macros and functions in `crates/chain/test/common/mod` - replace `bitcoin` external crate with `bd_chain::bitcoin` - move `DESCRIPTORS` sample array to `utils` for other crates to use - rename h! macro to hash! for clarity - rename localchain! macro parameter from 'block_hash' to 'hash' [Ticket: bitcoindevkit#1602]
e140f25
to
88a8403
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.
ACK 88a8403
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.
ACK 88a8403
Thanks for taking this one on.
Description
This change moves all transaction testing utilities (macros and functions) from
crates/chain/tests/common
tocrates/testenv/tx_utils
to minimize duplication.Closes #1602
Notes to the reviewers
Changelog notice
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
Bugfixes: