diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1dbd36ad..fc1a673a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -40,7 +40,7 @@ repos: args: [--notice=COPYRIGHT] files: python - repo: https://github.com/PyCQA/autoflake - rev: v2.2.0 + rev: v2.3.3 hooks: - id: autoflake args: @@ -54,7 +54,7 @@ repos: language: python types: [python] - repo: https://github.com/asottile/pyupgrade - rev: v3.9.0 + rev: v3.21.2 hooks: - id: pyupgrade args: [--py38-plus] @@ -62,7 +62,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 9.0.0a3 hooks: - id: isort name: isort (black profile, in place fixes) @@ -70,7 +70,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/docformatter - rev: v1.7.5 + rev: v1.7.8 hooks: - id: docformatter description: "Formats docstrings to follow PEP 257." @@ -78,7 +78,7 @@ repos: types: [python] args: ["--in-place"] - repo: https://github.com/DanielNoord/pydocstringformatter - rev: v0.7.3 + rev: v0.7.5 hooks: - id: pydocstringformatter language: python @@ -97,13 +97,13 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.3.0 hooks: - id: flake8 language: python types: [python] - - repo: https://github.com/psf/black - rev: 23.7.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.5.1 hooks: - id: black name: black (in place fixes) @@ -116,7 +116,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 + rev: 1.9.4 hooks: - id: bandit name: bandit (btclib) @@ -125,7 +125,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 + rev: 1.9.4 hooks: - id: bandit name: bandit (tests) @@ -138,7 +138,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/pylint - rev: v3.0.0a6 + rev: v4.0.6 hooks: - id: pylint args: [ @@ -147,13 +147,13 @@ repos: language: python types: [python] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v2.1.0 hooks: - id: mypy language: python types: [python] - repo: https://github.com/mgedmin/check-manifest - rev: "0.49" + rev: "0.51" hooks: - id: check-manifest description: Check the completeness of MANIFEST.in for Python packages. @@ -161,6 +161,6 @@ repos: pass_filenames: false always_run: true - repo: https://github.com/regebro/pyroma - rev: "4.2" + rev: "5.1b1" hooks: - id: pyroma diff --git a/btclib/alias.py b/btclib/alias.py index 38617587..798f9b70 100644 --- a/btclib/alias.py +++ b/btclib/alias.py @@ -11,6 +11,7 @@ mypy aliases, documenting also coding input conventions. """ + from __future__ import annotations from io import BytesIO diff --git a/btclib/b58.py b/btclib/b58.py index 5741526c..c599ca3e 100644 --- a/btclib/b58.py +++ b/btclib/b58.py @@ -12,6 +12,7 @@ Base58 encoding of public keys and scripts as addresses, private keys as WIFs """ + from __future__ import annotations from btclib import b32 diff --git a/btclib/base58.py b/btclib/base58.py index 9ab3ad5e..30610c0c 100644 --- a/btclib/base58.py +++ b/btclib/base58.py @@ -34,6 +34,7 @@ it supports encoding bytes-like objects to ASCII bytes, and decoding ASCII bytes-like objects or ASCII strings to bytes. """ + from __future__ import annotations from btclib.alias import Octets, String diff --git a/btclib/bip32/bip32.py b/btclib/bip32/bip32.py index 5d175f3b..d266b243 100644 --- a/btclib/bip32/bip32.py +++ b/btclib/bip32/bip32.py @@ -30,6 +30,7 @@ - [13:45] chain code - [45:78] compressed pub_key or [0x00][prv_key] """ + from __future__ import annotations import copy diff --git a/btclib/bip32/der_path.py b/btclib/bip32/der_path.py index d6d0ab76..90a2dfdf 100644 --- a/btclib/bip32/der_path.py +++ b/btclib/bip32/der_path.py @@ -15,6 +15,7 @@ - sequence of integer indexes (even a single int) - bytes (multiples of 4-bytes index) """ + from __future__ import annotations from typing import Sequence, Union diff --git a/btclib/bip32/key_origin.py b/btclib/bip32/key_origin.py index 24f65158..0960b347 100644 --- a/btclib/bip32/key_origin.py +++ b/btclib/bip32/key_origin.py @@ -8,6 +8,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. """BIP32 key origin.""" + from __future__ import annotations from dataclasses import dataclass @@ -138,7 +139,7 @@ def decode_hd_key_paths(map_: Mapping[Octets, BIP32KeyOrigin] | None) -> HdKeyPa def encode_to_bip32_derivs( - hd_key_paths: Mapping[bytes, BIP32KeyOrigin] + hd_key_paths: Mapping[bytes, BIP32KeyOrigin], ) -> list[_BIP32Deriv]: """Return the json representation of the dataclass element.""" return [ @@ -152,7 +153,7 @@ def encode_to_bip32_derivs( def _decode_from_bip32_deriv( - bip32_deriv: Mapping[str, str] + bip32_deriv: Mapping[str, str], ) -> tuple[bytes, BIP32KeyOrigin]: # FIXME remove size checks to allow # the instantiation of invalid master_fingerprint and pub_key diff --git a/btclib/bip32/slip132.py b/btclib/bip32/slip132.py index ee99185f..f9a40143 100644 --- a/btclib/bip32/slip132.py +++ b/btclib/bip32/slip132.py @@ -11,6 +11,7 @@ https://github.com/satoshilabs/slips/blob/master/slip-0132.md """ + from __future__ import annotations import contextlib diff --git a/btclib/block/block.py b/btclib/block/block.py index 595c17d9..025eb7cc 100644 --- a/btclib/block/block.py +++ b/btclib/block/block.py @@ -11,6 +11,7 @@ Dataclass encapsulating BlockHeader and list[Tx]. """ + from __future__ import annotations from dataclasses import dataclass diff --git a/btclib/block/block_header.py b/btclib/block/block_header.py index 17209e6a..8ae11d2c 100644 --- a/btclib/block/block_header.py +++ b/btclib/block/block_header.py @@ -12,6 +12,7 @@ Dataclass encapsulating version, previous block hash, merkle root, time, bits, and nonce. """ + from __future__ import annotations from dataclasses import dataclass diff --git a/btclib/ec/curve.py b/btclib/ec/curve.py index a25e9e32..32073872 100644 --- a/btclib/ec/curve.py +++ b/btclib/ec/curve.py @@ -8,6 +8,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. """Elliptic curve classes and functions.""" + from __future__ import annotations import json @@ -241,9 +242,10 @@ def double_mult( def multi_mult( scalars: Sequence[Integer], points: Sequence[Point], ec: Curve = secp256k1 ) -> Point: - """Return the multi scalar multiplication u1*Q1 + ... + un*Qn. + """Return the multi scalar multiplication u1*Q1 + ... - Use Bos-Coster's algorithm for efficient computation. + + un*Qn. + Use Bos-Coster's algorithm for efficient computation. """ if len(scalars) != len(points): err_msg = "mismatch between number of scalars and points: " diff --git a/btclib/ec/curve_group.py b/btclib/ec/curve_group.py index 34d31f8e..99371a52 100644 --- a/btclib/ec/curve_group.py +++ b/btclib/ec/curve_group.py @@ -13,6 +13,7 @@ cyclic subgroup class CurveSubGroup and the cyclic subgroup class of prime order Curve, see the btclib.ec.curve module. """ + from __future__ import annotations import functools @@ -699,13 +700,14 @@ def _double_mult( def _multi_mult( scalars: Sequence[int], jac_points: Sequence[JacPoint], ec: CurveGroup ) -> JacPoint: - """Return the multi scalar multiplication u1*Q1 + ... + un*Qn. + """Return the multi scalar multiplication u1*Q1 + ... - Use Bos-Coster's algorithm for efficient computation. + + un*Qn. + Use Bos-Coster's algorithm for efficient computation. - The input points are assumed to be on curve, the scalar coefficients - are assumed to have been reduced mod n if appropriate (e.g. cyclic - groups of order n). + The input points are assumed to be on curve, the scalar coefficients + are assumed to have been reduced mod n if appropriate (e.g. cyclic + groups of order n). """ # source: https://cr.yp.to/badbatch/boscoster2.py if len(scalars) != len(jac_points): diff --git a/btclib/ec/curve_group_f.py b/btclib/ec/curve_group_f.py index 3ef9bd41..d0d8c42d 100644 --- a/btclib/ec/curve_group_f.py +++ b/btclib/ec/curve_group_f.py @@ -12,6 +12,7 @@ These functions are meant to explore low-cardinality CurveGroup, for didactical (and fun) reason only. """ + from __future__ import annotations from btclib.alias import INF, Point diff --git a/btclib/ec/libsecp256k1.py b/btclib/ec/libsecp256k1.py index 49ad996d..04e7eb54 100644 --- a/btclib/ec/libsecp256k1.py +++ b/btclib/ec/libsecp256k1.py @@ -9,7 +9,6 @@ # or distributed except according to the terms contained in the LICENSE file. """Helper functions to use the libsecp256k1 python bindings.""" - from __future__ import annotations import contextlib diff --git a/btclib/ecc/bms.py b/btclib/ecc/bms.py index a85c3fea..b1fdc408 100644 --- a/btclib/ecc/bms.py +++ b/btclib/ecc/bms.py @@ -129,6 +129,7 @@ https://github.com/bitcoin/bips/blob/master/bip-0137.mediawiki """ + from __future__ import annotations import base64 diff --git a/btclib/ecc/dh.py b/btclib/ecc/dh.py index 71560289..e27bd2a0 100644 --- a/btclib/ecc/dh.py +++ b/btclib/ecc/dh.py @@ -17,6 +17,7 @@ The two entities must agree on the elliptic curve and key derivation function to use. """ + from __future__ import annotations from hashlib import sha256 diff --git a/btclib/ecc/sign_to_contract.py b/btclib/ecc/sign_to_contract.py index c7ea4beb..46c94e78 100644 --- a/btclib/ecc/sign_to_contract.py +++ b/btclib/ecc/sign_to_contract.py @@ -31,6 +31,7 @@ with e = hash(R||commit_hash)) and W.x being known from the signature. """ + from __future__ import annotations from hashlib import sha256 diff --git a/btclib/hashes.py b/btclib/hashes.py index 3404ffae..5c685457 100644 --- a/btclib/hashes.py +++ b/btclib/hashes.py @@ -8,6 +8,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. """Hash based helper functions.""" + from __future__ import annotations import hashlib diff --git a/btclib/mnemonic/electrum.py b/btclib/mnemonic/electrum.py index ab137ba7..dc54654a 100644 --- a/btclib/mnemonic/electrum.py +++ b/btclib/mnemonic/electrum.py @@ -11,6 +11,7 @@ Electrum mnemonic is versioned, conveying BIP32 derivation rule too. """ + from __future__ import annotations import hmac diff --git a/btclib/mnemonic/entropy.py b/btclib/mnemonic/entropy.py index 84087e94..a4a2ae31 100644 --- a/btclib/mnemonic/entropy.py +++ b/btclib/mnemonic/entropy.py @@ -18,6 +18,7 @@ Output entropy is always raw. """ + from __future__ import annotations import math diff --git a/btclib/mnemonic/mnemonic.py b/btclib/mnemonic/mnemonic.py index c198a921..822b66e4 100644 --- a/btclib/mnemonic/mnemonic.py +++ b/btclib/mnemonic/mnemonic.py @@ -8,6 +8,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. """Mnemonic sentence conversion from/to sequence of integer indexes.""" + from __future__ import annotations from os import path diff --git a/btclib/number_theory.py b/btclib/number_theory.py index c052cdbc..8b446c98 100644 --- a/btclib/number_theory.py +++ b/btclib/number_theory.py @@ -19,6 +19,7 @@ * minor improvements * added extensive unit test """ + from __future__ import annotations from btclib.exceptions import BTClibValueError diff --git a/btclib/psbt/psbt.py b/btclib/psbt/psbt.py index 57d44deb..b53e37d7 100644 --- a/btclib/psbt/psbt.py +++ b/btclib/psbt/psbt.py @@ -11,6 +11,7 @@ https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki """ + from __future__ import annotations import base64 diff --git a/btclib/psbt/psbt_in.py b/btclib/psbt/psbt_in.py index 1f12a0bf..5c306612 100644 --- a/btclib/psbt/psbt_in.py +++ b/btclib/psbt/psbt_in.py @@ -11,6 +11,7 @@ https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki """ + from __future__ import annotations # Standard library imports @@ -126,7 +127,7 @@ def _deserialize_final_script_witness(k: bytes, v: bytes) -> Witness: def _assert_valid_ripemd160_preimages( - ripemd160_preimages: Mapping[bytes, bytes] + ripemd160_preimages: Mapping[bytes, bytes], ) -> None: for h, preimage in ripemd160_preimages.items(): if ripemd160(preimage) != h: @@ -200,8 +201,9 @@ def __init__( taproot_key_spend_signature: Octets = b"", taproot_script_spend_signatures: Mapping[Octets, Octets] | None = None, taproot_leaf_scripts: Mapping[Octets, tuple[Octets, int]] | None = None, - taproot_hd_key_paths: Mapping[Octets, tuple[list[Octets], BIP32KeyOrigin]] - | None = None, + taproot_hd_key_paths: ( + Mapping[Octets, tuple[list[Octets], BIP32KeyOrigin]] | None + ) = None, taproot_internal_key: Octets = b"", taproot_merkle_root: Octets = b"", unknown: Mapping[Octets, Octets] | None = None, @@ -283,12 +285,12 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]: self.assert_valid() return { - "non_witness_utxo": self.non_witness_utxo.to_dict(False) - if self.non_witness_utxo - else None, - "witness_utxo": self.witness_utxo.to_dict(False) - if self.witness_utxo - else None, + "non_witness_utxo": ( + self.non_witness_utxo.to_dict(False) if self.non_witness_utxo else None + ), + "witness_utxo": ( + self.witness_utxo.to_dict(False) if self.witness_utxo else None + ), "partial_signatures": encode_dict_bytes_bytes(self.partial_sigs), "sig_hash": self.sig_hash_type, # TODO make it { "asm": "", "hex": "" } @@ -327,12 +329,16 @@ def from_dict( decode_from_bip32_derivs(dict_["taproot_hd_key_paths"]), ) return cls( - Tx.from_dict(dict_["non_witness_utxo"], False) - if dict_["non_witness_utxo"] - else None, - TxOut.from_dict(dict_["witness_utxo"], False) - if dict_["witness_utxo"] - else None, + ( + Tx.from_dict(dict_["non_witness_utxo"], False) + if dict_["non_witness_utxo"] + else None + ), + ( + TxOut.from_dict(dict_["witness_utxo"], False) + if dict_["witness_utxo"] + else None + ), dict_["partial_signatures"], dict_["sig_hash"], dict_["redeem_script"], diff --git a/btclib/psbt/psbt_out.py b/btclib/psbt/psbt_out.py index f09bb5fe..5a73af45 100644 --- a/btclib/psbt/psbt_out.py +++ b/btclib/psbt/psbt_out.py @@ -12,6 +12,7 @@ Dataclass and functions. https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki """ + from __future__ import annotations from dataclasses import dataclass @@ -80,8 +81,9 @@ def __init__( hd_key_paths: Mapping[Octets, BIP32KeyOrigin] | None = None, taproot_internal_key: Octets = b"", taproot_tree: Sequence[tuple[int, int, Octets]] | None = None, - taproot_hd_key_paths: Mapping[Octets, tuple[list[bytes], BIP32KeyOrigin]] - | None = None, + taproot_hd_key_paths: ( + Mapping[Octets, tuple[list[bytes], BIP32KeyOrigin]] | None + ) = None, unknown: Mapping[Octets, Octets] | None = None, check_validity: bool = True, ) -> None: diff --git a/btclib/psbt/psbt_utils.py b/btclib/psbt/psbt_utils.py index fde85cca..cb8228a2 100644 --- a/btclib/psbt/psbt_utils.py +++ b/btclib/psbt/psbt_utils.py @@ -11,6 +11,7 @@ https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki """ + from __future__ import annotations from io import BytesIO @@ -96,7 +97,7 @@ def serialize_dict_bytes_bytes( def encode_leaf_scripts( - dict_: Mapping[bytes, tuple[bytes, int]] + dict_: Mapping[bytes, tuple[bytes, int]], ) -> dict[str, tuple[str, int]]: """Return the json representation of a tap_leaf_script. @@ -107,7 +108,7 @@ def encode_leaf_scripts( def decode_leaf_scripts( - map_: Mapping[Octets, tuple[Octets, int]] | None + map_: Mapping[Octets, tuple[Octets, int]] | None, ) -> dict[bytes, tuple[bytes, int]]: """Return a tap_leaf_script from its json representation.""" if map_ is None: @@ -136,7 +137,7 @@ def parse_leaf_script(v: bytes) -> tuple[bytes, int]: def encode_taproot_tree( - list_: list[tuple[int, int, bytes]] + list_: list[tuple[int, int, bytes]], ) -> list[tuple[int, int, str]]: """Return the json representation of a tap_tree. @@ -146,7 +147,7 @@ def encode_taproot_tree( def decode_taproot_tree( - list_: Sequence[tuple[int, int, Octets]] | None + list_: Sequence[tuple[int, int, Octets]] | None, ) -> list[tuple[int, int, bytes]]: """Return a tap_tree from its json representation.""" if list_ is None: @@ -184,7 +185,7 @@ def parse_taproot_tree(v: bytes) -> list[tuple[int, int, bytes]]: def taproot_bip32_to_dict( - taproot_hd_key_paths: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]] + taproot_hd_key_paths: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]], ) -> list[dict[str, Any]]: """Return the json representation of a tap_bip32_derivation. @@ -203,7 +204,7 @@ def taproot_bip32_to_dict( def taproot_bip32_from_dict( - taproot_hd_key_paths: list[dict[str, str]] + taproot_hd_key_paths: list[dict[str, str]], ) -> dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]: """Return a tap_bip32_derivation from its json representation.""" return { @@ -219,7 +220,7 @@ def taproot_bip32_from_dict( def decode_taproot_bip32( - dict_: Mapping[Octets, tuple[Sequence[Octets], BIP32KeyOrigin]] | None + dict_: Mapping[Octets, tuple[Sequence[Octets], BIP32KeyOrigin]] | None, ) -> dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]: """Parse correctly the tap_bip32_derivation init arguments.""" if dict_ is None: @@ -315,7 +316,7 @@ def assert_valid_taproot_tree(tree: list[tuple[int, int, bytes]]) -> None: def assert_valid_taproot_bip32_derivation( - derivations: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]] + derivations: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]], ) -> None: """Fails when the public keys have not the correct length.""" for pubkey in derivations: diff --git a/btclib/to_prv_key.py b/btclib/to_prv_key.py index 8089f256..be49dbb3 100644 --- a/btclib/to_prv_key.py +++ b/btclib/to_prv_key.py @@ -8,6 +8,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. """Functions for conversions between different private key formats.""" + from __future__ import annotations import contextlib diff --git a/btclib/to_pub_key.py b/btclib/to_pub_key.py index d987d99b..db053873 100644 --- a/btclib/to_pub_key.py +++ b/btclib/to_pub_key.py @@ -8,6 +8,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. """Functions for conversions between different public key formats.""" + from __future__ import annotations import contextlib diff --git a/btclib/tx/out_point.py b/btclib/tx/out_point.py index 7b46679d..fbf12d8a 100644 --- a/btclib/tx/out_point.py +++ b/btclib/tx/out_point.py @@ -12,7 +12,6 @@ Dataclass encapsulating tx_id and vout. """ - from __future__ import annotations from dataclasses import dataclass diff --git a/btclib/tx/tx.py b/btclib/tx/tx.py index 58da44ac..9b937dfc 100644 --- a/btclib/tx/tx.py +++ b/btclib/tx/tx.py @@ -224,11 +224,14 @@ def serialize(self, include_witness: bool, check_validity: bool = True) -> bytes b"".join(tx_in.serialize(check_validity) for tx_in in self.vin), var_int.serialize(len(self.vout)), b"".join(tx_out.serialize(check_validity) for tx_out in self.vout), - b"".join( - tx_in.script_witness.serialize(check_validity) for tx_in in self.vin - ) - if segwit - else b"", + ( + b"".join( + tx_in.script_witness.serialize(check_validity) + for tx_in in self.vin + ) + if segwit + else b"" + ), self.lock_time.to_bytes(4, byteorder="little", signed=False), ] ) diff --git a/btclib/utils.py b/btclib/utils.py index a4a7eebe..7f286046 100644 --- a/btclib/utils.py +++ b/btclib/utils.py @@ -13,6 +13,7 @@ https://www.secg.org/sec1-v2.pdf """ + from __future__ import annotations from collections.abc import Iterable as IterableCollection diff --git a/btclib/var_int.py b/btclib/var_int.py index bf261e57..7ca5a8ac 100644 --- a/btclib/var_int.py +++ b/btclib/var_int.py @@ -58,9 +58,9 @@ def serialize(i: int) -> bytes: if i < 0xFD: # 1 byte return bytes([i]) if i <= 0xFFFF: # 2 bytes - return b"\xFD" + i.to_bytes(2, byteorder="little", signed=False) + return b"\xfd" + i.to_bytes(2, byteorder="little", signed=False) if i <= 0xFFFFFFFF: # 4 bytes - return b"\xFE" + i.to_bytes(4, byteorder="little", signed=False) + return b"\xfe" + i.to_bytes(4, byteorder="little", signed=False) if i <= 0xFFFFFFFFFFFFFFFF: # 8 bytes - return b"\xFF" + i.to_bytes(8, byteorder="little", signed=False) + return b"\xff" + i.to_bytes(8, byteorder="little", signed=False) raise BTClibValueError(f"integer too big for var_int encoding: '{hex_string(i)}'") diff --git a/docs/source/conf.py b/docs/source/conf.py index 16a281fb..18c571c6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,7 +10,8 @@ """Configuration file for the Sphinx documentation builder. For the full list of built-in configuration values, see the -documentation: https://www.sphinx- +documentation: +https://www.sphinx- doc.org/en/master/usage/configuration.html """ diff --git a/tests/bip32/test_bip32.py b/tests/bip32/test_bip32.py index 433eb9ca..f631c01f 100644 --- a/tests/bip32/test_bip32.py +++ b/tests/bip32/test_bip32.py @@ -44,7 +44,7 @@ def test_exceptions() -> None: seed = "5b56c417303faa3fcba7e57400e120a0" with pytest.raises(BTClibValueError, match="unknown extended key version: "): - version = b"\x04\x88\xAD\xE5" + version = b"\x04\x88\xad\xe5" rootxprv_from_seed(seed, version) with pytest.raises(BTClibValueError, match="too many bits for seed: "): diff --git a/tests/bip32/test_der_path.py b/tests/bip32/test_der_path.py index e5c8a4e1..d5698a6d 100644 --- a/tests/bip32/test_der_path.py +++ b/tests/bip32/test_der_path.py @@ -9,7 +9,6 @@ # or distributed except according to the terms contained in the LICENSE file. """Tests for the `btclib.bip32_path` module.""" - import pytest from btclib.bip32 import ( diff --git a/tests/ec/test_curve.py b/tests/ec/test_curve.py index a16dc3ca..7a0f43a0 100644 --- a/tests/ec/test_curve.py +++ b/tests/ec/test_curve.py @@ -9,7 +9,6 @@ # or distributed except according to the terms contained in the LICENSE file. """Tests for the `btclib.curve` module.""" - import itertools import json from os import path diff --git a/tests/ecc/test_ssa.py b/tests/ecc/test_ssa.py index 2792a691..846fe43e 100644 --- a/tests/ecc/test_ssa.py +++ b/tests/ecc/test_ssa.py @@ -101,7 +101,7 @@ def test_bip340_vectors() -> None: # skip column headers while checking that there are 7 columns next(reader) for row in reader: - (index, seckey, pub_key, aux_rand, m, sig, result, comment) = row + index, seckey, pub_key, aux_rand, m, sig, result, comment = row err_msg = f"Test vector #{int(index)}" try: if seckey != "": diff --git a/tests/psbt/test_psbt.py b/tests/psbt/test_psbt.py index fd39f5e7..fc76412a 100644 --- a/tests/psbt/test_psbt.py +++ b/tests/psbt/test_psbt.py @@ -62,7 +62,6 @@ def test_vectors_bip174() -> None: def test_vectors_bip371() -> None: """Test https://github.com/bitcoin/bips/blob/master/bip-0371.mediawiki.""" - data_folder = path.join(path.dirname(__file__), "_data") filename = path.join(data_folder, "bip371_test_vectors.json") with open(filename, encoding="ascii") as file_: diff --git a/tests/psbt/test_psbt_out.py b/tests/psbt/test_psbt_out.py index 90f05d4b..f813022c 100644 --- a/tests/psbt/test_psbt_out.py +++ b/tests/psbt/test_psbt_out.py @@ -8,6 +8,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.psbt.psbt_out` module.""" + from __future__ import annotations import json diff --git a/tests/script/test_op_codes_taproot.py b/tests/script/test_op_codes_taproot.py index 143ee9f9..e73625b8 100644 --- a/tests/script/test_op_codes_taproot.py +++ b/tests/script/test_op_codes_taproot.py @@ -9,7 +9,6 @@ # or distributed except according to the terms contained in the LICENSE file. """Tests for the `btclib.script.op_codes_tapscript` module.""" - import pytest from btclib.exceptions import BTClibValueError diff --git a/tests/script/test_script.py b/tests/script/test_script.py index 5e3ec54a..a1efdaeb 100644 --- a/tests/script/test_script.py +++ b/tests/script/test_script.py @@ -60,15 +60,15 @@ def test_op_int() -> None: def test_serialize_bytes_command() -> None: length = 75 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 1 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 2 length = 255 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 2 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 3 diff --git a/tests/script/test_taproot.py b/tests/script/test_taproot.py index 0824982f..094c24fc 100644 --- a/tests/script/test_taproot.py +++ b/tests/script/test_taproot.py @@ -145,15 +145,15 @@ def test_serialize_op_success() -> None: def test_serialize_bytes_command() -> None: length = 75 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 1 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 2 length = 255 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 2 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 3 diff --git a/tests/test_bech32.py b/tests/test_bech32.py index 7eaf639d..3195c922 100644 --- a/tests/test_bech32.py +++ b/tests/test_bech32.py @@ -38,7 +38,6 @@ - checked for raised exceptions instead of assertIsNone """ - import itertools import pytest @@ -72,7 +71,7 @@ def test_bech32() -> None: invalid_checksum = [ ["\x20" + " 1nwldj5", r"HRP character out of range: *"], - ["\x7F" + "1axkwrx", r"HRP character out of range: *"], + ["\x7f" + "1axkwrx", r"HRP character out of range: *"], ["\x80" + "1eym55h", r"HRP character out of range: *"], ["pzry9x0s0muk", r"no separator character: *"], ["1pzry9x0s0muk", r"empty HRP: *"], @@ -129,7 +128,7 @@ def test_bech32m() -> None: invalid_checksum = [ ["\x20" + "1xj0phk", r"HRP character out of range: *"], - ["\x7F" + "1g6xzxy", r"HRP character out of range: *"], + ["\x7f" + "1g6xzxy", r"HRP character out of range: *"], ["\x80" + "1vctc34", r"HRP character out of range: *"], ["qyrz8wqd2c9m", r"no separator character: *"], ["1qyrz8wqd2c9m", r"empty HRP: *"],