test(encoding): use real addresses in test_address and cover the script-type edges
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Read tests/test_address.py and tests/test_encoding.py, then inspect the referenced functions in btc_toolkit/encoding.py to understand the current behavior. Replace the synthetic address cases, add the specified edge-case assertions, and check that each test fails when its covered behavior is removed or changed. Done when the tests cover real decoding, script endings, and the Base58 length guard without changing files under btc_toolkit/.
Written by the indexing model from the issue text.
Description
What
A few tests pass for the wrong reason, and a few guards have no test at all:
test_p2wshandtest_p2trintests/test_address.pyuse"bc1q" + "a" * 58and"bc1p" + "a" * 58, which have invalid checksums. They pass through the prefix-and-length guess ofdetect_address_type, not through real decoding.script_type(encoding.pyL240-L246) recognizes P2PKH by its88acending and P2SH by its87ending; nothing fails if either ending check is removed, although an address would then be derived from a script that is not P2PKH or P2SH.- The length guard in
b58check_decode(L127-L128), which stops a huge input from being decoded, is never really checked:test_base58_edge_casespasses"1" * 120but only asserts aValueError, and without the guard the checksum check raises one anyway.
What to do
- In
tests/test_address.py, replace the two synthetic addresses with real ones: a P2WSH and a P2TR address (e.g.bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3from BIP 173 andbc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0from BIP 350), and keep a separate test for the fallback guess on a checksum-invalid string. The guess gives a 62-characterbc1q/bc1paddress the same type, so these tests cannot catch broken decoding on their own: also add a real address the guess gets wrong, such asbc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs(witness_v2; the guess saysunknown) orbc1pfeessrawgf(P2A). - In
tests/test_encoding.py, test that a 25-byte script with the P2PKH prefix but another ending, and a 23-byte script with the P2SH prefix but another last byte, are not P2PKH / P2SH. - Test that a Base58 string longer than 100 characters (e.g.
"1" * 101) is rejected with the message "too long" (match the message: anyValueErroris not enough).
Acceptance
- Each new or changed test fails if the code it covers is removed or changed (please say in the PR that you checked).
- No change under
btc_toolkit/.
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
-
test(verify): cover invalid bits, the mainnet and testnet limits, and the strong thresholdPossibly taken @omarelshamy25x claimed this 1 day ago. Opengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
devdavidejesus/btc-toolkit#99 · 1 comment ·
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