#36231 test: add pow tests covering live mutants
https://github.com/bitcoin/bitcoin/pull/36231 · · +67/-0 in 1 files, 4 commits · labels: Tests
Goal
- Add unit tests for proof-of-work and difficulty calculation edge cases found via mutation testing
- Protects consensus and header-sync validation from future regressions
Adds four unit tests to pow_tests.cpp targeting edge cases in proof-of-work calculation and difficulty verification that were identified via mutation testing. The tests cover first-block timestamp selection in GetNextWorkRequired, handling of negative timespans in CalculateNextWorkRequired, target rounding in PermittedDifficultyTransition, and rejection of difficulty changes at non-retarget heights.
Problem: Subtle edge cases in proof-of-work calculation and difficulty verification lacked explicit unit test coverage, leaving consensus and header-sync validation vulnerable to untested regressions.
Category: Validation (#27 of 48)
P3 · test coverage
- P3 because it improves unit test coverage over core consensus and header-sync proof-of-work logic
- Kills live mutants in consensus-critical code to guard against future regressions without fixing active bugs
P3 because it improves test coverage over core consensus and header-sync proof-of-work algorithms. While it does not fix an active bug or block active development, killing live mutants in consensus-critical code like GetNextWorkRequired and PermittedDifficultyTransition protects against subtle future regressions.
Membership: Adds unit tests pinning consensus proof-of-work logic and header-sync difficulty rules in pow.cpp.
Factors: security/stability 1, bug 0, performance 0, user value 0, leverage 1
Reviewability: Ready
- Ready for review: the patch is small, cleanly rebased, and passes CI
The patch is small, cleanly rebased, passes CI, and has already resolved inline reviewer comments.
Author status: active
Resolved concerns:
- brunoerg suggested simplifying the first block time test setup and keeping consensus initialization consistent across tests, which the author incorporated in a rebase.
Agreement: Strong
- Strong support after author addressed setup suggestions in revision (brunoerg)
- No open concerns remain
Strong approval from brunoerg following revision.
brunoerg provided code suggestions that were addressed in the latest push, followed by an explicit ACK.
- brunoerg approved the latest head commit e6975adf58 after suggestions on block timestamp test construction were adopted
Review verdicts (DrahtBot): 1
- ACK: brunoerg
Files
67 lines under test/bench/ci.
- src/test/pow_tests.cpp +67/-0
Card
PR 36231 adds unit tests in pow_tests.cpp to cover four previously untested edge cases in pow.cpp found via mutation testing. The added cases exercise first-block timestamp selection, negative adjustment timespans, target rounding, and difficulty changes outside retarget heights in consensus and header sync. It has an approval from brunoerg after addressing initial feedback and has no external dependencies.