Skip to content

Commit 2bbd429

Browse files
authored
refactor: centralize ADDR_ALPHABET constant usage (#3193)
Move the ADDR_ALPHABET definition to common.py and update all references in test_cli.py and test_tx_negative.py to use common.ADDR_ALPHABET. This reduces duplication and ensures consistency in address generation for hypothesis-based tests.
1 parent 70f2598 commit 2bbd429

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

cardano_node_tests/tests/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import string
23
import time
34
import typing as tp
45

@@ -20,6 +21,8 @@
2021
MAX_INT64 = (2**63) - 1
2122
MAX_UINT64 = (2**64) - 1
2223

24+
ADDR_ALPHABET = string.ascii_lowercase + string.digits
25+
2326
ORDER5_BYRON = (
2427
pytest.mark.order(5) if "_fast" not in configuration.TESTNET_VARIANT else pytest.mark.noop
2528
)

cardano_node_tests/tests/test_cli.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
LOGGER = logging.getLogger(__name__)
3030
DATA_DIR = pl.Path(__file__).parent / "data"
3131

32-
ADDR_ALPHABET = list(f"{string.ascii_lowercase}{string.digits}")
33-
34-
3532
pytestmark = common.SKIPIF_WRONG_ERA
3633

3734

@@ -373,7 +370,7 @@ def test_address_info_payment_with_outfile(self, cluster: clusterlib.ClusterLib)
373370
)
374371

