Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit fedfa2e

Browse files
committed
test - typos and improvements from PR review
1 parent ab75ff4 commit fedfa2e

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

test/common/unit/net/test_bolt1.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99

1010
def test_message():
11-
# Messages are built from a message_type (bytes) a payload (bytes) an a optional list of TLVRecords
11+
# Messages are built from a message_type (bytes) a payload (bytes), and an optional list of TLVRecords
1212
mtype = b"\x00"
1313
payload = b"\x00\x01\x02"
1414
extension = []
1515
m = Message(mtype, payload, extension)
1616
assert isinstance(m, Message)
17-
assert m.type == mtype and m.payload == payload and m.extension is None
17+
assert m.type == mtype and m.payload == payload and m.extension == []
1818

1919
# Same with some tlvs
2020
extension = [TLVRecord(), NetworksTLV()]
@@ -43,7 +43,7 @@ def test_message_wrong_types():
4343

4444
def test_message_from_bytes():
4545
# From bytes builds an instance of a children class as long as the type is known, raises ValueError otherwise
46-
# Not testing particular cases for the children since they will be covered in their own tests
46+
# Not testing particular cases for the child classes since they will be covered in their own tests
4747

4848
# Init
4949
m = b"\x00\x10\x00\x00\x00\x00"
@@ -77,7 +77,7 @@ def test_message_from_bytes_wrong():
7777

7878

7979
def test_message_serialize():
80-
# Serialize returns the concatenation opf the byte representation of each field:
80+
# Serialize returns the concatenation of the byte representation of each field:
8181
# type + payload + [extension]
8282

8383
# No extension
@@ -162,7 +162,7 @@ def test_init_message_from_bytes_wrong():
162162

163163
# Message is not long enough < 6
164164
with pytest.raises(ValueError, match="message be must at least 6-byte long"):
165-
InitMessage.from_bytes(b"\x00\x10\x00")
165+
InitMessage.from_bytes(b"\x00\x10\x00\x01\x02")
166166

167167
# Type is not init
168168
with pytest.raises(ValueError, match="Wrong message format. types do not match"):
@@ -179,7 +179,7 @@ def test_error_message():
179179
em = ErrorMessage(cid)
180180
assert isinstance(em, ErrorMessage)
181181
assert em.channel_id == cid
182-
assert em.data is None
182+
assert not em.data
183183

184184
# Same with associated data
185185
data = "error message data"
@@ -191,7 +191,7 @@ def test_error_message():
191191

192192
def test_error_message_wrong():
193193
# Channel id must be a 32-byte hex str
194-
# Data must be string if set and no longer than the message cap size when encoded pow(2, 16)
194+
# Data must be string if set and no longer than the message cap size when encoded pow(2, 16) - 1
195195

196196
# Wrong channel id
197197
with pytest.raises(ValueError, match="channel_id must be a 256-bit hex string"):
@@ -205,8 +205,8 @@ def test_error_message_wrong():
205205
ErrorMessage(get_random_value_hex(32), b"message")
206206

207207
# Data too long
208-
with pytest.raises(ValueError, match=f"Encoded data length cannot be bigger than {pow(2, 16)}"):
209-
ErrorMessage(get_random_value_hex(32), "A" * (pow(2, 16) + 1))
208+
with pytest.raises(ValueError, match=f"Encoded data length cannot be bigger than {pow(2, 16) - 1}"):
209+
ErrorMessage(get_random_value_hex(32), "A" * (pow(2, 16)))
210210

211211

212212
def test_error_from_bytes():
@@ -218,7 +218,7 @@ def test_error_from_bytes():
218218
em = ErrorMessage.from_bytes(mtype + cid + data_len)
219219
assert isinstance(em, ErrorMessage)
220220
assert em.channel_id == cid.hex()
221-
assert em.data is None
221+
assert not em.data
222222

223223
# Same with associated data
224224
data = "message"
@@ -236,7 +236,7 @@ def test_error_from_bytes_wrong():
236236

237237
# Message is not long enough < 36
238238
with pytest.raises(ValueError, match="message be must at least 36-byte long"):
239-
ErrorMessage.from_bytes(b"\x00\x11\x00\x01")
239+
ErrorMessage.from_bytes(b"\x00\x11" + bytes(33))
240240

