Skip to content

Commit 6725ee8

Browse files
committed
Check epoch_state table in dbsync
1 parent f3a9f59 commit 6725ee8

File tree

7 files changed

+82
-1
lines changed

7 files changed

+82
-1
lines changed

cardano_node_tests/tests/reqs_conway.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,5 @@ def __dr(id: str) -> requirements.Req:
259259
db020 = __dr("off_chain_vote_external_update")
260260
db021 = __dr("off_chain_vote_fetch_error")
261261
db022 = __dr("reward_rest")
262+
db023_01 = __dr("int-epoch_state-01") # related to committee
263+
db023_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
@@ -1023,6 +1023,16 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
10231023
_msg = f"db-sync error: {dbsync_resign_err}"
10241024
raise AssertionError(_msg)
10251025

1026+
# Check epoch state in dbsync
1027+
reqc.db023_01.start(url=helpers.get_vcs_link())
1028+
dbsync_utils.check_epoch_state(
1029+
epoch_no=enact_epoch, txid=action_add_txid, change_type="committee"
1030+
)
1031+
dbsync_utils.check_epoch_state(
1032+
epoch_no=rem_epoch, txid=action_rem_txid, change_type="committee"
1033+
)
1034+
reqc.db023_01.success()
1035+
10261036
@allure.link(helpers.get_vcs_link())
10271037
@pytest.mark.skipif(not configuration.HAS_CC, reason="Runs only on setup with CC")
10281038
@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.db023_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.db023_02.success()

cardano_node_tests/utils/dbsync_queries.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,15 @@ class NewConstitutionInfoDBRow:
589589
action_ix: int
590590

591591

592+
@pydantic.dataclasses.dataclass(frozen=True)
593+
class EpochStateDBRow:
594+
id: int
595+
committee_id: int
596+
no_confidence_id: tp.Optional[int]
597+
constitution_id: int
598+
epoch_no: int
599+
600+
592601
@contextlib.contextmanager
593602
def execute(query: str, vars: tp.Sequence = ()) -> tp.Iterator[psycopg2.extensions.cursor]:
594603
# pylint: disable=redefined-builtin
@@ -1514,3 +1523,17 @@ def query_new_constitution(txhash: str) -> tp.Generator[NewConstitutionInfoDBRow
15141523
with execute(query=query, vars=(rf"\x{txhash}",)) as cur:
15151524
while (result := cur.fetchone()) is not None:
15161525
yield NewConstitutionInfoDBRow(*result)
1526+
1527+
1528+
def query_epoch_state(epoch_no: int) -> tp.Generator[EpochStateDBRow, None, None]:
1529+
"""Query epoch_state table in db-sync."""
1530+
query = (
1531+
"SELECT "
1532+
" id, committee_id, no_confidence_id, constitution_id, epoch_no "
1533+
"FROM epoch_state "
1534+
"WHERE epoch_no = %s "
1535+
)
1536+
1537+
with execute(query=query, vars=(epoch_no,)) as cur:
1538+
while (result := cur.fetchone()) is not None:
1539+
yield EpochStateDBRow(*result)

cardano_node_tests/utils/dbsync_utils.py

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

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

src_docs/chang_user_stories_template.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,11 @@ DB Sync - Conway related tables
13471347
- |image-off_chain_vote_fetch_error|
13481348
- Errors while fetching or validating offchain Voting Anchor metadata.
13491349
`<https://github.com/IntersectMBO/cardano-db-sync/blob/master/doc/schema.md#off_chain_vote_fetch_error>`__
1350+
-
1351+
1352+
- |image-epoch_state|
1353+
- Table with governance stats per epoch.
1354+
`<https://github.com/IntersectMBO/cardano-db-sync/blob/master/doc/schema.md#epoch_state>`__
13501355

13511356
.. |Success Badge| image:: https://img.shields.io/badge/success-green
13521357
.. |Failure Badge| image:: https://img.shields.io/badge/failure-red
@@ -1753,3 +1758,5 @@ DB Sync - Conway related tables
17531758
:target: https://github.com/off_chain_vote_external_update-404
17541759
.. |image-off_chain_vote_fetch_error| image:: https://img.shields.io/badge/off_chain_vote_fetch_error-grey
17551760
:target: https://github.com/off_chain_vote_fetch_error-404
1761+
.. |image-epoch_state| image:: https://img.shields.io/badge/epoch_state-grey
1762+
: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)