375372
@allure.link(helpers.get_vcs_link())
376-
@hypothesis.given(address=st.text(alphabet=ADDR_ALPHABET, min_size=1))
373+
@hypothesis.given(address=st.text(alphabet=common.ADDR_ALPHABET, min_size=1))
377374
@common.hypothesis_settings(max_examples=300)
378375
@pytest.mark.smoke
379376
def test_address_info_with_invalid_address(self, cluster: clusterlib.ClusterLib, address: str):
@@ -471,7 +468,7 @@ def test_address_build(
471468

472469
@allure.link(helpers.get_vcs_link())
473470
@pytest.mark.parametrize("option", ("vkey", "vkey_file", "script_file"))
474-
@hypothesis.given(key=st.text(alphabet=ADDR_ALPHABET, min_size=1))
471+
@hypothesis.given(key=st.text(alphabet=common.ADDR_ALPHABET, min_size=1))
475472
@common.hypothesis_settings(max_examples=300)
476473
@pytest.mark.smoke
477474
def test_invalid_payment_info(
@@ -531,7 +528,7 @@ def test_invalid_payment_info(
531528
"address",
532529
),
533530
)
534-
@hypothesis.given(key=st.text(alphabet=ADDR_ALPHABET, min_size=1))
531+
@hypothesis.given(key=st.text(alphabet=common.ADDR_ALPHABET, min_size=1))
535532
@common.hypothesis_settings(max_examples=300)
536533
@pytest.mark.smoke
537534
def test_invalid_stake_info(
@@ -619,7 +616,7 @@ def test_valid_verification_key(self, cluster: clusterlib.ClusterLib, option: st
619616

620617
@allure.link(helpers.get_vcs_link())
621618
@pytest.mark.parametrize("option", ("vkey", "vkey_file"))
622-
@hypothesis.given(vkey=st.text(alphabet=ADDR_ALPHABET, min_size=1))
619+
@hypothesis.given(vkey=st.text(alphabet=common.ADDR_ALPHABET, min_size=1))
623620
@common.hypothesis_settings(max_examples=300)
624621
@pytest.mark.smoke
625622
def test_invalid_verification_key(self, cluster: clusterlib.ClusterLib, option: str, vkey: str):
@@ -866,7 +863,7 @@ def test_tx_in_invalid_data(
866863
assert "expecting digit" in err_str, err_str
867864

868865
@allure.link(helpers.get_vcs_link())
869-
@hypothesis.given(filter_str=st.text(alphabet=ADDR_ALPHABET, min_size=1))
866+
@hypothesis.given(filter_str=st.text(alphabet=common.ADDR_ALPHABET, min_size=1))
870867
@common.hypothesis_settings(max_examples=300)
871868
@pytest.mark.smoke
872869
def test_address_invalid_data(self, cluster: clusterlib.ClusterLib, filter_str: str):
@@ -922,7 +919,7 @@ def test_valid_verification_key(self, cluster: clusterlib.ClusterLib, option: st
922919

923920
@allure.link(helpers.get_vcs_link())
924921
@pytest.mark.parametrize("option", ("vkey", "vkey_file"))
925-
@hypothesis.given(vkey=st.text(alphabet=ADDR_ALPHABET, min_size=1))
922+
@hypothesis.given(vkey=st.text(alphabet=common.ADDR_ALPHABET, min_size=1))
926923
@common.hypothesis_settings(max_examples=300)
927924
@pytest.mark.smoke
928925
def test_invalid_verification_key(self, cluster: clusterlib.ClusterLib, option: str, vkey: str):

cardano_node_tests/tests/test_tx_negative.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88
import pathlib as pl
99
import re
10-
import string
1110
import time
1211
import typing as tp
1312

@@ -31,8 +30,6 @@
3130

3231
LOGGER = logging.getLogger(__name__)
3332

34-
ADDR_ALPHABET = list(f"{string.ascii_lowercase}{string.digits}")
35-
3633

3734
class TestNegative:
3835
"""Transaction tests that are expected to fail."""
@@ -872,7 +869,7 @@ def test_send_funds_to_utxo_address(
872869

873870
@allure.link(helpers.get_vcs_link())
874871
@common.PARAM_BUILD_METHOD
875-
@hypothesis.given(addr=st.text(alphabet=ADDR_ALPHABET, min_size=98, max_size=98))
872+
@hypothesis.given(addr=st.text(alphabet=common.ADDR_ALPHABET, min_size=98, max_size=98))
876873
@common.hypothesis_settings(300)
877874
@pytest.mark.smoke
878875
@pytest.mark.testnets
@@ -899,7 +896,7 @@ def test_send_funds_to_invalid_address(
899896
)
900897

901898
@allure.link(helpers.get_vcs_link())
902-
@hypothesis.given(addr=st.text(alphabet=ADDR_ALPHABET, min_size=50, max_size=250))
899+
@hypothesis.given(addr=st.text(alphabet=common.ADDR_ALPHABET, min_size=50, max_size=250))
903900
@common.hypothesis_settings(300)
904901
@common.PARAM_BUILD_METHOD
905902
@pytest.mark.smoke
@@ -957,7 +954,7 @@ def test_send_funds_to_invalid_chars_address(
957954
)
958955

959956
@allure.link(helpers.get_vcs_link())
960-
@hypothesis.given(addr=st.text(alphabet=ADDR_ALPHABET, min_size=98, max_size=98))
957+
@hypothesis.given(addr=st.text(alphabet=common.ADDR_ALPHABET, min_size=98, max_size=98))
961958
@common.hypothesis_settings(300)
962959
@common.PARAM_BUILD_METHOD
963960
@pytest.mark.smoke
@@ -985,7 +982,7 @@ def test_send_funds_from_invalid_address(
985982
)
986983

987984
@allure.link(helpers.get_vcs_link())
988-
@hypothesis.given(addr=st.text(alphabet=ADDR_ALPHABET, min_size=50, max_size=250))
985+
@hypothesis.given(addr=st.text(alphabet=common.ADDR_ALPHABET, min_size=50, max_size=250))
989986
@common.hypothesis_settings(300)
990987
@common.PARAM_BUILD_METHOD
991988
@pytest.mark.smoke
@@ -1044,7 +1041,7 @@ def test_send_funds_from_invalid_chars_address(
10441041

10451042
@allure.link(helpers.get_vcs_link())
10461043
@common.SKIPIF_BUILD_UNUSABLE
1047-
@hypothesis.given(addr=st.text(alphabet=ADDR_ALPHABET, min_size=98, max_size=98))
1044+
@hypothesis.given(addr=st.text(alphabet=common.ADDR_ALPHABET, min_size=98, max_size=98))
10481045
@common.hypothesis_settings(300)
10491046
@pytest.mark.smoke
10501047
@pytest.mark.testnets
@@ -1096,7 +1093,7 @@ def test_build_send_funds_invalid_chars_change_address(
10961093

10971094
@allure.link(helpers.get_vcs_link())
10981095
@common.SKIPIF_BUILD_UNUSABLE
1099-
@hypothesis.given(addr=st.text(alphabet=ADDR_ALPHABET, min_size=50, max_size=250))
1096+
@hypothesis.given(addr=st.text(alphabet=common.ADDR_ALPHABET, min_size=50, max_size=250))
11001097
@common.hypothesis_settings(300)
11011098
@pytest.mark.smoke
11021099
@pytest.mark.testnets
@@ -1205,7 +1202,7 @@ def test_nonexistent_utxo_hash(
12051202
raise ValueError(msg)
12061203

12071204
@allure.link(helpers.get_vcs_link())
1208-
@hypothesis.given(utxo_hash=st.text(alphabet=ADDR_ALPHABET, min_size=10, max_size=550))
1205+
@hypothesis.given(utxo_hash=st.text(alphabet=common.ADDR_ALPHABET, min_size=10, max_size=550))
12091206
@common.hypothesis_settings(300)
12101207
@common.PARAM_BUILD_METHOD
12111208
@pytest.mark.smoke
@@ -1241,7 +1238,7 @@ def test_invalid_length_utxo_hash(
12411238

12421239
@allure.link(helpers.get_vcs_link())
12431240
@common.SKIPIF_BUILD_UNUSABLE
1244-
@hypothesis.given(utxo_hash=st.text(alphabet=ADDR_ALPHABET, min_size=10, max_size=550))
1241+
@hypothesis.given(utxo_hash=st.text(alphabet=common.ADDR_ALPHABET, min_size=10, max_size=550))
12451242
@common.hypothesis_settings(300)
12461243
@pytest.mark.smoke
12471244
@pytest.mark.testnets

0 commit comments

Comments
 (0)