tests: assert which API paths each command requests

Open Beginner friendly
#107 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@omarelshamy25x is already working on this.

Since Dec 4, 2026.

  • #120 by @omarelshamy25x — open

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
cli, testing

Research direction

Read the named tests in tests/test_verify.py, tests/test_fees.py, tests/test_block.py, and tests/test_new_commands.py for existing path assertions; then inspect the relevant command tests and patch targets named in the issue. Add mock call assertions for each listed command and verify paths are checked in order, including across get_json and get_text for verify. Done when each test fails on an unexpected or changed path and no files under btc_toolkit/ have changed.

Written by the indexing model from the issue text.

Description

good first issue

What

Many tests mock the API without checking which path is requested: _api() in tests/test_verify.py (L27-L38) routes only by the end of the path, and most other tests patch get_json with a fixed answer. So a command that requested the wrong endpoint (a typo such as /adress/<address> or /txs/<txid>) would still pass for balance, address, utxo, tx, opreturn, inscription, decode --txid, verify, and the second request of block latest.

fees, block by height and by hash, the tip request of block latest and the /outspends request of tx --outputs are already checked (tests/test_fees.py, tests/test_block.py, tests/test_new_commands.py); use them as examples.

What to do

Add tests that check the exact paths, in order, that each of these commands requests for a typical call:

  • balance and address: /address/<address>
  • utxo: /address/<address>/utxo
  • tx, opreturn and inscription: /tx/<txid>
  • block latest: /blocks/tip/height, then /block-height/<tip>, then /block/<hash>
  • decode --txid: /tx/<txid>/hex
  • verify: /tx/<txid>/status, /tx/<txid>/hex, /tx/<txid>/merkle-proof, /block/<hash>/header

Patch get_json / get_text where the command looks them up, with a Mock, and use assert_has_calls (or make the mock raise on any path it does not know). tx, opreturn and inscription fetch /tx/<txid> through fetch_transaction in btc_toolkit/opreturn.py, so patch btc_toolkit.opreturn.get_json; address goes through btc_toolkit.balance; decode --txid uses btc_toolkit.cli.get_text. For verify, the order spans two mocks (get_json and get_text): record the paths in one list, or use attach_mock, to check the full order.

Acceptance

  • Each test fails if the path its command requests changes.
  • 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from devdavidejesus/btc-toolkit

All issues in devdavidejesus/btc-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.