Skip to content

Commit a9e860b

Browse files
authored
Merge pull request #3099 from IntersectMBO/handle_known_fields
feat(tests): improve negative redeemer fuzzing coverage
2 parents 105c1f5 + e2f1bd4 commit a9e860b

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

cardano_node_tests/tests/tests_plutus/test_spend_negative_build.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ class TestNegativeRedeemer:
550550

551551
MIN_INT_VAL = -common.MAX_UINT64
552552
AMOUNT = 800_000
553+
KNOWN_FIELDS = ("int", "bytes", "string", "list", "map")
554+
NONINT_FIELDS = ("bytes", "string", "list", "map")
553555

554556
@pytest.fixture
555557
def fund_script_guessing_game_v1(
@@ -1189,7 +1191,12 @@ def test_invalid_json(
11891191
assert "JSON object expected. Unexpected value" in err_str, err_str
11901192

11911193
@allure.link(helpers.get_vcs_link())
1192-
@hypothesis.given(redeemer_type=st.text())
1194+
@hypothesis.given(
1195+
redeemer_type=st.one_of(
1196+
st.sampled_from(NONINT_FIELDS),
1197+
st.text(),
1198+
)
1199+
)
11931200
@common.hypothesis_settings(max_examples=200)
11941201
@common.PARAM_PLUTUS_VERSION
11951202
@pytest.mark.smoke
@@ -1206,6 +1213,8 @@ def test_json_schema_typed_invalid_type(
12061213
12071214
Expect failure.
12081215
"""
1216+
hypothesis.assume(redeemer_type != "int")
1217+
12091218
temp_template = f"{common.get_test_id(cluster)}_{common.unique_time_str()}"
12101219

12111220
fund_script_guessing_game = (
@@ -1244,10 +1253,19 @@ def test_json_schema_typed_invalid_type(
12441253
'Expected a single field named "int", "bytes", "string", "list" or "map".' in err_str
12451254
# See node commit ac662d8e46554c1ed02d485bfdd69e7ec04d8613
12461255
or 'Expected a single field named "int", "bytes", "list" or "map".' in err_str
1256+
or (
1257+
redeemer_type in self.KNOWN_FIELDS
1258+
and "JSON schema error within the script data" in err_str
1259+
)
12471260
), err_str
12481261

12491262
@allure.link(helpers.get_vcs_link())
1250-
@hypothesis.given(redeemer_type=st.text())
1263+
@hypothesis.given(
1264+
redeemer_type=st.one_of(
1265+
st.sampled_from(NONINT_FIELDS),
1266+
st.text(),
1267+
)
1268+
)
12511269
@common.hypothesis_settings(max_examples=200)
12521270
@common.PARAM_PLUTUS_VERSION
12531271
@pytest.mark.smoke
@@ -1264,6 +1282,8 @@ def test_json_schema_untyped_invalid_type(
12641282
12651283
Expect failure.
12661284
"""
1285+
hypothesis.assume(redeemer_type != "int")
1286+
12671287
temp_template = f"{common.get_test_id(cluster)}_{common.unique_time_str()}"
12681288

12691289
fund_script_guessing_game = (
@@ -1302,4 +1322,8 @@ def test_json_schema_untyped_invalid_type(
13021322
'Expected a single field named "int", "bytes", "string", "list" or "map".' in err_str
13031323
# See node commit ac662d8e46554c1ed02d485bfdd69e7ec04d8613
13041324
or 'Expected a single field named "int", "bytes", "list" or "map".' in err_str
1325+
or (
1326+
redeemer_type in self.KNOWN_FIELDS
1327+
and "JSON schema error within the script data" in err_str
1328+
)
13051329
), err_str

cardano_node_tests/tests/tests_plutus/test_spend_negative_raw.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ class TestNegativeRedeemer:
694694

695695
MIN_INT_VAL = -common.MAX_UINT64
696696
AMOUNT = 2_000_000
697+
KNOWN_FIELDS = ("int", "bytes", "string", "list", "map")
698+
NONINT_FIELDS = ("bytes", "string", "list", "map")
697699

698700
def _fund_script_guessing_game(
699701
self,
@@ -1460,7 +1462,12 @@ def test_invalid_json(
14601462
assert "Invalid JSON format" in err, err
14611463

14621464
@allure.link(helpers.get_vcs_link())
1463-
@hypothesis.given(redeemer_type=st.text())
1465+
@hypothesis.given(
1466+
redeemer_type=st.one_of(
1467+
st.sampled_from(NONINT_FIELDS),
1468+
st.text(),
1469+
)
1470+
)
14641471
@common.hypothesis_settings(max_examples=200)
14651472
@common.PARAM_PLUTUS_VERSION
14661473
@pytest.mark.smoke
@@ -1477,6 +1484,8 @@ def test_json_schema_typed_invalid_type(
14771484
14781485
Expect failure.
14791486
"""
1487+
hypothesis.assume(redeemer_type != "int")
1488+
14801489
temp_template = f"{common.get_test_id(cluster)}_{common.unique_time_str()}"
14811490

14821491
fund_script_guessing_game = (
@@ -1503,10 +1512,19 @@ def test_json_schema_typed_invalid_type(
15031512
'Expected a single field named "int", "bytes", "string", "list" or "map".' in err
15041513
# See node commit ac662d8e46554c1ed02d485bfdd69e7ec04d8613
15051514
or 'Expected a single field named "int", "bytes", "list" or "map".' in err
1515+
or (
1516+
redeemer_type in self.KNOWN_FIELDS
1517+
and "JSON schema error within the script data" in err
1518+
)
15061519
), err
15071520

15081521
@allure.link(helpers.get_vcs_link())
1509-
@hypothesis.given(redeemer_type=st.text())
1522+
@hypothesis.given(
1523+
redeemer_type=st.one_of(
1524+
st.sampled_from(NONINT_FIELDS),
1525+
st.text(),
1526+
)
1527+
)
15101528
@common.hypothesis_settings(max_examples=200)
15111529
@common.PARAM_PLUTUS_VERSION
15121530
@pytest.mark.smoke
@@ -1523,6 +1541,8 @@ def test_json_schema_untyped_invalid_type(
15231541
15241542
Expect failure.
15251543
"""
1544+
hypothesis.assume(redeemer_type != "int")
1545+
15261546
temp_template = f"{common.get_test_id(cluster)}_{common.unique_time_str()}"
15271547

15281548
fund_script_guessing_game = (
@@ -1549,4 +1569,8 @@ def test_json_schema_untyped_invalid_type(
15491569
'Expected a single field named "int", "bytes", "string", "list" or "map".' in err
15501570
# See node commit ac662d8e46554c1ed02d485bfdd69e7ec04d8613
15511571
or 'Expected a single field named "int", "bytes", "list" or "map".' in err
1572+
or (
1573+
redeemer_type in self.KNOWN_FIELDS
1574+
and "JSON schema error within the script data" in err
1575+
)
15521576
), err

0 commit comments

Comments
 (0)