Merge bitcoin/bitcoin#32091: test: replace assert with assert_equal and assert_greater_than

387385ba1e 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 387385ba1e
  0xB10C:
    had a quick look, lgtm ACK 387385ba1e
  theStack:
    utACK 387385ba1e
  brunoerg:
    code review ACK 387385ba1e
  i-am-yuvi:
    Great! ACK 387385ba1e

Tree-SHA512: 741a3d98288c9999f62bcbaa3806716b0519ec9b521e1e6e17aa458392245f6eff886af6cb601c66f2147e0265ff1eae57cea3dcfd67af93bef6dff25b056935
This commit is contained in:
merge-script 2025-03-20 12:59:35 +08:00
commit 780bcf80b5
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -17,7 +17,7 @@ except ImportError:
from test_framework.messages import CBlockHeader, MAX_HEADERS_RESULTS, msg_headers, msg_version from test_framework.messages import CBlockHeader, MAX_HEADERS_RESULTS, msg_headers, msg_version
from test_framework.p2p import P2PInterface from test_framework.p2p import P2PInterface
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal from test_framework.util import assert_equal, assert_greater_than
# Tor v3 addresses are 62 chars + 6 chars for the port (':12345'). # Tor v3 addresses are 62 chars + 6 chars for the port (':12345').
MAX_PEER_ADDR_LENGTH = 68 MAX_PEER_ADDR_LENGTH = 68
@ -364,8 +364,8 @@ class NetTracepointTest(BitcoinTestFramework):
assert_equal(EXPECTED_INBOUND_CONNECTIONS, len(inbound_connections)) assert_equal(EXPECTED_INBOUND_CONNECTIONS, len(inbound_connections))
for inbound_connection in inbound_connections: for inbound_connection in inbound_connections:
assert inbound_connection.conn.id > 0 assert_greater_than(inbound_connection.conn.id, 0)
assert inbound_connection.existing > 0 assert_greater_than(inbound_connection.existing, 0)
assert_equal(b'inbound', inbound_connection.conn.conn_type) assert_equal(b'inbound', inbound_connection.conn.conn_type)
assert_equal(NETWORK_TYPE_UNROUTABLE, inbound_connection.conn.network) assert_equal(NETWORK_TYPE_UNROUTABLE, inbound_connection.conn.network)
@ -405,8 +405,8 @@ class NetTracepointTest(BitcoinTestFramework):
assert_equal(EXPECTED_OUTBOUND_CONNECTIONS, len(outbound_connections)) assert_equal(EXPECTED_OUTBOUND_CONNECTIONS, len(outbound_connections))
for outbound_connection in outbound_connections: for outbound_connection in outbound_connections:
assert outbound_connection.conn.id > 0 assert_greater_than(outbound_connection.conn.id, 0)
assert outbound_connection.existing > 0 assert_greater_than(outbound_connection.existing, 0)
assert_equal(EXPECTED_CONNECTION_TYPE, outbound_connection.conn.conn_type.decode('utf-8')) assert_equal(EXPECTED_CONNECTION_TYPE, outbound_connection.conn.conn_type.decode('utf-8'))
assert_equal(NETWORK_TYPE_UNROUTABLE, outbound_connection.conn.network) assert_equal(NETWORK_TYPE_UNROUTABLE, outbound_connection.conn.network)
@ -442,8 +442,8 @@ class NetTracepointTest(BitcoinTestFramework):
assert_equal(EXPECTED_EVICTED_CONNECTIONS, len(evicted_connections)) assert_equal(EXPECTED_EVICTED_CONNECTIONS, len(evicted_connections))
for evicted_connection in evicted_connections: for evicted_connection in evicted_connections:
assert evicted_connection.conn.id > 0 assert_greater_than(evicted_connection.conn.id, 0)
assert evicted_connection.time_established > 0 assert_greater_than(evicted_connection.time_established, 0)
assert_equal("inbound", evicted_connection.conn.conn_type.decode('utf-8')) assert_equal("inbound", evicted_connection.conn.conn_type.decode('utf-8'))
assert_equal(NETWORK_TYPE_UNROUTABLE, evicted_connection.conn.network) assert_equal(NETWORK_TYPE_UNROUTABLE, evicted_connection.conn.network)
@ -479,9 +479,9 @@ class NetTracepointTest(BitcoinTestFramework):
assert_equal(EXPECTED_MISBEHAVING_CONNECTIONS, len(misbehaving_connections)) assert_equal(EXPECTED_MISBEHAVING_CONNECTIONS, len(misbehaving_connections))
for misbehaving_connection in misbehaving_connections: for misbehaving_connection in misbehaving_connections:
assert misbehaving_connection.id > 0 assert_greater_than(misbehaving_connection.id, 0)
assert len(misbehaving_connection.message) > 0 assert_greater_than(len(misbehaving_connection.message), 0)
assert misbehaving_connection.message == b"headers message size = 2001" assert_equal(misbehaving_connection.message, b"headers message size = 2001")
bpf.cleanup() bpf.cleanup()
@ -516,10 +516,10 @@ class NetTracepointTest(BitcoinTestFramework):
assert_equal(EXPECTED_CLOSED_CONNECTIONS, len(closed_connections)) assert_equal(EXPECTED_CLOSED_CONNECTIONS, len(closed_connections))
for closed_connection in closed_connections: for closed_connection in closed_connections:
assert closed_connection.conn.id > 0 assert_greater_than(closed_connection.conn.id, 0)
assert_equal("inbound", closed_connection.conn.conn_type.decode('utf-8')) assert_equal("inbound", closed_connection.conn.conn_type.decode('utf-8'))
assert_equal(0, closed_connection.conn.network) assert_equal(0, closed_connection.conn.network)
assert closed_connection.time_established > 0 assert_greater_than(closed_connection.time_established, 0)
bpf.cleanup() bpf.cleanup()