From 06a4176c420c1b469adebcae147694e2f46e6644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Tue, 7 Apr 2026 16:25:07 +0300 Subject: [PATCH] test: convert truthy asserts in `wallet_miniscript` and `rpc_psbt` Replace the last remaining truthy asserts (and a remaining `is False`) in `wallet_miniscript.py` and `rpc_psbt.py` with `assert_equal`. Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> --- test/functional/rpc_psbt.py | 32 ++++++++++++++-------------- test/functional/wallet_miniscript.py | 14 ++++++------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 7fa6186c7b8..56c0051477d 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -96,7 +96,7 @@ class PSBTTest(BitcoinTestFramework): # Check that the walletprocesspsbt call succeeds but also recognizes that the transaction is not complete signed_psbt_incomplete = wallet.walletprocesspsbt(psbt=signed_psbt_obj.to_base64(), finalize=False) - assert signed_psbt_incomplete["complete"] is False + assert_equal(signed_psbt_incomplete["complete"], False) def test_utxo_conversion(self): self.log.info("Check that non-witness UTXOs are removed for segwit v1+ inputs") @@ -940,16 +940,16 @@ 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'] - assert not analyzed['inputs'][0]['is_final'] + assert_equal(analyzed['inputs'][0]['has_utxo'], False) + assert_equal(analyzed['inputs'][0]['is_final'], False) 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'] - assert not analyzed['inputs'][0]['is_final'] + assert_equal(analyzed['inputs'][0]['has_utxo'], True) + assert_equal(analyzed['inputs'][0]['is_final'], False) assert_equal(analyzed['inputs'][0]['next'], 'signer') assert_equal(analyzed['next'], 'signer') assert_equal(analyzed['inputs'][0]['missing']['signatures'][0], addrinfo['embedded']['witness_program']) @@ -962,8 +962,8 @@ class PSBTTest(BitcoinTestFramework): # 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'] - assert analyzed['inputs'][0]['is_final'] + assert_equal(analyzed['inputs'][0]['has_utxo'], True) + assert_equal(analyzed['inputs'][0]['is_final'], True) assert_equal(analyzed['next'], 'extractor') self.log.info("PSBT spending unspendable outputs should have error message and Creator as next") @@ -998,7 +998,7 @@ class PSBTTest(BitcoinTestFramework): # Make a weird but signable script. sh(wsh(pkh())) descriptor accomplishes this desc = descsum_create("sh(wsh(pkh({})))".format(privkey)) res = self.nodes[0].importdescriptors([{"desc": desc, "timestamp": "now"}]) - assert res[0]["success"] + assert_equal(res[0]["success"], True) addr = self.nodes[0].deriveaddresses(desc)[0] addr_info = self.nodes[0].getaddressinfo(addr) @@ -1013,15 +1013,15 @@ class PSBTTest(BitcoinTestFramework): # But funding should work when the solving data is provided psbt = wallet.walletcreatefundedpsbt([ext_utxo], {self.nodes[0].getnewaddress(): 15}, 0, {"add_inputs": True, "solving_data": {"pubkeys": [addr_info['pubkey']], "scripts": [addr_info["embedded"]["scriptPubKey"], addr_info["embedded"]["embedded"]["scriptPubKey"]]}}) signed = wallet.walletprocesspsbt(psbt['psbt']) - assert not signed['complete'] + assert_equal(signed['complete'], False) signed = self.nodes[0].walletprocesspsbt(signed['psbt']) - assert signed['complete'] + assert_equal(signed['complete'], True) psbt = wallet.walletcreatefundedpsbt([ext_utxo], {self.nodes[0].getnewaddress(): 15}, 0, {"add_inputs": True, "solving_data":{"descriptors": [desc]}}) signed = wallet.walletprocesspsbt(psbt['psbt']) - assert not signed['complete'] + assert_equal(signed['complete'], False) signed = self.nodes[0].walletprocesspsbt(signed['psbt']) - assert signed['complete'] + assert_equal(signed['complete'], True) final = signed['hex'] dec = self.nodes[0].decodepsbt(signed["psbt"]) @@ -1055,7 +1055,7 @@ class PSBTTest(BitcoinTestFramework): signed = wallet.walletprocesspsbt(psbt["psbt"]) signed = self.nodes[0].walletprocesspsbt(signed["psbt"]) final = signed["hex"] - assert self.nodes[0].testmempoolaccept([final])[0]["allowed"] + assert_equal(self.nodes[0].testmempoolaccept([final])[0]["allowed"], True) # Reducing the weight should have a lower fee psbt2 = wallet.walletcreatefundedpsbt( inputs=[{"txid": ext_utxo["txid"], "vout": ext_utxo["vout"], "weight": low_input_weight}], @@ -1080,7 +1080,7 @@ class PSBTTest(BitcoinTestFramework): # Import the external utxo descriptor so that we can sign for it from the test wallet res = wallet.importdescriptors([{"desc": desc, "timestamp": "now"}]) - assert res[0]["success"] + assert_equal(res[0]["success"], True) # The provided weight should override the calculated weight for a wallet input psbt3 = wallet.walletcreatefundedpsbt( inputs=[{"txid": ext_utxo["txid"], "vout": ext_utxo["vout"], "weight": high_input_weight}], @@ -1097,7 +1097,7 @@ class PSBTTest(BitcoinTestFramework): desc = descsum_create("wsh(pkh({}))".format(pubkey.hex())) res = watchonly.importdescriptors([{"desc": desc, "timestamp": "now"}]) - assert res[0]["success"] + assert_equal(res[0]["success"], True) addr = self.nodes[0].deriveaddresses(desc)[0] self.nodes[0].sendtoaddress(addr, 10) self.generate(self.nodes[0], 1) @@ -1112,7 +1112,7 @@ class PSBTTest(BitcoinTestFramework): desc = descsum_create("tr({},pk({}))".format(H_POINT, pubkey.hex())) res = watchonly.importdescriptors([{"desc": desc, "timestamp": "now"}]) - assert res[0]["success"] + assert_equal(res[0]["success"], True) addr = self.nodes[0].deriveaddresses(desc)[0] self.nodes[0].sendtoaddress(addr, 10) self.generate(self.nodes[0], 1) diff --git a/test/functional/wallet_miniscript.py b/test/functional/wallet_miniscript.py index d8059176398..f3e5a0f82f5 100755 --- a/test/functional/wallet_miniscript.py +++ b/test/functional/wallet_miniscript.py @@ -213,7 +213,7 @@ class WalletMiniscriptTest(BitcoinTestFramework): def watchonly_test(self, desc): self.log.info(f"Importing descriptor '{desc}'") desc = descsum_create(f"{desc}") - assert self.ms_wo_wallet.importdescriptors( + assert_equal(self.ms_wo_wallet.importdescriptors( [ { "desc": desc, @@ -223,7 +223,7 @@ class WalletMiniscriptTest(BitcoinTestFramework): "timestamp": "now", } ] - )[0]["success"] + )[0]["success"], True) self.log.info("Testing we derive new addresses for it") addr_type = "bech32m" if desc.startswith("tr(") else "bech32" @@ -244,7 +244,7 @@ class WalletMiniscriptTest(BitcoinTestFramework): ) utxo = self.ms_wo_wallet.listunspent(minconf=0, addresses=[addr])[0] assert_equal(utxo["txid"], txid) - assert utxo["solvable"] + assert_equal(utxo["solvable"], True) def signing_test( self, desc, sequence, locktime, sigs_count, stack_size, sha256_preimages @@ -273,7 +273,7 @@ class WalletMiniscriptTest(BitcoinTestFramework): self.funder.generatetoaddress(1, self.funder.getnewaddress()) utxo = self.ms_sig_wallet.listunspent(addresses=[addr])[0] assert_equal(txid, utxo["txid"]) - assert utxo["solvable"] + assert_equal(utxo["solvable"], True) self.log.info("Creating a transaction spending these funds") dest_addr = self.funder.getnewaddress() @@ -303,7 +303,7 @@ class WalletMiniscriptTest(BitcoinTestFramework): sigs_field_name = "taproot_script_path_sigs" if is_taproot else "partial_signatures" assert len(psbtin[sigs_field_name]) == sigs_count res = self.ms_sig_wallet.finalizepsbt(res["psbt"]) - assert res["complete"] == (stack_size is not None) + assert_equal(res["complete"], stack_size is not None) if stack_size is not None: txin = self.nodes[0].decoderawtransaction(res["hex"])["vin"][0] @@ -342,7 +342,7 @@ class WalletMiniscriptTest(BitcoinTestFramework): } ] )[0] - assert not res["success"] + assert_equal(res["success"], False) assert "is not sane: witnesses without signature exist" in res["error"]["message"] # Sanity check we wouldn't let an unspendable Miniscript descriptor in @@ -394,7 +394,7 @@ class WalletMiniscriptTest(BitcoinTestFramework): } ] )[0] - assert not res["success"] + assert_equal(res["success"], False) assert "is not a valid descriptor function" in res["error"]["message"]