diff --git a/cardano_node_tests/tests/tests_conway/test_constitution.py b/cardano_node_tests/tests/tests_conway/test_constitution.py index 0a2923058..7a8fcd931 100644 --- a/cardano_node_tests/tests/tests_conway/test_constitution.py +++ b/cardano_node_tests/tests/tests_conway/test_constitution.py @@ -18,6 +18,8 @@ from cardano_node_tests.tests import reqs_conway as reqc from cardano_node_tests.tests.tests_conway import conway_common from cardano_node_tests.utils import clusterlib_utils +from cardano_node_tests.utils import configuration +from cardano_node_tests.utils import dbsync_queries from cardano_node_tests.utils import governance_setup from cardano_node_tests.utils import governance_utils from cardano_node_tests.utils import helpers @@ -314,8 +316,9 @@ class TestConstitution: """Tests for constitution.""" @allure.link(helpers.get_vcs_link()) + @pytest.mark.dbsync @pytest.mark.long - def test_change_constitution( + def test_change_constitution( # noqa: C901 self, cluster_lock_gov_script: governance_utils.GovClusterT, pool_user_lg: clusterlib.PoolUser, @@ -332,7 +335,6 @@ def test_change_constitution( * check that the action is enacted * check that it's not possible to vote on enacted action """ - # pylint: disable=too-many-locals,too-many-statements __: tp.Any # mypy workaround cluster, __ = cluster_lock_gov_script rand_str = clusterlib.get_rand_str(4) @@ -558,3 +560,11 @@ def _check_cli_query(): ledger_3979 = issues.ledger_3979.copy() ledger_3979.message = " ;".join(xfail_ledger_3979_msgs) ledger_3979.finish_test() + + # Check new constitution proposal in dbsync + if configuration.HAS_DBSYNC: + reqc.db012.start(url=helpers.get_vcs_link()) + constitution_db = list(dbsync_queries.query_new_constitution(txhash=action_txid)) + assert constitution_db, "No new constitution proposal found in dbsync" + assert constitution_db[0].gov_action_type == "NewConstitution" + reqc.db012.success() diff --git a/cardano_node_tests/utils/dbsync_queries.py b/cardano_node_tests/utils/dbsync_queries.py index aaf871027..e30926033 100644 --- a/cardano_node_tests/utils/dbsync_queries.py +++ b/cardano_node_tests/utils/dbsync_queries.py @@ -579,6 +579,16 @@ class DelegationVoteDBRow: drep_hash_view: str +@pydantic.dataclasses.dataclass(frozen=True, config=_CONF_ARBITRARY_T_ALLOWED) +class NewConstitutionInfoDBRow: + id: int + script_hash: tp.Optional[memoryview] + gov_action_type: str + gap_id: int + tx_id: int + action_ix: int + + @contextlib.contextmanager def execute(query: str, vars: tp.Sequence = ()) -> tp.Iterator[psycopg2.extensions.cursor]: # pylint: disable=redefined-builtin @@ -1487,3 +1497,20 @@ def query_delegation_vote(txhash: str) -> tp.Generator[DelegationVoteDBRow, None with execute(query=query, vars=(rf"\x{txhash}",)) as cur: while (result := cur.fetchone()) is not None: yield DelegationVoteDBRow(*result) + + +def query_new_constitution(txhash: str) -> tp.Generator[NewConstitutionInfoDBRow, None, None]: + """Query new constitution proposed in db-sync.""" + query = ( + "SELECT" + " constitution.id, constitution.script_hash, gap.type," + " gap.id, gap.tx_id, gap.index " + "FROM constitution " + "INNER JOIN gov_action_proposal AS gap ON gap.id = constitution.gov_action_proposal_id " + "INNER JOIN tx ON tx.id = gap.tx_id " + "WHERE tx.hash = %s;" + ) + + with execute(query=query, vars=(rf"\x{txhash}",)) as cur: + while (result := cur.fetchone()) is not None: + yield NewConstitutionInfoDBRow(*result)