test(verify): cover invalid bits, the mainnet and testnet limits, and the strong threshold
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- blockchain, testing
Research direction
Read tests/test_verify.py, especially _api(...), and inspect the verification checks and Verification grading referenced in the issue. Add offline unittest cases for invalid bits, mainnet and testnet limits, and the strong threshold, using the suggested mocks for difficulty and updated block hashes. Run the test commands in CONTRIBUTING.md; done means the new tests pass and each fails under the code changes described in the acceptance criteria.
Written by the indexing model from the issue text.
Description
What
verify_tx checks the block header's proof of work (verify.py L265-L274) and grades it "strong" or "weak" (L58, L168-L169). Three parts have no test:
- Invalid
bits. A header whosebitsfield encodes a negative or a zero target must fail with aVerificationError.bits_to_targetitself is tested intest_bits; what is missing is a test ofverify_txturning itsValueErrorinto aVerificationError(theexcept ValueErrorbranch). - The mainnet and testnet limits. A target easier than the network allows is rejected; only signet's limit is tested today.
- The strong threshold. Nothing fails if
STRONG_DIFFICULTYis changed (say from50e12to1e12), or if the>=becomes>.
What to do
Add tests to tests/test_verify.py (offline, unittest, like the existing ones):
- Headers whose
bitsencode a negative target (sign bit0x00800000set, with a non-zero mantissa, e.g.0x1d80ffff) and a zero target (e.g.0x1d000000) are rejected with aVerificationError. - A header whose target is above the limit (e.g.
bitsof0x1d01ffff) is rejected with "easier than the network allows" on mainnet and on testnet. - A
Verificationwhose header difficulty is exactlySTRONG_DIFFICULTYis "strong" on mainnet, just below it is "weak", and on testnet it is always "weak".
Acceptance
- The new tests pass, and each fails when the code it covers is changed: the
try/except ValueErroraroundheader.targetremoved; the mainnet or testnet value in_POW_LIMITloosened (e.g. set to signet's);STRONG_DIFFICULTYchanged or>=turned into>. Please say in the PR that you checked this. - No change under
btc_toolkit/.
Hints
_api(...)intests/test_verify.pymocks the API calls with the genesis block; pass your ownheaderandstatus.bitsare bytes 72–75 of the 80-byte header, little-endian. Changing them changes the header hash, so pass the new hash asblock_hashinstatus, or verification stops earlier, at "header hashes to".- The limit is checked before the hash, so these headers need no real proof of work.
- For item 3 you don't need a mined header. No
bitsvalue gives a difficulty of exactly50e12(the closest are0x1705a121, just above, and0x1705a122, just below), so a header built frombitscannot tell>=from>. PatchHeader.difficultyinstead:patch.object(verify.Header, "difficulty", new_callable=PropertyMock, return_value=50e12)for "exactly", andmath.nextafter(50e12, 0)for "just below". - Hard-code
50e12in the test: a test that readsverify.STRONG_DIFFICULTYcannot catch a changed constant.
See CONTRIBUTING.md for the test, lint and type-check commands. Comment below before starting, so two people don't take the same issue.
- Dominant language
- Python
- Stars
- 2
- Forks
- 1
- Avg merge
- 1h 45m
- Merged PRs (30d)
- 23
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from devdavidejesus/btc-toolkit
-
tests: assert which API paths each command requestsPossibly taken @omarelshamy25x claimed this today. Opengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
devdavidejesus/btc-toolkit#107 · 1 comment ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
devdavidejesus/btc-toolkit#104 ·
Maintainers usually reply within 1 day
-
enhancement help wanted
Difficulty 3/5 1-2 days Newbie friendliness 71/100
devdavidejesus/btc-toolkit#105 ·
Maintainers usually reply within 1 day
-
api: reject a /tx response that has no txid fieldPossibly taken @pkray2012 claimed this 1 day ago. Openenhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
devdavidejesus/btc-toolkit#103 ·
Maintainers usually reply within 1 day
-
cli: Ctrl+C should stop btc-toolkit without a tracebackPossibly taken @jay23606 claimed this 1 day ago. Openbug good first issue
Difficulty 3/5 1-2 days Newbie friendliness 25/100
devdavidejesus/btc-toolkit#102 ·
Maintainers usually reply within 1 day
All issues in devdavidejesus/btc-toolkit
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
daniel-ospina/tortoise#15308 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
difficulty:easy prio:low type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NatronGitHub/Natron#2405 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Jstar269/nakagawa-recomp#3746 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day