Skip to content

Commit 4d82c5b

Browse files
committed
Check epoch_state table in dbsync
1 parent df015aa commit 4d82c5b

File tree

6 files changed

+91
-10
lines changed

6 files changed

+91
-10
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: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,11 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
852852
reqc.cip003.success()
853853

854854
# Check enactment of add action
855-
_cur_epoch = cluster.wait_for_new_epoch(padding_seconds=5)
855+
_cur_epoch_add_action = cluster.wait_for_new_epoch(padding_seconds=5)
856856
enact_add_gov_state = cluster.g_conway_governance.query.gov_state()
857857
conway_common.save_gov_state(
858-
gov_state=enact_add_gov_state, name_template=f"{temp_template}_enact_add_{_cur_epoch}"
858+
gov_state=enact_add_gov_state,
859+
name_template=f"{temp_template}_enact_add_{_cur_epoch_add_action}",
859860
)
860861

861862
reqc.cip073_03.start(url=helpers.get_vcs_link())
@@ -870,9 +871,11 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
870871
enact_add_committee_state = cluster.g_conway_governance.query.committee_state()
871872
conway_common.save_committee_state(
872873
committee_state=enact_add_committee_state,
873-
name_template=f"{temp_template}_enact_add_{_cur_epoch}",
874+
name_template=f"{temp_template}_enact_add_{_cur_epoch_add_action}",
875+
)
876+
_check_cc_member1_expired(
877+
committee_state=enact_add_committee_state, curr_epoch=_cur_epoch_add_action
874878
)
875-
_check_cc_member1_expired(committee_state=enact_add_committee_state, curr_epoch=_cur_epoch)
876879

877880
_url = helpers.get_vcs_link()
878881
[r.start(url=_url) for r in (reqc.cip009, reqc.cip010)]
@@ -913,7 +916,7 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
913916
reqc.cip038_01.success()
914917

915918
# The proposal was enacted, but it is already expired
916-
assert _cur_epoch == actions_epoch + 3, "Unexpected epoch"
919+
assert _cur_epoch_add_action == actions_epoch + 3, "Unexpected epoch"
917920
with pytest.raises(clusterlib.CLIError) as excinfo:
918921
conway_common.cast_vote(
919922
cluster_obj=cluster,
@@ -939,23 +942,26 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
939942
), "CC Member is not marked for removal"
940943

941944
# Check enactment of removal action
942-
_cur_epoch = cluster.wait_for_new_epoch(padding_seconds=5)
945+
_cur_epoch_rem_action = cluster.wait_for_new_epoch(padding_seconds=5)
943946
enact_rem_gov_state = cluster.g_conway_governance.query.gov_state()
944947
conway_common.save_gov_state(
945-
gov_state=enact_rem_gov_state, name_template=f"{temp_template}_enact_rem_{_cur_epoch}"
948+
gov_state=enact_rem_gov_state,
949+
name_template=f"{temp_template}_enact_rem_{_cur_epoch_rem_action}",
946950
)
947951
_check_cc_member2_removed(gov_state=enact_rem_gov_state)
948952

949953
# Check committee state after enactment of removal action
950954
enact_rem_committee_state = cluster.g_conway_governance.query.committee_state()
951955
conway_common.save_committee_state(
952956
committee_state=enact_rem_committee_state,
953-
name_template=f"{temp_template}_enact_rem_{_cur_epoch}",
957+
name_template=f"{temp_template}_enact_rem_{_cur_epoch_rem_action}",
954958
)
955959
enact_rem_member_rec = enact_rem_committee_state["committee"].get(cc_member2_key)
956960
assert not enact_rem_member_rec, "Removed committee member still present"
957961

958-
_check_cc_member1_expired(committee_state=enact_rem_committee_state, curr_epoch=_cur_epoch)
962+
_check_cc_member1_expired(
963+
committee_state=enact_rem_committee_state, curr_epoch=_cur_epoch_rem_action
964+
)
959965
reqc.cip011.success()
960966