241241
# Type is not error
242242
with pytest.raises(ValueError, match="Wrong message format. types do not match"):
@@ -252,7 +252,7 @@ def test_error_from_bytes_wrong():
252252

253253

254254
def test_ping_message():
255-
# Ping expects a number of pong bytes and optionally a some ignored data (bytes)
255+
# Ping expects a number of pong bytes and optionally some ignored data (bytes)
256256
num_pong_bytes = 10
257257
pm = PingMessage(num_pong_bytes)
258258
assert isinstance(pm, PingMessage)
@@ -291,7 +291,7 @@ def test_ping_message_from_bytes():
291291
pm = PingMessage.from_bytes(mtype + num_pong_bytes + bytes_len)
292292
assert isinstance(pm, PingMessage)
293293
assert pm.num_pong_bytes == int.from_bytes(num_pong_bytes, "big")
294-
assert pm.ignored_bytes is None
294+
assert not pm.ignored_bytes
295295

296296
# Same with some ignored data
297297
ignored_data = b"\x00\x01\x02\x03"
@@ -309,7 +309,7 @@ def test_ping_message_from_bytes_wrong():
309309

310310
# Message is not long enough < 6
311311
with pytest.raises(ValueError, match="message be must at least 6-byte long"):
312-
PingMessage.from_bytes(b"\x00\x12\x00\x01")
312+
PingMessage.from_bytes(b"\x00\x12\x00\x01\x02")
313313

314314
# Type is not ping
315315
with pytest.raises(ValueError, match="Wrong message format. types do not match"):
@@ -325,10 +325,10 @@ def test_ping_message_from_bytes_wrong():
325325

326326

327327
def test_pong_message():
328-
# Pong can be empty, and optionally can receive so ignored bytes
328+
# Pong can be empty, and optionally can receive some ignored bytes
329329
pm = PongMessage()
330330
assert isinstance(pm, PongMessage)
331-
assert pm.ignored_bytes is None
331+
assert not pm.ignored_bytes
332332

333333
# With some ignored_bytes
334334
ignored_bytes = b"\x00\x02\x06"
@@ -353,7 +353,7 @@ def test_pong_message_from_bytes():
353353
bytes_len = b"\x00\x00"
354354
pm = PongMessage.from_bytes(mtype + bytes_len)
355355
assert isinstance(pm, PongMessage)
356-
assert pm.ignored_bytes is None
356+
assert not pm.ignored_bytes
357357

358358
# Add some ignored data
359359
ignored_data = b"\x03\xfd\xef"

test/common/unit/net/test_bolt9.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
def test_feature():
6-
# Features expect two params, a integer representing the bit of the feature and a boolean with whether that bit
6+
# Features expect two params, an integer representing the bit of the feature and a boolean with whether that bit
77
# is set or not.
88
odd_feature_set = Feature(1, True)
99
assert odd_feature_set.bit == 1
@@ -97,7 +97,7 @@ def test_feature_vector_from_bytes():
9797
assert fv_all_odd.option_anchor_outputs.is_set and fv_all_odd.option_anchor_outputs.is_odd
9898
assert fv_all_odd.serialize() == f_all_odd
9999

100-
# All eve features (but initial_routing_sync)
100+
# All even features (but initial_routing_sync)
101101
f_all_even = b"\x15\x55\x59"
102102
fv_all_even = FeatureVector.from_bytes(f_all_even)
103103
assert fv_all_even.option_data_loss_protect.is_set and not fv_all_even.option_data_loss_protect.is_odd

test/common/unit/net/test_tlv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_tlv_record():
2121

2222

2323
def test_tlv_record_len():
24-
# The TLV length is defined as the length of it's serialized fields
24+
# The TLV length is defined as the length of its serialized fields
2525
t = b"\x01"
2626
l = b"\x02"
2727
v = b"\x03"
@@ -30,7 +30,7 @@ def test_tlv_record_len():
3030

3131

3232
def test_tlv_record_from_bytes():
33-
# from_bytes builds a children class depending on the data type. Currently it only supports Networks
33+
# from_bytes builds an instance of a child class depending on the data type. Currently it only supports Networks.
3434

3535
# NetworksTLV
3636
t = bigsize.encode(1)

0 commit comments

Comments
 (0)