test: split equality asserts joined by `and`
What changed, and why it matters
This commit only changes Bitcoin Core's internal test code. It splits combined `assert` statements into separate assertions so that when a test fails, the error message points to the exact condition that failed. There is no change to the actual Bitcoin node software that users run, and no security vulnerability is being fixed.
No security action needed. This is a routine test-maintenance refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors three functional test files (rpc_psbt.py, wallet_importdescriptors.py, wallet_miniscript.py) to replace compound boolean assertions joined by and with individual assertions, mostly using assert_equal. This improves test failure diagnostics and removes mixed == expressions ahead of a later cleanup. No production code is modified.
Changed components
test/functional/rpc_psbt.pytest/functional/wallet_importdescriptors.pytest/functional/wallet_miniscript.pyInspect captured patch +27 / −9
diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py
index cc443f6a..7fa6186c 100755
--- a/test/functional/rpc_psbt.py
+++ b/test/functional/rpc_psbt.py
@@ -918,7 +918,10 @@ class PSBTTest(BitcoinTestFramework):
assert "final_scriptwitness" in psbt2_decoded['inputs'][0] and "final_scriptSig" in psbt2_decoded['inputs'][0]
joined = self.nodes[0].joinpsbts([psbt, psbt2])
joined_decoded = self.nodes[0].decodepsbt(joined)
- assert len(joined_decoded['inputs']) == 4 and len(joined_decoded['outputs']) == 2 and "final_scriptwitness" not in joined_decoded['inputs'][3] and "final_scriptSig" not in joined_decoded['inputs'][3]
+ assert_equal(len(joined_decoded['inputs']), 4)
+ assert_equal(len(joined_decoded['outputs']), 2)
+ assert "final_scriptwitness" not in joined_decoded['inputs'][3]
+ assert "final_scriptSig" not in joined_decoded['inputs'][3]
# Check that joining shuffles the inputs and outputs
# 10 attempts should be enough to get a shuffled join
@@ -937,20 +940,31 @@ class PSBTTest(BitcoinTestFramework):
self.generate(self.nodes[0], 6)[0]
psbt = self.nodes[1].createpsbt([utxo], {self.nodes[0].getnewaddress("", "p2sh-segwit"):Decimal('6.999')})
analyzed = self.nodes[0].analyzepsbt(psbt)
- assert not analyzed['inputs'][0]['has_utxo'] and not analyzed['inputs'][0]['is_final'] and analyzed['inputs'][0]['next'] == 'updater' and analyzed['next'] == 'updater'
+ assert not analyzed['inputs'][0]['has_utxo']
+ assert not analyzed['inputs'][0]['is_final']
+ assert_equal(analyzed['inputs'][0]['next'], 'updater')
+ assert_equal(analyzed['next'], 'updater')
# After update with wallet, only needs signing
updated = self.nodes[1].walletprocesspsbt(psbt, False, 'ALL', True)['psbt']
analyzed = self.nodes[0].analyzepsbt(updated)
- assert analyzed['inputs'][0]['has_utxo'] and not analyzed['inputs'][0]['is_final'] and analyzed['inputs'][0]['next'] == 'signer' and analyzed['next'] == 'signer' and analyzed['inputs'][0]['missing']['signatures'][0] == addrinfo['embedded']['witness_program']
+ assert analyzed['inputs'][0]['has_utxo']
+ assert not analyzed['inputs'][0]['is_final']
+ assert_equal(analyzed['inputs'][0]['next'], 'signer')
+ assert_equal(analyzed['next'], 'signer')
+ assert_equal(analyzed['inputs'][0]['missing']['signatures'][0], addrinfo['embedded']['witness_program'])
# Check fee and size things
- assert analyzed['fee'] == Decimal('0.001') and analyzed['estimated_vsize'] == 134 and analyzed['estimated_feerate'] == Decimal('0.00746268')
+ assert_equal(analyzed['fee'], Decimal('0.001'))
+ assert_equal(analyzed['estimated_vsize'], 134)
+ assert_equal(analyzed['estimated_feerate'], Decimal('0.00746268'))
# After signing and finalizing, needs extracting
signed = self.nodes[1].walletprocesspsbt(updated)['psbt']
analyzed = self.nodes[0].analyzepsbt(signed)
- assert analyzed['inputs'][0]['has_utxo'] and analyzed['inputs'][0]['is_final'] and analyzed['next'] == 'extractor'
+ assert analyzed['inputs'][0]['has_utxo']
+ assert analyzed['inputs'][0]['is_final']
+ assert_equal(analyzed['next'], 'extractor')
self.log.info("PSBT spending unspendable outputs should have error message and Creator as next")
analysis = self.nodes[0].analyzepsbt('cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWAEHYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFv8/wADXYP/7//////8JxOh0LR2HAI8AAAAAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHEAABAACAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHENkMak8AAAAA')
diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py
index fdaeae35..bfb25c63 100755
--- a/test/functional/wallet_importdescriptors.py
+++ b/test/functional/wallet_importdescriptors.py
@@ -723,12 +723,14 @@ class ImportDescriptorsTest(BitcoinTestFramework):
try:
self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletlock()
except JSONRPCException as e:
- assert e.error["code"] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before locking the wallet." in e.error["message"]
+ assert_equal(e.error["code"], -4)
+ assert "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before locking the wallet." in e.error["message"]
try:
self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletpassphrasechange("passphrase", "newpassphrase")
except JSONRPCException as e:
- assert e.error["code"] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before changing the passphrase." in e.error["message"]
+ assert_equal(e.error["code"], -4)
+ assert "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before changing the passphrase." in e.error["message"]
assert_equal(importing.result(), [{"success": True}])
diff --git a/test/functional/wallet_miniscript.py b/test/functional/wallet_miniscript.py
index a086cf02..d8059176 100755
--- a/test/functional/wallet_miniscript.py
+++ b/test/functional/wallet_miniscript.py
@@ -243,7 +243,8 @@ class WalletMiniscriptTest(BitcoinTestFramework):
lambda: len(self.ms_wo_wallet.listunspent(minconf=0, addresses=[addr])) == 1
)
utxo = self.ms_wo_wallet.listunspent(minconf=0, addresses=[addr])[0]
- assert utxo["txid"] == txid and utxo["solvable"]
+ assert_equal(utxo["txid"], txid)
+ assert utxo["solvable"]
def signing_test(
self, desc, sequence, locktime, sigs_count, stack_size, sha256_preimages
@@ -271,7 +272,8 @@ class WalletMiniscriptTest(BitcoinTestFramework):
self.wait_until(lambda: txid in self.funder.getrawmempool())
self.funder.generatetoaddress(1, self.funder.getnewaddress())
utxo = self.ms_sig_wallet.listunspent(addresses=[addr])[0]
- assert txid == utxo["txid"] and utxo["solvable"]
+ assert_equal(txid, utxo["txid"])
+ assert utxo["solvable"]
self.log.info("Creating a transaction spending these funds")
dest_addr = self.funder.getnewaddress()
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.