961967
# Try to vote on enacted removal action
@@ -1020,6 +1026,16 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
10201026
_msg = f"db-sync error: {dbsync_resign_err}"
10211027
raise AssertionError(_msg)
10221028

1029+
# Check epoch state in dbsync
1030+
reqc.db023_01.start(url=helpers.get_vcs_link())
1031+
dbsync_utils.check_epoch_state(
1032+
epoch_no=_cur_epoch_add_action, txid=action_add_txid, change_type="committee"
1033+
)
1034+
dbsync_utils.check_epoch_state(
1035+
epoch_no=_cur_epoch_rem_action, txid=action_rem_txid, change_type="committee"
1036+
)
1037+
reqc.db023_01.success()
1038+
10231039
@allure.link(helpers.get_vcs_link())
10241040
@pytest.mark.skipif(not configuration.HAS_CC, reason="Runs only on setup with CC")
10251041
@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
@@ -20,6 +20,7 @@
2020
from cardano_node_tests.utils import clusterlib_utils
2121
from cardano_node_tests.utils import configuration
2222
from cardano_node_tests.utils import dbsync_queries
23+
from cardano_node_tests.utils import dbsync_utils
2324
from cardano_node_tests.utils import governance_setup
2425
from cardano_node_tests.utils import governance_utils
2526
from cardano_node_tests.utils import helpers
@@ -568,3 +569,10 @@ def _check_cli_query():
568569
assert constitution_db, "No new constitution proposal found in dbsync"
569570
assert constitution_db[0].gov_action_type == "NewConstitution"
570571
reqc.db012.success()
572+
573+
# Check epoch state in dbsync
574+
reqc.db023_02.start(url=helpers.get_vcs_link())
575+
dbsync_utils.check_epoch_state(
576+
epoch_no=cluster.g_query.get_epoch(), txid=action_txid, change_type="constitution"
577+
)
578+
reqc.db023_02.success()

cardano_node_tests/utils/dbsync_queries.py

Lines changed: 24 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,18 @@ 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)
1540+

cardano_node_tests/utils/dbsync_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,3 +1507,33 @@ def check_delegation_vote(txhash: str, stake_address: str, drep: str) -> None:
15071507
assert delegation_vote_data.stake_address_hash_view == stake_address, (
15081508
"Incorrect delegation DRep: " f"{delegation_vote_data.drep_hash_view} vs {drep}"
15091509
)
1510+
1511+
1512+
def check_epoch_state(epoch_no: int, txid: str, change_type: str = "") -> None:
1513+
"""Check governance stats per epoch in dbsync."""
1514+
if not configuration.HAS_DBSYNC:
1515+
return
1516+
1517+
epoch_state_data = list(dbsync_queries.query_epoch_state(epoch_no=epoch_no))
1518+
1519+
if not epoch_state_data:
1520+
msg = f"No information about epoch state in dbsync for epoch: {epoch_no}"
1521+
raise AssertionError(msg)
1522+
1523+
if change_type == "committee":
1524+
dbsync_committee_info = list(dbsync_queries.query_new_committee_info(txhash=txid))[-1]
1525+
es_committee_id = epoch_state_data[0].committee_id
1526+
tx_committee_id = dbsync_committee_info.id
1527+
assert es_committee_id == tx_committee_id, (
1528+
f"Committee id mismatch between epoch_state {es_committee_id} "
1529+
f"and committee table {tx_committee_id}."
1530+
)
1531+
1532+
if change_type == "constitution":
1533+
dbsync_constitution_info = list(dbsync_queries.query_new_constitution(txhash=txid))[-1]
1534+
es_constitution_id = epoch_state_data[0].constitution_id
1535+
tx_constitution_id = dbsync_constitution_info.id
1536+
assert es_constitution_id == tx_constitution_id, (
1537+
f"Committee id mismatch between epoch_state {es_constitution_id} "
1538+
f"and committee table {tx_constitution_id}."
1539+
)

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)