Skip to content

Commit 0ef1deb

Browse files
committed
Check epoch_state table in dbsync
1 parent 2cd21ea commit 0ef1deb

File tree

7 files changed

+83
-1
lines changed

7 files changed

+83
-1
lines changed

cardano_node_tests/tests/reqs_conway.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,5 @@ def __dr(id: str) -> requirements.Req:
261261
db022 = __dr("reward_rest")
262262
db023 = __dr("param_proposal") # new/updated fields
263263
db024 = __dr("epoch_param") # new/updated fields
264+
db025_01 = __dr("int-epoch_state-01") # related to committee
265+
db025_02 = __dr("int-epoch_state-02") # related to constitution

cardano_node_tests/tests/tests_conway/test_committee.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,16 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
10331033
_msg = f"db-sync error: {dbsync_resign_err}"
10341034
raise AssertionError(_msg)
10351035

1036+
# Check epoch state in dbsync
1037+
reqc.db025_01.start(url=helpers.get_vcs_link())
1038+
dbsync_utils.check_epoch_state(
1039+
epoch_no=enact_epoch, txid=action_add_txid, change_type="committee"
1040+
)
1041+
dbsync_utils.check_epoch_state(
1042+
epoch_no=rem_epoch, txid=action_rem_txid, change_type="committee"
1043+
)
1044+
reqc.db025_01.success()
1045+
10361046
@allure.link(helpers.get_vcs_link())
10371047
@pytest.mark.skipif(not configuration.HAS_CC, reason="Runs only on setup with CC")
10381048
@pytest.mark.long

cardano_node_tests/tests/tests_conway/test_constitution.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from cardano_node_tests.utils import clusterlib_utils
2020
from cardano_node_tests.utils import configuration
2121
from cardano_node_tests.utils import dbsync_queries
22+
from cardano_node_tests.utils import dbsync_utils
2223
from cardano_node_tests.utils import governance_setup
2324
from cardano_node_tests.utils import governance_utils
2425
from cardano_node_tests.utils import helpers
@@ -554,3 +555,10 @@ def _check_cli_query():
554555
assert constitution_db, "No new constitution proposal found in dbsync"
555556
assert constitution_db[0].gov_action_type == "NewConstitution"
556557
reqc.db012.success()
558+
559+
# Check epoch state in dbsync
560+
reqc.db025_02.start(url=helpers.get_vcs_link())
561+
dbsync_utils.check_epoch_state(
562+
epoch_no=cluster.g_query.get_epoch(), txid=action_txid, change_type="constitution"
563+
)
564+
reqc.db025_02.success()

cardano_node_tests/utils/dbsync_queries.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,15 @@ class DrepDistributionDBRow:
598598
drep_hash_view: str
599599

600600

