From 2b982023c2d13702aabf984daa737e70c594f904 Mon Sep 17 00:00:00 2001 From: Martin Kourim Date: Wed, 14 Jan 2026 11:48:10 +0100 Subject: [PATCH] refactor(tests): fix tx unbalanced test example value Fixed the test to not use an in bounds Lovelace amount as an hypothesis example. Refactored the test for out-of-bounds Lovelace amounts to use pytest.raises for exception handling instead of try/except. Updated parameter names for clarity and removed redundant error string logic. --- .../tests/test_tx_unbalanced.py | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/cardano_node_tests/tests/test_tx_unbalanced.py b/cardano_node_tests/tests/test_tx_unbalanced.py index 09b245d51..35cd3bbe5 100644 --- a/cardano_node_tests/tests/test_tx_unbalanced.py +++ b/cardano_node_tests/tests/test_tx_unbalanced.py @@ -262,9 +262,8 @@ def test_wrong_balance( ) @allure.link(helpers.get_vcs_link()) - @hypothesis.given(change_amount=st.integers(min_value=MAX_LOVELACE_AMOUNT + 1)) - @hypothesis.example(change_amount=2_000_000) - @hypothesis.example(change_amount=MAX_LOVELACE_AMOUNT + 1) + @hypothesis.given(amount=st.integers(min_value=MAX_LOVELACE_AMOUNT + 1)) + @hypothesis.example(amount=MAX_LOVELACE_AMOUNT + 1) @common.hypothesis_settings(300) @pytest.mark.smoke @pytest.mark.testnets @@ -273,7 +272,7 @@ def test_out_of_bounds_amount( cluster: clusterlib.ClusterLib, payment_addrs: list[clusterlib.AddressRecord], pbt_highest_utxo: clusterlib.UTXOData, - change_amount: int, + amount: int, ): """Try to build a transaction with output Lovelace amount that is out of bounds.""" temp_template = f"{common.get_test_id(cluster)}_{common.unique_time_str()}" @@ -286,11 +285,10 @@ def test_out_of_bounds_amount( # Use only the UTxO with the highest amount txins = [pbt_highest_utxo] txouts = [ - clusterlib.TxOut(address=payment_addrs[0].address, amount=change_amount), + clusterlib.TxOut(address=payment_addrs[0].address, amount=amount), ] - err_str = "" - try: + with pytest.raises(clusterlib.CLIError) as excinfo: cluster.g_transaction.build_raw_tx_bare( out_file=out_file_tx, txins=txins, @@ -299,12 +297,9 @@ def test_out_of_bounds_amount( fee=fee, ttl=ttl, ) - except clusterlib.CLIError as exc: - err_str = str(exc) - - if err_str: - with common.allow_unstable_error_messages(): - assert "out of bounds" in err_str or "exceeds the max bound" in err_str, err_str + exc_value = str(excinfo.value) + with common.allow_unstable_error_messages(): + assert "out of bounds" in exc_value or "exceeds the max bound" in exc_value, exc_value @allure.link(helpers.get_vcs_link()) @common.SKIPIF_BUILD_UNUSABLE