Skip to content

Commit 74b76d2

Browse files
authored
Merge branch 'karask:master' into core_default_nsequence
2 parents 3900141 + 041a801 commit 74b76d2

3 files changed

Lines changed: 77 additions & 28 deletions

File tree

CONTRIBUTING.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Thank you for considering contributing to the `python-bitcoin-utils` project! Yo
77
### 1. Reporting Issues
88

99
If you encounter any bugs, unexpected behavior, or have feature requests, please open an issue on the [GitHub Issues](https://github.com/karask/python-bitcoin-utils/issues) page. When reporting a bug, provide the following information:
10-
1110
- A clear description of the issue.
1211
- Steps to reproduce the issue.
1312
- Expected behavior.
@@ -26,19 +25,18 @@ We welcome pull requests! To contribute code:
2625

2726
1. Fork the repository on GitHub.
2827
2. Clone your fork to your local machine:
29-
```sh
30-
git clone https://github.com/your-username/python-bitcoin-utils.git
31-
cd python-bitcoin-utils
32-
```
28+
```sh
29+
git clone https://github.com/your-username/python-bitcoin-utils.git
30+
cd python-bitcoin-utils
31+
```
3332
3. Add the upstream repository to keep your fork updated:
34-
```sh
35-
git remote add upstream https://github.com/karask/python-bitcoin-utils.git
36-
```
33+
```sh
34+
git remote add upstream https://github.com/karask/python-bitcoin-utils.git
35+
```
3736

3837
#### Step 2: Create a Feature Branch
3938

4039
Create a new branch for your changes:
41-
4240
```sh
4341
git checkout -b feature-name
4442
```
@@ -47,6 +45,11 @@ git checkout -b feature-name
4745

4846
- Follow the project's coding style.
4947
- Ensure your code is well-documented and includes meaningful commit messages.
48+
- Install the package in development mode before running tests:
49+
```sh
50+
pip install -e .
51+
```
52+
This creates an editable installation linking to your local code, which is necessary for the tests to properly discover and import modules.
5053
- Run tests before submitting a pull request:
5154
```sh
5255
pytest tests/
@@ -56,9 +59,9 @@ git checkout -b feature-name
5659
#### Step 4: Submit a Pull Request
5760

5861
1. Push your changes to your fork's branch:
59-
```sh
60-
git push origin feature-name
61-
```
62+
```sh
63+
git push origin feature-name
64+
```
6265
2. Open a pull request from your fork's branch to the `master` branch of the original repository.
6366
3. Provide a detailed description of your changes.
6467
4. Address any requested changes from maintainers.
@@ -78,11 +81,9 @@ git checkout -b feature-name
7881
### 5. Writing Tests
7982

8083
Ensure new features and bug fixes include test cases. The project uses `pytest` for testing. Run all tests with:
81-
8284
```sh
8385
pytest
8486
```
85-
8687
If you add new features, create corresponding test cases under the `tests/` directory. Ensure your tests cover:
8788
- Normal expected operation
8889
- Edge cases
@@ -92,10 +93,19 @@ If you add new features, create corresponding test cases under the `tests/` dire
9293

9394
Help improve the documentation by submitting corrections, clarifications, or examples. Update the README or other documentation files as needed.
9495

96+
### 7. Troubleshooting Test Failures
97+
98+
If you encounter test failures when running the test suite, check for these common issues:
99+
100+
- **Module import errors**: Make sure you've installed the package in development mode with `pip install -e .`
101+
- **API mismatch errors**: If tests are failing with TypeError or similar errors about function signatures, check if there have been recent API changes in the corresponding modules.
102+
- **Transaction hex mismatches**: Assertion errors in transaction tests with hex string differences often indicate changes in transaction serialization or signature generation logic.
103+
104+
For specific test failures, please refer to the test file and the corresponding implementation to understand the expected behavior.
105+
95106
## Code of Conduct
96107

97108
Be respectful and follow the open-source community guidelines. Maintain a collaborative and inclusive environment.
98109

99110
---
100-
101-
Thank you for contributing! 🚀
111+
Thank you for contributing! 🚀

bitcoinutils/script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@
225225
b"\xaf": "OP_CHECKMULTISIGVERIFY",
226226
b"\xba": "OP_CHECKSIGADD", # added this new OPCODE
227227
# locktime
228-
b"\xb1": "OP_NOP2",
229-
b"\xb1": "OP_CHECKLOCKTIMEVERIFY",
230-
b"\xb2": "OP_NOP3",
231-
b"\xb2": "OP_CHECKSEQUENCEVERIFY",
228+
# This used to be OP_NOP2
229+
b"\xb1": "OP_CHECKLOCKTIMEVERIFY",
230+
# This used to be OP_NOP3
231+
b"\xb2": "OP_CHECKSEQUENCEVERIFY",
232232
}
233233

234234

@@ -452,4 +452,4 @@ def __repr__(self) -> str:
452452
def __eq__(self, _other: object) -> bool:
453453
if not isinstance(_other, Script):
454454
return False
455-
return self.script == _other.script
455+
return self.script == _other.script

bitcoinutils/utils.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,14 @@ def to_bytes(self) -> bytes:
105105
pub_key = bytes.fromhex(self.pubkey.to_x_only_hex())
106106
return leaf_version + pub_key + self.merkle_path
107107

108-
def to_hex(self):
109-
"""Converts object to hexadecimal string"""
108+
def to_hex(self) -> str:
109+
"""Converts object to hexadecimal string
110+
111+
Returns
112+
-------
113+
str
114+
The control block as a hexadecimal string
115+
"""
110116
return b_to_h(self.to_bytes())
111117

112118

@@ -302,8 +308,17 @@ def get_transaction_length(data: bytes) -> int:
302308

303309

304310
def is_address_bech32(address: str) -> bool:
305-
"""
306-
Returns if an address (string) is bech32 or not
311+
"""Returns if an address (string) is bech32 or not
312+
313+
Parameters
314+
----------
315+
address : str
316+
The address to check
317+
318+
Returns
319+
-------
320+
bool
321+
True if the address is bech32, False otherwise
307322
"""
308323
if not address:
309324
return False
@@ -398,15 +413,39 @@ def calculate_tweak(
398413

399414

400415
def tapleaf_tagged_hash(script: Script) -> bytes:
401-
"""Calculates the tagged hash for a tapleaf"""
416+
"""Calculates the tagged hash for a tapleaf
417+
418+
Parameters
419+
----------
420+
script : Script
421+
The script to calculate the tagged hash for
422+
423+
Returns
424+
-------
425+
bytes
426+
The tagged hash of the tapleaf
427+
"""
402428
script_part = bytes([LEAF_VERSION_TAPSCRIPT]) + prepend_compact_size(
403429
script.to_bytes()
404430
)
405431
return tagged_hash(script_part, "TapLeaf")
406432

407433

408434
def tapbranch_tagged_hash(thashed_a: bytes, thashed_b: bytes) -> bytes:
409-
"""Calculates the tagged hash for a tapbranch"""
435+
"""Calculates the tagged hash for a tapbranch
436+
437+
Parameters
438+
----------
439+
thashed_a : bytes
440+
First tagged hash
441+
thashed_b : bytes
442+
Second tagged hash
443+
444+
Returns
445+
-------
446+
bytes
447+
The tagged hash of the tapbranch
448+
"""
410449
# order - smaller left side
411450
if thashed_a < thashed_b:
412451
return tagged_hash(thashed_a + thashed_b, "TapBranch")
@@ -555,4 +594,4 @@ def i_to_b(i: int) -> bytes:
555594
return i.to_bytes(byte_length, "big")
556595

557596

558-
# TODO are these required - maybe bytestoint and inttobytes are only required?!?
597+
# TODO are these required - maybe bytestoint and inttobytes are only required?!?

0 commit comments

Comments
 (0)