test(encoding): use real addresses in test_address and cover the script-type edges

Aperta Adatta ai principianti
#104 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli, testing

Direzione di ricerca

Leggi tests/test_address.py e tests/test_encoding.py, poi esamina le funzioni a cui fanno riferimento in btc_toolkit/encoding.py per capire il comportamento attuale. Sostituisci i casi di indirizzi sintetici, aggiungi le asserzioni specificate per i casi limite e verifica che ogni test fallisca quando il comportamento coperto viene rimosso o modificato. Il lavoro è completato quando i test coprono la decodifica reale, le terminazioni degli script e il controllo della lunghezza Base58, senza modificare file in btc_toolkit/.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

good first issue

What

A few tests pass for the wrong reason, and a few guards have no test at all:

  • test_p2wsh and test_p2tr in tests/test_address.py use "bc1q" + "a" * 58 and "bc1p" + "a" * 58, which have invalid checksums. They pass through the prefix-and-length guess of detect_address_type, not through real decoding.
  • script_type (encoding.py L240-L246) recognizes P2PKH by its 88ac ending and P2SH by its 87 ending; 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_cases passes "1" * 120 but only asserts a ValueError, and without the guard the checksum check raises one anyway.

What to do

  1. In tests/test_address.py, replace the two synthetic addresses with real ones: a P2WSH and a P2TR address (e.g. bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3 from BIP 173 and bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0 from BIP 350), and keep a separate test for the fallback guess on a checksum-invalid string. The guess gives a 62-character bc1q/bc1p address the same type, so these tests cannot catch broken decoding on their own: also add a real address the guess gets wrong, such as bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs (witness_v2; the guess says unknown) or bc1pfeessrawgf (P2A).
  2. 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.
  3. Test that a Base58 string longer than 100 characters (e.g. "1" * 101) is rejected with the message "too long" (match the message: any ValueError is 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.

Lingua principale
Python
Stelle
2
Fork
1
Merge medio
1h 45m
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di devdavidejesus/btc-toolkit

Tutte le issue di devdavidejesus/btc-toolkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.