Skip to content

Commit 7d0c486

Browse files
authored
Update blackify version (buidl-bitcoin#142)
Also tweak imports and testing dependency installation
1 parent df85d77 commit 7d0c486

16 files changed

+48
-55
lines changed

.github/workflows/python.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ jobs:
6464
- uses: actions/setup-python@v2
6565
with:
6666
python-version: ${{ matrix.python-version }}
67-
# HACK: Since unit tests are super slow, we only install pytest and not the rest of the testing dependencies
68-
- name: Install pytest
67+
- name: Install python testing dependencies
6968
run: |
70-
python -m pip install pytest==6.2.5
69+
pip install -r requirements-test.txt
7170
- name: pytest unit tests
7271
run: |
7372
pytest -v buidl/test

buidl/bech32.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
BECH32M_CONSTANT = 0x2BC830A3
1313

1414
PREFIX = {
15-
'mainnet': 'bc',
16-
'testnet': 'tb',
17-
'regtest': 'bcrt',
18-
'signet': 'tb',
15+
"mainnet": "bc",
16+
"testnet": "tb",
17+
"regtest": "bcrt",
18+
"signet": "tb",
1919
}
20-
NET_FOR_PREFIX = {v: k for k, v in PREFIX.items() if k != 'signet'}
20+
NET_FOR_PREFIX = {v: k for k, v in PREFIX.items() if k != "signet"}
2121

2222

2323
def uses_only_bech32_chars(string):
@@ -188,7 +188,7 @@ def encode_bech32_checksum(s, network="mainnet"):
188188

189189
def decode_bech32(s):
190190
"""Returns network, segwit version and the hash from the bech32 address"""
191-
regtest_prefix = PREFIX['regtest']
191+
regtest_prefix = PREFIX["regtest"]
192192
if s.startswith(regtest_prefix):
193193
hrp, raw_data = regtest_prefix, s[5:]
194194
else:

buidl/blinding.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def secure_secret_path(depth=4):
3030
to_return = ["m"]
3131
for _ in range(depth):
3232
# https://bitcoin.stackexchange.com/questions/92056/what-is-the-max-allowed-depth-for-bip32-derivation-paths#comment105756_92057
33-
rand_int = randbelow(2 ** 31 - 1)
33+
rand_int = randbelow(2**31 - 1)
3434
to_return.append(str(rand_int))
3535
return "/".join(to_return)
3636

buidl/cecc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
),
2020
lib.secp256k1_context_destroy,
2121
)
22-
P = 2 ** 256 - 2 ** 32 - 977
22+
P = 2**256 - 2**32 - 977
2323
N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
2424

2525

buidl/compactfilter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
BASIC_FILTER_TYPE = 0
1414
GOLOMB_P = 19
15-
GOLOMB_M = int(round(1.497137 * 2 ** GOLOMB_P))
15+
GOLOMB_M = int(round(1.497137 * 2**GOLOMB_P))
1616

1717

1818
def _siphash(key, value):

buidl/hd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def is_valid_bip32_path(path):
779779
return False
780780
if int(sub_path) < 0:
781781
return False
782-
if int(sub_path) >= 2 ** 31:
782+
if int(sub_path) >= 2**31:
783783
# https://bitcoin.stackexchange.com/a/92057
784784
return False
785785

buidl/helper.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def _siphash(key, value):
1313
raise ValueError("Key should be 16 bytes")
1414
return little_endian_to_int(siphash24(key, value))
1515

16-
1716
except ModuleNotFoundError:
1817
from buidl.siphash import SipHash_2_4
1918

@@ -33,7 +32,7 @@ def _siphash(key, value):
3332
BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
3433
PBKDF2_ROUNDS = 2048
3534
GOLOMB_P = 19
36-
GOLOMB_M = int(round(1.497137 * 2 ** GOLOMB_P))
35+
GOLOMB_M = int(round(1.497137 * 2**GOLOMB_P))
3736
TWO_WEEKS = 60 * 60 * 24 * 14
3837
MAX_TARGET = 0xFFFF * 256 ** (0x1D - 3)
3938

