refactor: wallet_importdescriptors to separate run_test() contents into specific functions #36402

Open
nebula-21 wants to merge 1 commit from refactor-wallet-importdescriptors-test into master AGit
nebula-21 commented 2026-10-01 17:12:40 +00:00 (Migrated from github.com)

The motivation behind this PR came when reviewing a PR related with wallet_importdescriptors and I noticed that the run_test() function was more than 800 lines of code long, and looked messy and confusing, specially for someone not familiar with that test suite.
I believe refactoring the contents inside run_test() and separating it into specific functions would make the test easier to understand and to add new future test cases.

To review this PR, I recommend using the following command to easily see that the changes are only code movement and function organization:

git show --color-moved=dimmed-zebra

Suggestions about the new functions, organization, or their order are more than welcome. The approach I took is the one I felt would provide a good balance between keeping the code clean and making the changes as easy as possible to review.

If reviewers would prefer to split this into multiple commits, I'm also happy to do so.

The motivation behind this PR came when reviewing a PR related with `wallet_importdescriptors` and I noticed that the `run_test()` function was more than 800 lines of code long, and looked messy and confusing, specially for someone not familiar with that test suite. I believe refactoring the contents inside `run_test()` and separating it into specific functions would make the test easier to understand and to add new future test cases. To review this PR, I recommend using the following command to easily see that the changes are only code movement and function organization: ``` git show --color-moved=dimmed-zebra ``` Suggestions about the new functions, organization, or their order are more than welcome. The approach I took is the one I felt would provide a good balance between keeping the code clean and making the changes as easy as possible to review. If reviewers would prefer to split this into multiple commits, I'm also happy to do so.
DrahtBot commented 2026-10-01 17:12:48 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK polespinasa
Concept ACK achow101

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36648 (descriptor, rpc, wallet: do not echo key material in error messages by fametrano)
  • #36257 (qa: assert_equal -> assert_true/assert_false by hodlinator)
  • #36005 (rpc, descriptor: warn when multipath expansion clones single-path key expressions by pythcoiner)
  • #31668 (Added rescan option for import descriptors by saikiran57)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • test/functional/wallet_importdescriptors.py: we can use import and use multisig → we can import and use multisig [the original phrasing is grammatically broken]

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • test/functional/wallet_importdescriptors.py: multi_priv_big.sendtoaddress(w0.getnewaddress(), 10, "", "", True)

2026-11-06 20:28:24

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36402 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36402.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36402#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [polespinasa](https://github.com/bitcoin/bitcoin/pull/36402#pullrequestreview-5826029933) | | Concept ACK | [achow101](https://github.com/bitcoin/bitcoin/pull/36402#issuecomment-6641857671) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36990](https://github.com/bitcoin/bitcoin/pull/36990) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36990.svg"></sub> (test: replace hard-coded RPC error codes by l0rinc) * [#36648](https://github.com/bitcoin/bitcoin/pull/36648) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36648.svg"></sub> (descriptor, rpc, wallet: do not echo key material in error messages by fametrano) * [#36257](https://github.com/bitcoin/bitcoin/pull/36257) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equal -> assert_true/assert_false by hodlinator) * [#36005](https://github.com/bitcoin/bitcoin/pull/36005) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36005.svg"></sub> (rpc, descriptor: warn when multipath expansion clones single-path key expressions by pythcoiner) * [#31668](https://github.com/bitcoin/bitcoin/pull/31668) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31668.svg"></sub> (Added rescan option for import descriptors by saikiran57) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible typos and grammar issues: - `test/functional/wallet_importdescriptors.py`: `we can use import and use multisig` → `we can import and use multisig` [the original phrasing is grammatically broken] Possible places where named args for integral literals may be used (e.g. `func(x, /*named_arg=*/0)` in C++, and `func(x, named_arg=0)` in Python): - `test/functional/wallet_importdescriptors.py`: `multi_priv_big.sendtoaddress(w0.getnewaddress(), 10, "", "", True)` <sup>2026-11-06 20:28:24</sup>
First-time contributor

🔵 Suggestion · Split the remaining multisig test into focused helpers

test_multisig_descriptors (head lines 489-749, about 260 lines) still bundles private/watch-only multisig, distributed-key signing, large P2WSH/P2SH multisig and amendment. Finding or extending one scenario means reading the whole helper. Base run_test grouped these the same way, inline.

Location: test/functional/wallet_importdescriptors.py:489 (head).

