From ae4730ea128e2fefab3247e3e6fbfda91dea9383 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:23:51 +0100 Subject: [PATCH 1/2] qa: Add assert_true() This follows the style of ASSERT_TRUE() in GoogleTest: https://google.github.io/googletest/reference/assertions.html --- test/functional/test_framework/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 14930ef6719..598329e423a 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -69,6 +69,14 @@ def summarise_dict_differences(thing1, thing2): d2[k] = thing2[k] return d1, d2 + +def assert_true(condition: bool) -> None: + """Separate from the `assert` keyword in that it should not be optimized out + when environment var `PYTHONOPTIMIZE=1`, or Python is run with `-O`.""" + if not condition: + raise AssertionError + + def assert_equal(thing1, thing2, *args): if thing1 != thing2 and not args and isinstance(thing1, dict) and isinstance(thing2, dict): d1,d2 = summarise_dict_differences(thing1, thing2) From 790c509a4796ec47be2275d86b35370ff25a599a Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Fri, 14 Feb 2025 23:11:07 +0100 Subject: [PATCH 2/2] qa wallet: Actually make use of conditions The two ones in run_test() were basically no-ops. --- test/functional/wallet_multisig_descriptor_psbt.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/functional/wallet_multisig_descriptor_psbt.py b/test/functional/wallet_multisig_descriptor_psbt.py index a69185b3a5f..88c792c5693 100755 --- a/test/functional/wallet_multisig_descriptor_psbt.py +++ b/test/functional/wallet_multisig_descriptor_psbt.py @@ -11,6 +11,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_approx, assert_equal, + assert_true, ) @@ -69,7 +70,7 @@ class WalletMultisigDescriptorPSBTTest(BitcoinTestFramework): "timestamp": "now", }, ]) - assert all(r["success"] for r in result) + assert_true(all(r["success"] for r in result)) yield multisig def run_test(self): @@ -96,9 +97,9 @@ class WalletMultisigDescriptorPSBTTest(BitcoinTestFramework): self.log.info("Check that every participant's multisig generates the same addresses...") for _ in range(10): # we check that the first 10 generated addresses are the same for all participant's multisigs receive_addresses = [multisig.getnewaddress() for multisig in participants["multisigs"]] - all(address == receive_addresses[0] for address in receive_addresses) + assert_true(all(address == receive_addresses[0] for address in receive_addresses)) change_addresses = [multisig.getrawchangeaddress() for multisig in participants["multisigs"]] - all(address == change_addresses[0] for address in change_addresses) + assert_true(all(address == change_addresses[0] for address in change_addresses)) self.log.info("Get a mature utxo to send to the multisig...") coordinator_wallet = participants["signers"][0]