601+
@pydantic.dataclasses.dataclass(frozen=True)
602+
class EpochStateDBRow:
603+
id: int
604+
committee_id: int
605+
no_confidence_id: tp.Optional[int]
606+
constitution_id: int
607+
epoch_no: int
608+
609+
601610
@contextlib.contextmanager
602611
def execute(query: str, vars: tp.Sequence = ()) -> tp.Iterator[psycopg2.extensions.cursor]:
603612
# pylint: disable=redefined-builtin
@@ -1541,3 +1550,17 @@ def query_drep_distr(
15411550
with execute(query=query, vars=(drep_hash, epoch_no)) as cur:
15421551
while (result := cur.fetchone()) is not None:
15431552
yield DrepDistributionDBRow(*result)
1553+
1554+
1555+
def query_epoch_state(epoch_no: int) -> tp.Generator[EpochStateDBRow, None, None]:
1556+
"""Query epoch_state table in db-sync."""
1557+
query = (
1558+
"SELECT "
1559+
" id, committee_id, no_confidence_id, constitution_id, epoch_no "
1560+
"FROM epoch_state "
1561+
"WHERE epoch_no = %s "
1562+
)
1563+
1564+
with execute(query=query, vars=(epoch_no,)) as cur:
1565+
while (result := cur.fetchone()) is not None:
1566+
yield EpochStateDBRow(*result)

cardano_node_tests/utils/dbsync_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,3 +1531,33 @@ def check_off_chain_vote_fetch_error(voting_anchor_id: int) -> None:
15311531

15321532
fetch_error_str = db_off_chain_vote_fetch_error[-1].fetch_error or ""
15331533
assert "Hash mismatch when fetching metadata" in fetch_error_str
1534+
1535+
1536+
def check_epoch_state(epoch_no: int, txid: str, change_type: str = "") -> None:
1537+
"""Check governance stats per epoch in dbsync."""
1538+
if not configuration.HAS_DBSYNC:
1539+
return
1540+
1541+
epoch_state_data = list(dbsync_queries.query_epoch_state(epoch_no=epoch_no))
1542+
1543+
if not epoch_state_data:
1544+
msg = f"No information about epoch state in dbsync for epoch: {epoch_no}"
1545+
raise AssertionError(msg)
1546+
1547+
if change_type == "committee":
1548+
dbsync_committee_info = list(dbsync_queries.query_new_committee_info(txhash=txid))[-1]
1549+
es_committee_id = epoch_state_data[0].committee_id
1550+
tx_committee_id = dbsync_committee_info.id
1551+
assert es_committee_id == tx_committee_id, (
1552+
f"Committee id mismatch between epoch_state {es_committee_id} "
1553+
f"and committee table {tx_committee_id}."
1554+
)
1555+
1556+
if change_type == "constitution":
1557+
dbsync_constitution_info = list(dbsync_queries.query_new_constitution(txhash=txid))[-1]
1558+
es_constitution_id = epoch_state_data[0].constitution_id
1559+
tx_constitution_id = dbsync_constitution_info.id
1560+
assert es_constitution_id == tx_constitution_id, (
1561+
f"Committee id mismatch between epoch_state {es_constitution_id} "
1562+
f"and committee table {tx_constitution_id}."
1563+
)

src_docs/chang_user_stories_template.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,12 @@ DB Sync - Conway related tables
13571357
- |image-epoch_param|
13581358
- The accepted protocol parameters for an epoch.
13591359
`<https://github.com/IntersectMBO/cardano-db-sync/blob/master/doc/schema.md#epoch_param>`__
1360+
-
1361+
1362+
- |image-epoch_state|
1363+
- Table with governance stats per epoch.
1364+
`<https://github.com/IntersectMBO/cardano-db-sync/blob/master/doc/schema.md#epoch_state>`__
1365+
13601366

13611367
.. |Success Badge| image:: https://img.shields.io/badge/success-green
13621368
.. |Failure Badge| image:: https://img.shields.io/badge/failure-red
@@ -1767,3 +1773,5 @@ DB Sync - Conway related tables
17671773
:target: https://github.com/param_proposal-404
17681774
.. |image-epoch_param| image:: https://img.shields.io/badge/epoch_param-grey
17691775
:target: https://github.com/epoch_param-404
1776+
.. |image-epoch_state| image:: https://img.shields.io/badge/epoch_state-grey
1777+
:target: https://github.com/epoch_state-404

src_docs/requirements_mapping.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"CIP062": ["intCIP062-01", "intCIP062-02"],
4343
"CIP064": ["intCIP064-01", "intCIP064-02", "intCIP064-03", "intCIP064-04"],
4444
"CIP069": ["intCIP069en", "intCIP069ex"],
45-
"CIP073": ["intCIP073-01", "intCIP073-02", "intCIP073-03", "intCIP073-04"]
45+
"CIP073": ["intCIP073-01", "intCIP073-02", "intCIP073-03", "intCIP073-04"],
46+
"epoch_state": ["int-epoch_state-01", "int-epoch_state-02"]
4647
}
4748
}

0 commit comments

Comments
 (0)