Review coverage was incomplete.


Reviewed: 1dbe6869cece · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:055d1cd96b176486294e0a3d052a7e506a00c1f0c7c35fbf579b09cfe6d615cd:adfdaf6241fe97209d62717f4b34912a3f3c05551d5eb04e28ec078dd3f7e4f2 --> <!-- ralph-base:5bf3bc5e263407a252c14a17afe04fc3bf24a889 --> <!-- ralph-head:1dbe6869cece7b839e88769b4209a3679c7bde93 --> <!-- ralph-case:6e78c77383df461c7d8fda416b7a8b3d1659f2f6f46444e9dbb6b6e5f06658c1 --> **🔵 Suggestion · Split the remaining multisig test into focused helpers** `test_multisig_descriptors` (head lines 489-749, about 260 lines) still bundles private/watch-only multisig, distributed-key signing, large P2WSH/P2SH multisig and amendment. Finding or extending one scenario means reading the whole helper. Base `run_test` grouped these the same way, inline. Location: [`test/functional/wallet_importdescriptors.py:489`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/1dbe6869cece7b839e88769b4209a3679c7bde93/test/functional/wallet_importdescriptors.py#L489>) (head). Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`1dbe6869cece`](<https://git.fish.foo/bitcoin/bitcoin/commit/1dbe6869cece7b839e88769b4209a3679c7bde93>) · [Full review report](<https://review.fish.foo/traces/36402-1dbe6869cece7b839e88769b4209a3679c7bde93-2341-7.html>) · [Previous reports](<https://review.fish.foo/traces/36402/>) [permalink](<https://review.fish.foo/traces/36402-1dbe6869cece7b839e88769b4209a3679c7bde93-2341-7.html>)
w0xlt (Migrated from github.com) reviewed 2026-10-01 18:26:28 +00:00
w0xlt (Migrated from github.com) left a comment

Approach aCK

Approach aCK
polespinasa commented 2026-10-05 20:53:06 +00:00 (Migrated from github.com)

Concept ACK

There are some unnecessary new lines added and removed that add noise to the color-dimmed filter :)

Concept ACK There are some unnecessary new lines added and removed that add noise to the color-dimmed filter :)
nebula-21 commented 2026-10-08 15:19:27 +00:00 (Migrated from github.com)

Concept ACK

There are some unnecessary new lines added and removed that add noise to the color-dimmed filter :)

I've tried to avoid them as much as possible, but some of them are necessary to re-arrange into new functions keeping the separations of the original tests intact.

> Concept ACK > > There are some unnecessary new lines added and removed that add noise to the color-dimmed filter :) I've tried to avoid them as much as possible, but some of them are necessary to re-arrange into new functions keeping the separations of the original tests intact.
DrahtBot commented 2026-10-09 01:23:42 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
nebula-21 commented 2026-10-09 12:25:32 +00:00 (Migrated from github.com)

Rebased on master

Rebased on master
polespinasa (Migrated from github.com) reviewed 2026-11-02 18:38:13 +00:00
polespinasa (Migrated from github.com) left a comment

I think this looks pretty good

I think this looks pretty good
polespinasa (Migrated from github.com) commented 2026-11-02 18:30:21 +00:00

this does not only test combo descriptors, maybe should drop combo from the function name?

this does not only test combo descriptors, maybe should drop combo from the function name?
nebula-21 (Migrated from github.com) reviewed 2026-11-03 12:11:55 +00:00
nebula-21 (Migrated from github.com) commented 2026-11-03 12:11:55 +00:00

agree, changed!

agree, changed!
achow101 commented 2026-11-04 20:54:10 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
nebula-21 commented 2026-11-06 20:30:57 +00:00 (Migrated from github.com)

1dbe6869ce addressed ralph's suggestion for test_next_index (line 938) to issue indices 0-4 from a different origin descriptor over the same xpub, to still test returning already handed-out scripts as it did before the refactor

1dbe6869cece7b839e88769b4209a3679c7bde93 addressed ralph's suggestion for `test_next_index` (line 938) to issue indices 0-4 from a different origin descriptor over the same xpub, to still test returning already handed-out scripts as it did before the refactor
polespinasa (Migrated from github.com) reviewed 2026-11-09 12:46:50 +00:00
polespinasa (Migrated from github.com) left a comment
ACK 1dbe6869cece7b839e88769b4209a3679c7bde93
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36402
No description provided.