buidl/network.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __init__(
125125
self.sender_ip = sender_ip
126126
self.sender_port = sender_port
127127
if nonce is None:
128-
self.nonce = int_to_little_endian(randint(0, 2 ** 64), 8)
128+
self.nonce = int_to_little_endian(randint(0, 2**64), 8)
129129
else:
130130
self.nonce = nonce
131131
self.user_agent = user_agent

buidl/pecc.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(self, x, y, a, b):
113113
return
114114
# make sure that the elliptic curve equation is satisfied
115115
# y**2 == x**3 + a*x + b
116-
if self.y ** 2 != self.x ** 3 + a * x + b:
116+
if self.y**2 != self.x**3 + a * x + b:
117117
# if not, raise a ValueError
118118
raise ValueError(f"({self.x}, {self.y}) is not on the curve")
119119

@@ -158,7 +158,7 @@ def __add__(self, other):
158158
# s=(y2-y1)/(x2-x1)
159159
s = (other.y - self.y) / (other.x - self.x)
160160
# x3=s**2-x1-x2
161-
x = s ** 2 - self.x - other.x
161+
x = s**2 - self.x - other.x
162162
# y3=s*(x1-x3)-y1
163163
y = s * (self.x - x) - self.y
164164
return self.__class__(x, y, self.a, self.b)
@@ -167,9 +167,9 @@ def __add__(self, other):
167167
else:
168168
# Formula (x3,y3)=(x1,y1)+(x1,y1)
169169
# s=(3*x1**2+a)/(2*y1)
170-
s = (3 * self.x ** 2 + self.a) / (2 * self.y)
170+
s = (3 * self.x**2 + self.a) / (2 * self.y)
171171
# x3=s**2-2*x1
172-
x = s ** 2 - 2 * self.x
172+
x = s**2 - 2 * self.x
173173
# y3=s*(x1-x3)-y1
174174
y = s * (self.x - x) - self.y
175175
return self.__class__(x, y, self.a, self.b)
@@ -192,7 +192,7 @@ def __rmul__(self, coefficient):
192192

193193
A = 0
194194
B = 7
195-
P = 2 ** 256 - 2 ** 32 - 977
195+
P = 2**256 - 2**32 - 977
196196
N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
197197

198198

@@ -384,7 +384,7 @@ def parse_sec(cls, sec_bin):
384384
is_even = sec_bin[0] == 2
385385
x = S256Field(int(sec_bin[1:].hex(), 16))
386386
# right side of the equation y^2 = x^3 + 7
387-
alpha = x ** 3 + S256Field(B)
387+
alpha = x**3 + S256Field(B)
388388
# solve for left side
389389
beta = alpha.sqrt()
390390
if beta.num % 2 == 0:
@@ -407,7 +407,7 @@ def parse_bip340(cls, bip340_bin):
407407
return cls(None, None)
408408
x = S256Field(n)
409409
# right side of the equation y^2 = x^3 + 7
410-
alpha = x ** 3 + S256Field(B)
410+
alpha = x**3 + S256Field(B)
411411
# solve for left side
412412
beta = alpha.sqrt()
413413
if beta.num % 2 == 1:

buidl/test/test_ecc.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def test_pubpoint(self):
2222
"04C982196A7466FBBBB0E27A940B6AF926C1A74D5AD07128C82824A11B5398AFDA7A91F9EAE64438AFB9CE6448A1C133DB2D8FB9254E4546B6F001637D50901F55",
2323
),
2424
(
25-
2 ** 128,
25+
2**128,
2626
"048F68B9D2F63B5F339239C1AD981F162EE88C5678723EA3351B7B444C9EC4C0DA662A9F2DBA063986DE1D90C2B6BE215DBBEA2CFE95510BFDF23CBF79501FFF82",
2727
),
2828
(
29-
2 ** 240 + 2 ** 31,
29+
2**240 + 2**31,
3030
"049577FF57C8234558F293DF502CA4F09CBC65A6572C842B39B366F2171794511610B49C67FA9365AD7B90DAB070BE339A1DAF9052373EC30FFAE4F72D5E66D053",
3131
),
3232
)
@@ -45,7 +45,7 @@ def test_pubpoint(self):
4545
self.assertEqual(sum_secrets * G, S256Point.combine(point_objects))
4646

