diff --git a/cardano_node_tests/tests/tests_conway/test_drep.py b/cardano_node_tests/tests/tests_conway/test_drep.py index 0adf329ae..adeb8ccb8 100644 --- a/cardano_node_tests/tests/tests_conway/test_drep.py +++ b/cardano_node_tests/tests/tests_conway/test_drep.py @@ -507,6 +507,104 @@ def _query_func(): if errors_final: raise AssertionError("\n".join(errors_final)) + @allure.link(helpers.get_vcs_link()) + @pytest.mark.needs_dbsync + def test_register_wrong_metadata( + self, + cluster: clusterlib.ClusterLib, + payment_addr: clusterlib.AddressRecord, + testfile_temp_dir: pl.Path, + request: FixtureRequest, + ): + """Register a DRep with wrong metadata url. + + * register DRep with mismatch url metadata vs metadata file + * check that DRep was registered + * verify that dbsync is returning an error + """ + temp_template = common.get_test_id(cluster) + + drep_metadata_file = DATA_DIR / "governance_action_anchor.json" + + # Register DRep + drep_metadata_url = "https://tinyurl.com/w7vd3ek6" + drep_metadata_hash = cluster.g_conway_governance.drep.get_metadata_hash( + drep_metadata_file=drep_metadata_file + ) + + reg_drep = governance_utils.get_drep_reg_record( + cluster_obj=cluster, + name_template=temp_template, + drep_metadata_url=drep_metadata_url, + drep_metadata_hash=drep_metadata_hash, + ) + + tx_files_reg = clusterlib.TxFiles( + certificate_files=[reg_drep.registration_cert], + signing_key_files=[payment_addr.skey_file, reg_drep.key_pair.skey_file], + ) + + tx_output_reg = clusterlib_utils.build_and_submit_tx( + cluster_obj=cluster, + name_template=f"{temp_template}_reg", + src_address=payment_addr.address, + tx_files=tx_files_reg, + deposit=reg_drep.deposit, + ) + + reg_drep_state = cluster.g_conway_governance.query.drep_state( + drep_vkey_file=reg_drep.key_pair.vkey_file + ) + assert reg_drep_state[0][0]["keyHash"] == reg_drep.drep_id, "DRep was not registered" + + def _retire_drep() -> None: + """Retire the new DRep so it doesn't affect voting.""" + with helpers.change_cwd(testfile_temp_dir): + ret_cert = cluster.g_conway_governance.drep.gen_retirement_cert( + cert_name=temp_template, + deposit_amt=reg_drep.deposit, + drep_vkey_file=reg_drep.key_pair.vkey_file, + ) + + tx_files_ret = clusterlib.TxFiles( + certificate_files=[ret_cert], + signing_key_files=[payment_addr.skey_file, reg_drep.key_pair.skey_file], + ) + + clusterlib_utils.build_and_submit_tx( + cluster_obj=cluster, + name_template=f"{temp_template}_ret", + src_address=payment_addr.address, + tx_files=tx_files_ret, + deposit=-reg_drep.deposit, + ) + + ret_drep_state = cluster.g_conway_governance.query.drep_state( + drep_vkey_file=reg_drep.key_pair.vkey_file + ) + assert not ret_drep_state, "DRep was not retired" + + request.addfinalizer(_retire_drep) + + reg_out_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_output_reg) + assert ( + clusterlib.filter_utxos(utxos=reg_out_utxos, address=payment_addr.address)[0].amount + == clusterlib.calculate_utxos_balance(tx_output_reg.txins) + - tx_output_reg.fee + - reg_drep.deposit + ), f"Incorrect balance for source address `{payment_addr.address}`" + + drep_data = dbsync_utils.get_drep(drep_hash=reg_drep.drep_id, drep_deposit=reg_drep.deposit) + + def _query_func(): + dbsync_utils.check_off_chain_vote_fetch_error( + voting_anchor_id=drep_data.voting_anchor_id + ) + + reqc.db021.start(url=helpers.get_vcs_link()) + dbsync_utils.retry_query(query_func=_query_func, timeout=300) + reqc.db021.success() + class TestNegativeDReps: """Tests for DReps where we test failing condition.""" diff --git a/cardano_node_tests/utils/dbsync_utils.py b/cardano_node_tests/utils/dbsync_utils.py index bfe3dd53d..7fe2829b2 100644 --- a/cardano_node_tests/utils/dbsync_utils.py +++ b/cardano_node_tests/utils/dbsync_utils.py @@ -1507,3 +1507,20 @@ def check_delegation_vote(txhash: str, stake_address: str, drep: str) -> None: assert delegation_vote_data.stake_address_hash_view == stake_address, ( "Incorrect delegation DRep: " f"{delegation_vote_data.drep_hash_view} vs {drep}" ) + + +def check_off_chain_vote_fetch_error(voting_anchor_id: int) -> None: + """Check expected error in off_chain_vote_fetch_error.""" + if not configuration.HAS_DBSYNC: + return + + db_off_chain_vote_fetch_error = list( + dbsync_queries.query_off_chain_vote_fetch_error(voting_anchor_id) + ) + + assert ( + db_off_chain_vote_fetch_error + ), f"{NO_RESPONSE_STR} no off chain vote fetch error for {voting_anchor_id}" + + fetch_error_str = db_off_chain_vote_fetch_error[-1].fetch_error or "" + assert "Hash mismatch when fetching metadata" in fetch_error_str