Skip to content

Commit

Permalink
Pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocaironi committed Jul 12, 2023
1 parent 2486895 commit 6210dca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
8 changes: 3 additions & 5 deletions btclib/descriptors.py
Expand Up @@ -7,8 +7,7 @@
#
# No part of btclib including this file, may be copied, modified, propagated,
# or distributed except according to the terms contained in the LICENSE file.

"""Descriptors util functions
"""Descriptors util functions.
BIP 380: https://github.com/bitcoin/bips/blob/master/bip-0380.mediawiki
"""
Expand All @@ -21,7 +20,6 @@


def __descsum_polymod(symbols):
"""Internal function that computes the descriptor checksum."""
chk = 1
for value in symbols:
top = chk >> 35
Expand All @@ -32,7 +30,7 @@ def __descsum_polymod(symbols):


def __descsum_expand(descriptor_string: str):
"""Internal function that does the character to symbol expansion"""
"""Perform the character to symbol expansion."""
groups = []
symbols = []
for char in descriptor_string:
Expand All @@ -52,7 +50,7 @@ def __descsum_expand(descriptor_string: str):


def descriptor_checksum(descriptor: str) -> str:
"""Compute the descriptor checksum"""
"""Compute the descriptor checksum."""
symbols = __descsum_expand(descriptor) + [0, 0, 0, 0, 0, 0, 0, 0]
checksum = __descsum_polymod(symbols) ^ 1
return "".join(CHECKSUM_CHARSET[(checksum >> (5 * (7 - i))) & 31] for i in range(8))
Expand Down
2 changes: 1 addition & 1 deletion tests/_data/descriptor_checksums.json
Expand Up @@ -71,4 +71,4 @@
"desc": "tr(c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5,sortedmulti_a(2,2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4,5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc))",
"checksum": "tp09wjyq"
}
]
]
8 changes: 2 additions & 6 deletions tests/test_descriptors.py
Expand Up @@ -7,8 +7,7 @@
#
# No part of btclib including this file, may be copied, modified, propagated,
# or distributed except according to the terms contained in the LICENSE file.

"Tests for the `btclib.descriptors` module."
"""Tests for the `btclib.descriptors` module."""

import json
from pathlib import Path
Expand All @@ -26,9 +25,8 @@
# descriptors taken from https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md
# checksum calculated using https://docs.rs/bdk/latest/bdk/descriptor/checksum/fn.get_checksum.html
def test_checksum():

filename = Path(__file__).parent / "_data" / "descriptor_checksums.json"
with open(filename, "r", encoding="utf-8") as file:
with open(filename, encoding="utf-8") as file:
data = json.load(file)

for descriptor_data in data:
Expand All @@ -38,13 +36,11 @@ def test_checksum():


def test_invalid_charset():

with pytest.raises(BTClibValueError):
__descsum_expand("è")


def test_addr():

address = "bc1qnehtvnd4fedkwjq6axfgsrxgllwne3k58rhdh0"
descriptor = "addr(bc1qnehtvnd4fedkwjq6axfgsrxgllwne3k58rhdh0)#s2y3vepm"
assert descriptor_from_address(address) == descriptor

0 comments on commit 6210dca

Please sign in to comment.