Skip to content

Commit 7d0c486

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

File tree

16 files changed

+48
-55
lines changed

16 files changed

+48
-55
lines changed

.github/workflows/python.yml

Lines changed: 2 additions & 3 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 6 additions & 6 deletions
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
),

0 commit comments

Comments
 (0)