test: use `in` for two-value equality asserts
What changed, and why it matters
This commit only rewrites a handful of test-file assertions from the form 'x equals a or x equals b' to the equivalent form 'x is in the set (a, b)'. It does not change any production code, does not alter what the tests check, and has no security relevance for running Bitcoin software.
No action needed; this is a non-security test-only style refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff touches three functional test scripts (interface_zmq.py, p2p_compactblocks.py, wallet_send.py) and replaces assert x == a or x == b patterns with assert x in (a, b). The logic and accepted values remain identical; the change is purely stylistic to avoid a later cleanup pass from touching == forms. No runtime behavior of Bitcoin Core is affected.
Changed components
test/functional/interface_zmq.pytest/functional/p2p_compactblocks.pytest/functional/wallet_send.pyInspect captured patch +6 / −8
diff --git a/test/functional/interface_zmq.py b/test/functional/interface_zmq.py
index 79882a43..f8a6bfc6 100755
--- a/test/functional/interface_zmq.py
+++ b/test/functional/interface_zmq.py
@@ -75,9 +75,9 @@ class ZMQSubscriber:
label = chr(body[32])
mempool_sequence = None if len(body) != 32+1+8 else struct.unpack("<Q", body[32+1:])[0]
if mempool_sequence is not None:
- assert label == "A" or label == "R"
+ assert label in ("A", "R")
else:
- assert label == "D" or label == "C"
+ assert label in ("D", "C")
return (hash, label, mempool_sequence)
@@ -480,7 +480,7 @@ class ZMQTest (BitcoinTestFramework):
while zmq_mem_seq is None:
(hash_str, label, zmq_mem_seq) = seq.receive_sequence()
- assert label == "A" or label == "R"
+ assert label in ("A", "R")
assert hash_str is not None
# 2) We need to "seed" our view of the mempool
diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py
index 48776e7d..ebc83964 100755
--- a/test/functional/p2p_compactblocks.py
+++ b/test/functional/p2p_compactblocks.py
@@ -551,8 +551,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# We should receive a getdata request
test_node.wait_for_getdata([block.hash_int], timeout=10)
- assert test_node.last_message["getdata"].inv[0].type == MSG_BLOCK or \
- test_node.last_message["getdata"].inv[0].type == MSG_BLOCK | MSG_WITNESS_FLAG
+ assert test_node.last_message["getdata"].inv[0].type in (MSG_BLOCK, MSG_BLOCK | MSG_WITNESS_FLAG)
# Deliver the block
test_node.send_and_ping(msg_block(block))
@@ -586,8 +585,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# We should receive a getdata request
test_node.wait_for_getdata([block.hash_int], timeout=10)
- assert test_node.last_message["getdata"].inv[0].type == MSG_BLOCK or \
- test_node.last_message["getdata"].inv[0].type == MSG_BLOCK | MSG_WITNESS_FLAG
+ assert test_node.last_message["getdata"].inv[0].type in (MSG_BLOCK, MSG_BLOCK | MSG_WITNESS_FLAG)
# Send the same blocktxn and assert the sender gets disconnected.
with node.assert_debug_log(['previous compact block reconstruction attempt failed']):
diff --git a/test/functional/wallet_send.py b/test/functional/wallet_send.py
index ab8f74f2..e6a74050 100755
--- a/test/functional/wallet_send.py
+++ b/test/functional/wallet_send.py
@@ -392,7 +392,7 @@ class WalletSendTest(BitcoinTestFramework):
res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, add_to_wallet=False, change_type="legacy", change_position=0)
assert res["complete"]
change_address = self.nodes[0].decodepsbt(res["psbt"])["tx"]["vout"][0]["scriptPubKey"]["address"]
- assert change_address[0] == "m" or change_address[0] == "n"
+ assert change_address[0] in ("m", "n")
self.log.info("Set lock time...")
height = self.nodes[0].getblockchaininfo()["blocks"]
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.