diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index ceca0d3b19b..08e42a459fa 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) diff --git a/test/functional/wallet_multisig_descriptor_psbt.py b/test/functional/wallet_multisig_descriptor_psbt.py index 23a9a4cc755..5f5c79434e0 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, ) @@ -68,7 +69,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): @@ -95,9 +96,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]