4747
def test_sec(self):
48-
coefficient = 999 ** 3
48+
coefficient = 999**3
4949
uncompressed = "049d5ca49670cbe4c3bfa84c96a8c87df086c6ea6a24ba6b809c9de234496808d56fa15cc7f3d38cda98dee2419f415b7513dde1301f8643cd9245aea7f3f911f9"
5050
compressed = (
5151
"039d5ca49670cbe4c3bfa84c96a8c87df086c6ea6a24ba6b809c9de234496808d5"
@@ -73,7 +73,7 @@ def test_sec(self):
7373
def test_address(self):
7474
tests = (
7575
(
76-
888 ** 3,
76+
888**3,
7777
"148dY81A9BmdpMhvYEVznrM45kWN32vSCN",
7878
"mnabU9NCcRE5zcNZ2C16CnvKPELrFvisn3",
7979
),
@@ -101,7 +101,7 @@ def test_address(self):
101101
def test_p2wpkh_address(self):
102102
tests = (
103103
(
104-
888 ** 3,
104+
888**3,
105105
"bc1qyfvunnpszmjwcqgfk9dsne6j4edq3fglx9y5x7",
106106
"tb1qyfvunnpszmjwcqgfk9dsne6j4edq3fglvrl8ad",
107107
),
@@ -126,7 +126,7 @@ def test_p2wpkh_address(self):
126126
def test_p2sh_p2wpkh_address(self):
127127
tests = (
128128
(
129-
888 ** 3,
129+
888**3,
130130
"32cE3VHX5k1Z4gDCJBXMSLgd1akUzvqNvH",
131131
"2MtAS7EDYhCWuGTqjyK9E4HftDvxek7ELQn",
132132
),

buidl/test/test_mnemonic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_secure_mnemonic_extra_entropy(self):
3030
# num_bits, num_words, extra_entropy
3131
(128, 12, 0),
3232
(160, 15, 1),
33-
(192, 18, 2 ** 128),
34-
(224, 21, 2 ** 256),
35-
(256, 24, 2 ** 512),
33+
(192, 18, 2**128),
34+
(224, 21, 2**256),
35+
(256, 24, 2**512),
3636
)
3737

3838
for num_bits, num_words, extra_entropy in tests:

buidl/test/test_network.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from unittest import TestCase
2-
import unittest # for skipunless
3-
41
from io import BytesIO
52
from os import getenv
3+
from unittest import TestCase, skipUnless
64

75
from buidl.block import Block
86
from buidl.bloomfilter import BloomFilter
@@ -100,9 +98,9 @@ def test_serialize(self):
10098
self.assertEqual(get_data.serialize().hex(), hex_msg)
10199

102100

103-
@unittest.skipUnless(
101+
@skipUnless(
104102
getenv("INCLUDE_NETWORK_TESTS"),
105-
reason="Requires network connection, so may not be unreliable",
103+
reason="Requires (unreliable) network connection",
106104
)
107105
class SimpleNodeTest(TestCase):
108106
def test_handshake(self):

buidl/test/test_pecc.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ def test_mul(self):
3535

3636
def test_pow(self):
3737
a = FieldElement(17, 31)
38-
self.assertEqual(a ** 3, FieldElement(15, 31))
38+
self.assertEqual(a**3, FieldElement(15, 31))
3939
a = FieldElement(5, 31)
4040
b = FieldElement(18, 31)
41-
self.assertEqual(a ** 5 * b, FieldElement(16, 31))
41+
self.assertEqual(a**5 * b, FieldElement(16, 31))
4242

4343
def test_div(self):
4444
a = FieldElement(3, 31)
4545
b = FieldElement(24, 31)
4646
self.assertEqual(a / b, FieldElement(4, 31))
4747
a = FieldElement(17, 31)
48-
self.assertEqual(a ** -3, FieldElement(29, 31))
48+
self.assertEqual(a**-3, FieldElement(29, 31))
4949
a = FieldElement(4, 31)
5050
b = FieldElement(11, 31)
51-
self.assertEqual(a ** -4 * b, FieldElement(13, 31))
51+
self.assertEqual(a**-4 * b, FieldElement(13, 31))
5252

5353

5454
class PointTest(TestCase):

buidl/test/test_tx.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from buidl.ecc import PrivateKey, Signature
22
from buidl.script import RedeemScript, WitnessScript
3-
from buidl.tx import Tx, TxIn, TxOut, TxFetcher
4-
53
from buidl.test import OfflineTestCase
4+
from buidl.tx import Tx, TxIn, TxOut, TxFetcher
65

7-
import unittest # for skipUnless
86
from os import getenv
7+
from unittest import skipUnless
98
from urllib.error import HTTPError
109

1110

@@ -429,11 +428,11 @@ def test_coinbase_height(self):
429428
self.assertIsNone(tx.coinbase_height())
430429

431430

431+
@skipUnless(
432+
getenv("INCLUDE_NETWORK_TESTS"),
433+
reason="Requires (unreliable) network connection",
434+
)
432435
class TxFetcherTest(OfflineTestCase):
433-
@unittest.skipUnless(
434-
getenv("INCLUDE_NETWORK_TESTS"),
435-
reason="Requires network connection, so may not be unreliable",
436-
)
437436
def test_broadcast_duplicate_tx_spent_signet(self):
438437
tx_hex = "020000000001017bf99a29dd2f9968ca9a075e85b43a638b600bcc49fd9ba0ac8eaf2fa8d851330000000000feffffff02a0860100000000001600149253a4d3d120add0ddd578a5cca6139891503cb917ef7d9c4f060000160014f59bb0a324f3f6026574c1186b4f7e82de9ed77e0247304402201d7531c7aff722a10f4c97ea52bd10ae48dda497d514d0c8d491e80c9981daa0022036b67fb050b0e503ebba71578e2f5c35118b4f0cfa65f0ded1605c896e3c09ce012102eb882bb156e79619d5cd9089be277b39980830030e2ee2c5a07deed3fa1aba7ff9940100"
439438

@@ -443,10 +442,6 @@ def test_broadcast_duplicate_tx_spent_signet(self):
443442
self.assertEqual(400, fail.exception.code)
444443
self.assertIn("missingorspent", fail.exception.read().decode())
445444

446-
@unittest.skipUnless(
447-
getenv("INCLUDE_NETWORK_TESTS"),
448-
reason="Requires network connection, so may not be unreliable",
449-
)
450445
def test_broadcast_duplicate_tx_spent_testnet(self):
451446
tx_hex = "020000000001018b526b2fecec943908bbc2e61edbbe8182af32cdfaac3f3f97a07550c0221bc800000000171600145d2f5871d3b1c9a72e86071645fbff06634cdc00feffffff028c12d10300000000160014b2f894963b3bdb3dcf46e0eb06817aa0fd65cda050c30000000000001600143d9e1c6c27c4dd45816cedb9334672da6eea27a102473044022000f991d8a8556efa902a482c836557bde98fece79ed428b248d23480315e24780220461d4fc104d1af74967ba6a2ecd994746b243bf2c74b55ee25e6d170e778caa3012102fdd06a74d4791846e0f86239c7dbbf208afc7eb6108620b8ee842ebab1b1c6f2c4b72300"
452447

buidl/tx.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def dump_cache(cls, filename):
9292
def sendrawtransaction(cls, signed_tx_hex_str, network="mainnet"):
9393
"""Broadcasts a signed transaction."""
9494
url = "{}/tx".format(cls.get_url(network=network))
95-
req = Request(url, data=signed_tx_hex_str.encode(), headers={"User-Agent": "Mozilla/5.0"})
95+
req = Request(
96+
url, data=signed_tx_hex_str.encode(), headers={"User-Agent": "Mozilla/5.0"}
97+
)
9698
response = urlopen(req)
9799
return response.read().decode("utf-8") # returns the txid if successful
98100

requirements-test.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
black==21.10b0
2-
flake8==3.8.4
1+
black==22.6.0
2+
flake8==5.0.4
33
pexpect==4.8.0
44
pytest==6.2.5

0 commit comments

Comments
 (0)