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. |
| [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.
Hello! Since bdk_chain already re-exports bitcoin, we don't need to add bitcoin as a dependency here.
oleonardolima
left a comment
There was a problem hiding this comment.
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 |
oleonardolima
left a comment
There was a problem hiding this comment.
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.
| }, | ||
| BlockId, | ||
| }; | ||
| use bdk_testenv::{chain_update, h, local_chain}; |
There was a problem hiding this comment.
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;| #[allow(unused_macros)] | ||
| #[macro_export] | ||
| macro_rules! h { | ||
| ($index:literal) => {{ | ||
| bitcoin::hashes::Hash::hash($index.as_bytes()) | ||
| }}; | ||
| } |
There was a problem hiding this comment.
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 |
| 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.
Nit: I suggest renaming this expression to hash for consistency with the other macros.
There was a problem hiding this comment.
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.
Oops! Just to clarify: I meant to change block_hash to hash, not rename the local_chain macro. Apologies for the confusion!
- 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
notmandatory
left a comment
There was a problem hiding this comment.
ACK 88a8403
Thanks for taking this one on.
Description
This change moves all transaction testing utilities (macros and functions) from
crates/chain/tests/commontocrates/testenv/tx_utilsto minimize duplication.Closes #1602
Notes to the reviewers
Changelog notice
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features:
Bugfixes: