Skip to content

Commit

Permalink
Merge pull request #2577 from saratomaz/check_constitution_table
Browse files Browse the repository at this point in the history
Check constitution table in dbsync
  • Loading branch information
mkoura authored Sep 5, 2024
2 parents a6a778d + b32f56a commit df015aa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cardano_node_tests/tests/tests_conway/test_constitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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()
27 changes: 27 additions & 0 deletions cardano_node_tests/utils/dbsync_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit df015aa

Please sign in to comment.