Skip to content

Commit 780bcf8

Browse files
committedMar 20, 2025··
Merge bitcoin/bitcoin#32091: test: replace assert with assert_equal and assert_greater_than
387385b test: replace assert with assert_equal and assert_greater_than (Chandra Pratap) Pull request description: In `test/functional/interface_usdt_net.py`, `assert_equal` is already used to check for equality between objects. Replace `assert.*==` with `assert_equal` and `assert.*>` with `assert_greater_than` to further easify debugging. Relevant issue: #23119 ACKs for top commit: maflcko: lgtm ACK 387385b 0xB10C: had a quick look, lgtm ACK 387385b theStack: utACK 387385b brunoerg: code review ACK 387385b i-am-yuvi: Great! ACK 387385b Tree-SHA512: 741a3d98288c9999f62bcbaa3806716b0519ec9b521e1e6e17aa458392245f6eff886af6cb601c66f2147e0265ff1eae57cea3dcfd67af93bef6dff25b056935
2 parents e568c1d + 387385b commit 780bcf8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
 

‎test/functional/interface_usdt_net.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from test_framework.messages import CBlockHeader, MAX_HEADERS_RESULTS, msg_headers, msg_version
1818
from test_framework.p2p import P2PInterface
1919
from test_framework.test_framework import BitcoinTestFramework
20-
from test_framework.util import assert_equal
20+
from test_framework.util import assert_equal, assert_greater_than
2121

2222
# Tor v3 addresses are 62 chars + 6 chars for the port (':12345').
2323
MAX_PEER_ADDR_LENGTH = 68
@@ -364,8 +364,8 @@ def handle_inbound_connection(_, data, __):
364364

365365
assert_equal(EXPECTED_INBOUND_CONNECTIONS, len(inbound_connections))
366366
for inbound_connection in inbound_connections:
367-
assert inbound_connection.conn.id > 0
368-
assert inbound_connection.existing > 0
367+
assert_greater_than(inbound_connection.conn.id, 0)
368+
assert_greater_than(inbound_connection.existing, 0)
369369
assert_equal(b'inbound', inbound_connection.conn.conn_type)
370370
assert_equal(NETWORK_TYPE_UNROUTABLE, inbound_connection.conn.network)
371371

@@ -405,8 +405,8 @@ def handle_outbound_connection(_, data, __):
405405

406406
assert_equal(EXPECTED_OUTBOUND_CONNECTIONS, len(outbound_connections))
407407
for outbound_connection in outbound_connections:
408-
assert outbound_connection.conn.id > 0
409-
assert outbound_connection.existing > 0
408+
assert_greater_than(outbound_connection.conn.id, 0)
409+
assert_greater_than(outbound_connection.existing, 0)
410410
assert_equal(EXPECTED_CONNECTION_TYPE, outbound_connection.conn.conn_type.decode('utf-8'))
411411
assert_equal(NETWORK_TYPE_UNROUTABLE, outbound_connection.conn.network)
412412

@@ -442,8 +442,8 @@ def handle_evicted_inbound_connection(_, data, __):
442442

443443
assert_equal(EXPECTED_EVICTED_CONNECTIONS, len(evicted_connections))
444444
for evicted_connection in evicted_connections:
445-
assert evicted_connection.conn.id > 0
446-
assert evicted_connection.time_established > 0
445+
assert_greater_than(evicted_connection.conn.id, 0)
446+
assert_greater_than(evicted_connection.time_established, 0)
447447
assert_equal("inbound", evicted_connection.conn.conn_type.decode('utf-8'))
448448
assert_equal(NETWORK_TYPE_UNROUTABLE, evicted_connection.conn.network)
449449

@@ -479,9 +479,9 @@ def handle_misbehaving_connection(_, data, __):
479479

480480
assert_equal(EXPECTED_MISBEHAVING_CONNECTIONS, len(misbehaving_connections))
481481
for misbehaving_connection in misbehaving_connections:
482-
assert misbehaving_connection.id > 0
483-
assert len(misbehaving_connection.message) > 0
484-
assert misbehaving_connection.message == b"headers message size = 2001"
482+
assert_greater_than(misbehaving_connection.id, 0)
483+
assert_greater_than(len(misbehaving_connection.message), 0)
484+
assert_equal(misbehaving_connection.message, b"headers message size = 2001")
485485

486486
bpf.cleanup()
487487

@@ -516,10 +516,10 @@ def handle_closed_connection(_, data, __):
516516

517517
assert_equal(EXPECTED_CLOSED_CONNECTIONS, len(closed_connections))
518518
for closed_connection in closed_connections:
519-
assert closed_connection.conn.id > 0
519+
assert_greater_than(closed_connection.conn.id, 0)
520520
assert_equal("inbound", closed_connection.conn.conn_type.decode('utf-8'))
521521
assert_equal(0, closed_connection.conn.network)
522-
assert closed_connection.time_established > 0
522+
assert_greater_than(closed_connection.time_established, 0)
523523

524524
bpf.cleanup()
525525

0 commit comments

Comments
 (0)
Please sign in to comment.