test: Replace hardcoded extended keys with ExtendedKey helpers #36710

Open
nebula-21 wants to merge 1 commit from replace-hardcoded-keys into master AGit
nebula-21 commented 2026-10-30 15:35:19 +00:00 (Migrated from github.com)

This PR is a follow-up of PR #35543.
I've updated the tests that were still using hardcoded keys, and used the ExtendedKey classes instead.

This PR is a follow-up of [PR #35543](https://github.com/bitcoin/bitcoin/pull/35543). I've updated the tests that were still using hardcoded keys, and used the `ExtendedKey` classes instead.
DrahtBot commented 2026-10-30 15:35:28 +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

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)
  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36005 (rpc, descriptor: warn when multipath expansion clones single-path key expressions by pythcoiner)
  • #32468 (rpc: generateblock to allow multiple outputs with custom payouts by polespinasa)

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.

<!--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/36710 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36710.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36710#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/36710#pullrequestreview-6166731727) | 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) * [#36885](https://github.com/bitcoin/bitcoin/pull/36885) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36885.svg"></sub> (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc) * [#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) * [#32468](https://github.com/bitcoin/bitcoin/pull/32468) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32468.svg"></sub> (rpc: generateblock to allow multiple outputs with custom payouts by polespinasa) 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-->
First-time contributor

No findings were published from this review.

Review coverage was incomplete.


Reviewed: 25dec17ff487 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:e1a29e5e677c47d383756f0fcf8f3760725c91d1104dd3ccb2f333b6217eba26:47880f5569fd2047d249266f337c4f2a509adf7d96c3ccb1c7644c2c2a650bff --> <!-- ralph-base:0bc1e88dd332476e143eaee3c74911f4ce91f0a1 --> <!-- ralph-head:25dec17ff4877f2606d15922df3319d83f471c8a --> <!-- ralph-case:3666b2ea594651735de699cb66fc8a50a2c5493ebc7ffc5154382b49155faf9d --> No findings were published from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`25dec17ff487`](<https://git.fish.foo/bitcoin/bitcoin/commit/25dec17ff4877f2606d15922df3319d83f471c8a>) · [Review report](<https://review.fish.foo/report/36710-25dec17ff4877f2606d15922df3319d83f471c8a-3465-5.html>) · [Previous reports](<https://review.fish.foo/traces/36710/>) [permalink](<https://review.fish.foo/report/36710-25dec17ff4877f2606d15922df3319d83f471c8a-3465-5.html>)
DrahtBot commented 2026-10-31 03:40:01 +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).
polespinasa (Migrated from github.com) reviewed 2026-11-04 18:15:48 +00:00
polespinasa (Migrated from github.com) left a comment

cACK

cACK
polespinasa (Migrated from github.com) commented 2026-11-04 18:15:37 +00:00

in f805f095fd test: Replace hardcoded extended keys with ExtendedKey helpers

If I am not wrong this can cause some problems when running the test framework with --randomseed=. As same seed could produce different results, making errors non reproducible. This is because the seed is not applied into the rng before you call a function.

A solution to this would be to not use an rng for this test and hardcode some value.
For example:

$ git diff
diff --git a/test/functional/wallet_miniscript.py b/test/functional/wallet_miniscript.py
index 6daf21b9b3..a6d9cb6843 100755
--- a/test/functional/wallet_miniscript.py
+++ b/test/functional/wallet_miniscript.py
@@ -10,9 +10,8 @@ from test_framework.psbt import PSBT, PSBT_IN_SHA256
 from test_framework.test_framework import BitcoinTestFramework
 from test_framework.util import assert_equal
 

-TPRVS = [ExtendedPrivateKey.generate().to_string() for _ in range(0, 3)]
-TPUBS = [ExtendedPrivateKey.generate().pubkey().to_string() for _ in range(0, 7)]
+TPRVS = [ExtendedPrivateKey.from_seed(f"miniscript-private-{i}".encode()).to_string() for i in range(3)]
+TPUBS = [ExtendedPrivateKey.from_seed(f"miniscript-public-{i}".encode()).pubkey().to_string() for i in range(7)]
 PUBKEYS = [
     "02aebf2d10b040eb936a6f02f44ee82f8b34f5c1ccb20ff3949c2b28206b7c1068",
     "030f64b922aee2fd597f104bc6cb3b670f1ca2c6c49b1071a1a6c010575d94fe5a",

in f805f095fd8c8e2b4b7a46490069b5dfa8751586 test: Replace hardcoded extended keys with ExtendedKey helpers If I am not wrong this can cause some problems when running the test framework with `--randomseed=`. As same seed could produce different results, making errors non reproducible. This is because the seed is not applied into the rng before you call a function. A solution to this would be to not use an rng for this test and hardcode some value. For example: ```diff $ git diff diff --git a/test/functional/wallet_miniscript.py b/test/functional/wallet_miniscript.py index 6daf21b9b3..a6d9cb6843 100755 --- a/test/functional/wallet_miniscript.py +++ b/test/functional/wallet_miniscript.py @@ -10,9 +10,8 @@ from test_framework.psbt import PSBT, PSBT_IN_SHA256 from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal -TPRVS = [ExtendedPrivateKey.generate().to_string() for _ in range(0, 3)] -TPUBS = [ExtendedPrivateKey.generate().pubkey().to_string() for _ in range(0, 7)] +TPRVS = [ExtendedPrivateKey.from_seed(f"miniscript-private-{i}".encode()).to_string() for i in range(3)] +TPUBS = [ExtendedPrivateKey.from_seed(f"miniscript-public-{i}".encode()).pubkey().to_string() for i in range(7)] PUBKEYS = [ "02aebf2d10b040eb936a6f02f44ee82f8b34f5c1ccb20ff3949c2b28206b7c1068", "030f64b922aee2fd597f104bc6cb3b670f1ca2c6c49b1071a1a6c010575d94fe5a", ```
nebula-21 commented 2026-11-13 17:08:38 +00:00 (Migrated from github.com)

@polespinasa took you suggestion, I was also thinking about generating the keys inside run_test() instead so the seed would cover them, but that would require a bigger restructuring and maybe not worth it.

@polespinasa took you suggestion, I was also thinking about generating the keys inside `run_test()` instead so the seed would cover them, but that would require a bigger restructuring and maybe not worth it.
polespinasa (Migrated from github.com) reviewed 2026-11-25 20:18:17 +00:00
polespinasa (Migrated from github.com) left a comment
ACK 174adf559d8f1852c9362bcbecb0f16c45b2496a
polespinasa (Migrated from github.com) commented 2026-11-25 20:17:54 +00:00
nit: this import should go in multiple lines. See https://github.com/bitcoin/bitcoin/tree/master/test/functional#style-guidelines
nebula-21 (Migrated from github.com) reviewed 2026-12-03 08:29:46 +00:00
nebula-21 (Migrated from github.com) commented 2026-12-03 08:29:46 +00:00

done

done
polespinasa (Migrated from github.com) reviewed 2026-12-03 09:13:13 +00:00
polespinasa (Migrated from github.com) left a comment
ACK 25dec17ff4877f2606d15922df3319d83f471c8a
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!36710
No description provided.