diff --git a/cardano_node_tests/tests/common.py b/cardano_node_tests/tests/common.py index fab9a2351..71b698437 100644 --- a/cardano_node_tests/tests/common.py +++ b/cardano_node_tests/tests/common.py @@ -14,7 +14,6 @@ from cardano_node_tests.utils import configuration from cardano_node_tests.utils import helpers from cardano_node_tests.utils import pytest_utils -from cardano_node_tests.utils import types as ttypes from cardano_node_tests.utils.versions import VERSIONS LOGGER = logging.getLogger(__name__) @@ -621,21 +620,3 @@ def allow_unstable_error_messages() -> tp.Iterator[None]: yield except AssertionError: LOGGER.exception("AssertionError suppressed") - - -def check_reference_script_policyid( - name_template: str, - cluster_obj: clusterlib.ClusterLib, - script_file: ttypes.FileType, - script_data: dict, -) -> None: - """Check that the policy ID of a reference script file matches the original script policy ID.""" - policyid_file = cluster_obj.g_transaction.get_policyid(script_file=script_file) - policyid_data = clusterlib_utils.get_script_data_policyid( - cluster_obj=cluster_obj, - script_name=name_template, - script_data=script_data, - ) - assert policyid_file == policyid_data, ( - f"Reference script hash mismatch: file '{policyid_file}' vs data '{policyid_data}'" - ) diff --git a/cardano_node_tests/tests/test_native_tokens.py b/cardano_node_tests/tests/test_native_tokens.py index bfaab8b7a..5df10d2c1 100644 --- a/cardano_node_tests/tests/test_native_tokens.py +++ b/cardano_node_tests/tests/test_native_tokens.py @@ -2728,7 +2728,7 @@ def test_script_reference_utxo( assert reference_utxo.reference_script has_issue_1332 = False try: - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=script, diff --git a/cardano_node_tests/tests/test_scripts.py b/cardano_node_tests/tests/test_scripts.py index 742a0ec23..81fa559e7 100644 --- a/cardano_node_tests/tests/test_scripts.py +++ b/cardano_node_tests/tests/test_scripts.py @@ -2466,7 +2466,7 @@ def test_script_reference_utxo( assert reference_utxo.reference_script has_issue_1332 = False try: - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=multisig_script, @@ -2640,7 +2640,7 @@ def test_spend_reference_script( assert reference_utxo.reference_script has_issue_1332 = False try: - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=multisig_script, diff --git a/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_build.py b/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_build.py index ebe513917..bcba0fc82 100644 --- a/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_build.py +++ b/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_build.py @@ -606,7 +606,7 @@ def test_spend_reference_script( ) assert reference_utxo.amount == amount, "Incorrect amount transferred" assert reference_utxo.reference_script, "Reference script is missing" - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=script_file, @@ -703,7 +703,7 @@ def test_spend_regular_utxo_and_reference_script( ) reference_script = clusterlib.filter_utxos(utxos=out_utxos_step1, utxo_ix=utxo_ix_offset) assert reference_script[0].reference_script, "No reference script UTxO" - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=plutus_op.script_file, @@ -1235,7 +1235,7 @@ def test_lock_byron_reference_script( ) assert reference_utxo.address == byron_addr.address, "Incorrect address for reference UTxO" assert reference_utxo.reference_script, "Reference script is missing" - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=plutus_op.script_file, diff --git a/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_raw.py b/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_raw.py index 5736b9199..6b335ec19 100644 --- a/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_raw.py +++ b/cardano_node_tests/tests/tests_plutus_v2/test_spend_ref_scripts_raw.py @@ -542,7 +542,7 @@ def test_spend_reference_script( ) assert reference_utxo.amount == amount, "Incorrect amount transferred" assert reference_utxo.reference_script, "Reference script is missing" - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=script_file, @@ -621,7 +621,7 @@ def test_spend_regular_utxo_and_reference_script( txid = cluster.g_transaction.get_txid(tx_body_file=tx_output_step1.out_file) reference_script = cluster.g_query.get_utxo(txin=f"{txid}#0") assert reference_script[0].reference_script, "No reference script UTxO" - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=plutus_op.script_file, @@ -682,7 +682,7 @@ def test_reference_script_byron_address( assert reference_utxo.address == byron_addr.address, "Incorrect address for reference UTxO" assert reference_utxo.reference_script, "Reference script is missing" - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=script_file, @@ -1200,7 +1200,7 @@ def test_lock_byron_reference_script( ) assert reference_utxo.address == byron_addr.address, "Incorrect address for reference UTxO" assert reference_utxo.reference_script, "Reference script is missing" - common.check_reference_script_policyid( + clusterlib_utils.check_reference_script_policyid( name_template=f"{temp_template}_check", cluster_obj=cluster, script_file=plutus_op.script_file, diff --git a/cardano_node_tests/utils/clusterlib_utils.py b/cardano_node_tests/utils/clusterlib_utils.py index 4bf5136ee..5a645cea3 100644 --- a/cardano_node_tests/utils/clusterlib_utils.py +++ b/cardano_node_tests/utils/clusterlib_utils.py @@ -1633,3 +1633,21 @@ def get_script_data_policyid( with open(script_file, "w", encoding="utf-8") as outfile: json.dump(script_data, outfile) return cluster_obj.g_transaction.get_policyid(script_file=script_file) + + +def check_reference_script_policyid( + name_template: str, + cluster_obj: clusterlib.ClusterLib, + script_file: cl_types.FileType, + script_data: dict, +) -> None: + """Check that the policy ID of a reference script file matches the original script policy ID.""" + policyid_file = cluster_obj.g_transaction.get_policyid(script_file=script_file) + policyid_data = get_script_data_policyid( + cluster_obj=cluster_obj, + script_name=name_template, + script_data=script_data, + ) + if policyid_file != policyid_data: + msg = f"Reference script hash mismatch: file '{policyid_file}' vs data '{policyid_data}'" + raise AssertionError(msg)