test: split CreateNewBlock_validity into independent test cases #36852

Open
yuvicc wants to merge 4 commits from test-declarative-miner-basic into master AGit
yuvicc commented 2026-11-13 10:49:53 +00:00 (Migrated from github.com)

CreateNewBlock_validity mines a 110-block chain and then runs four subtests on it as member functions. The subtests share one chain, so each starts from whatever the previous one left behind, and the caller has to patch Tip()->nHeight between them. Inside TestBasicMining a single CMutableTransaction is reused across all sections, with each section overwriting some of its fields, so the transaction a section actually tests depends on every section before it.

This PR removes both kinds of hidden state.

`CreateNewBlock_validity` mines a 110-block chain and then runs four subtests on it as member functions. The subtests share one chain, so each starts from whatever the previous one left behind, and the caller has to patch `Tip()->nHeight` between them. Inside `TestBasicMining` a single `CMutableTransaction` is reused across all sections, with each section overwriting some of its fields, so the transaction a section actually tests depends on every section before it. This PR removes both kinds of hidden state.
DrahtBot commented 2026-11-13 10:50:03 +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.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36525 (mining: add Block interface, fix template data race by Sjors)
  • #36318 (validation: Ensure Invalid ValidationState has result by optout21)
  • #36156 (mining: include chunks that reach block limits by l0rinc)

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/36852 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36852.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36852#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. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36525](https://github.com/bitcoin/bitcoin/pull/36525) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36525.svg"></sub> (mining: add Block interface, fix template data race by Sjors) * [#36318](https://github.com/bitcoin/bitcoin/pull/36318) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36318.svg"></sub> (validation: Ensure Invalid ValidationState has result by optout21) * [#36156](https://github.com/bitcoin/bitcoin/pull/36156) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36156.svg"></sub> (mining: include chunks that reach block limits by l0rinc) 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

🔵 Suggestion · Redundant chain mining remains in CreateNewBlock_validity

After the split, CreateNewBlock_validity still mines the 110-block chain without consuming it, while all four extracted cases already execute the same assertion-bearing helper.

Location: src/test/miner_tests.cpp:981 (head).

🔵 Suggestion · basic_mining still inherits parent IDs and entry metadata between sections

Although behavior matches base, the declarative transactions still depend on a repeatedly overwritten hash and persistent entry-helper settings, leaving some test inputs implicit.

Location: src/test/miner_tests.cpp:595 (head).

Review coverage was incomplete.


Reviewed: 13847d55430b · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3705f06c6a27c475c77f2533c4d016ac03c829c839b7b538bba5e4768ccf54f1:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:079437cca7a8e2997a6dcd83ad38350014352544 --> <!-- ralph-head:13847d55430b570cad7f120d34452252053c3b4d --> <!-- ralph-case:dfe999df47b32d3b515ca2970f87eb2467a25fed6a51e8fa92bc00b381e7c702 --> **🔵 Suggestion · Redundant chain mining remains in `CreateNewBlock_validity`** After the split, `CreateNewBlock_validity` still mines the 110-block chain without consuming it, while all four extracted cases already execute the same assertion-bearing helper. Location: [`src/test/miner_tests.cpp:981`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/13847d55430b570cad7f120d34452252053c3b4d/src/test/miner_tests.cpp#L981>) (head). **🔵 Suggestion · `basic_mining` still inherits parent IDs and entry metadata between sections** Although behavior matches base, the declarative transactions still depend on a repeatedly overwritten `hash` and persistent entry-helper settings, leaving some test inputs implicit. Location: [`src/test/miner_tests.cpp:595`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/13847d55430b570cad7f120d34452252053c3b4d/src/test/miner_tests.cpp#L595>) (head). Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`13847d55430b`](<https://git.fish.foo/bitcoin/bitcoin/commit/13847d55430b570cad7f120d34452252053c3b4d>) · [Review report](<https://review.fish.foo/report/36852-13847d55430b570cad7f120d34452252053c3b4d-2869-2.html>) · [Previous reports](<https://review.fish.foo/traces/36852/>) [permalink](<https://review.fish.foo/report/36852-13847d55430b570cad7f120d34452252053c3b4d-2869-2.html>)
yuvicc commented 2026-11-20 05:27:03 +00:00 (Migrated from github.com)

ralph review:

Separating the mining-loop extraction would let reviewers check the relocation independently before reviewing fresh fixtures and removal of the height adjustments; this is a review-flow improvement, not a final-tree defect.

Split the helper extraction into its own commit (71204c4b34). It's move-only.

Addressed the LLM linter comment: submitSolutionOld7 is now checked with BOOST_CHECK_EXCEPTION(..., HasReason{"Old submitSolution (@7) not supported"}) instead of BOOST_CHECK_THROW.

ralph review: > Separating the mining-loop extraction would let reviewers check the relocation independently before reviewing fresh fixtures and removal of the height adjustments; this is a review-flow improvement, not a final-tree defect. Split the helper extraction into its own commit (71204c4b348c6d34df0999239f89e7d8f482a305). It's move-only. Addressed the LLM linter comment: `submitSolutionOld7` is now checked with `BOOST_CHECK_EXCEPTION(..., HasReason{"Old submitSolution (@7) not supported"}`) instead of `BOOST_CHECK_THROW`.
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!36852
No description provided.