Skip to content

Commit 7bd834a

Browse files
committed
refactor: use enum for epoch state action type
Refactored dbsync_utils.check_epoch_state to use ActionTypes enum instead of string literals for action type. Updated all usages in committee and constitution tests. Added ActionTypes enum to dbsync_utils for clarity and type safety. Improved error handling for unsupported action types.
1 parent e40fb0f commit 7bd834a

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

cardano_node_tests/tests/tests_conway/test_committee.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,12 @@ def _check_resign_dbsync(res_member: clusterlib.CCMember) -> None:
13171317
# Check epoch state in dbsync
13181318
reqc.db025_01.start(url=helpers.get_vcs_link())
13191319
dbsync_utils.check_epoch_state(
1320-
epoch_no=enact_epoch, txid=action_add_txid, change_type="committee"
1320+
epoch_no=enact_epoch,
1321+
txid=action_add_txid,
1322+
action_type=dbsync_utils.ActionTypes.COMMITTEE,
13211323
)
13221324
dbsync_utils.check_epoch_state(
1323-
epoch_no=rem_epoch, txid=action_rem_txid, change_type="committee"
1325+
epoch_no=rem_epoch, txid=action_rem_txid, action_type=dbsync_utils.ActionTypes.COMMITTEE
13241326
)
13251327
reqc.db025_01.success()
13261328

cardano_node_tests/tests/tests_conway/test_constitution.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,11 @@ def _check_cli_query():
589589
assert constitution_db[0].gov_action_type == "NewConstitution"
590590
reqc.db012.success()
591591

592-
# Check epoch state in dbsync
593-
reqc.db025_02.start(url=helpers.get_vcs_link())
594-
dbsync_utils.check_epoch_state(
595-
epoch_no=cluster.g_query.get_epoch(), txid=action_txid, change_type="constitution"
596-
)
597-
reqc.db025_02.success()
592+
# Check epoch state in dbsync
593+
reqc.db025_02.start(url=helpers.get_vcs_link())
594+
dbsync_utils.check_epoch_state(
595+
epoch_no=cluster.g_query.get_epoch(),
596+
txid=action_txid,
597+
action_type=dbsync_utils.ActionTypes.CONSTITUTION,
598+
)
599+
reqc.db025_02.success()

cardano_node_tests/utils/dbsync_utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Functionality for interacting with db-sync."""
22

3+
import enum
34
import functools
45
import itertools
56
import logging
@@ -20,6 +21,11 @@
2021
NO_RESPONSE_STR = "No response returned from db-sync:"
2122

2223

24+
class ActionTypes(enum.StrEnum):
25+
COMMITTEE = "committee"
26+
CONSTITUTION = "constitution"
27+
28+
2329
def get_address_reward(
2430
address: str, epoch_from: int = 0, epoch_to: int = 99999999
2531
) -> dbsync_types.RewardRecord:
@@ -1593,7 +1599,7 @@ def table_exists(table: str) -> bool:
15931599
return table in table_names
15941600

15951601

1596-
def check_epoch_state(epoch_no: int, txid: str, change_type: str = "") -> None:
1602+
def check_epoch_state(epoch_no: int, txid: str, action_type: ActionTypes) -> None:
15971603
"""Check governance stats per epoch in dbsync."""
15981604
if not configuration.HAS_DBSYNC:
15991605
return
@@ -1604,20 +1610,22 @@ def check_epoch_state(epoch_no: int, txid: str, change_type: str = "") -> None:
16041610
msg = f"No information about epoch state in dbsync for epoch: {epoch_no}"
16051611
raise ValueError(msg)
16061612

1607-
if change_type == "committee":
1613+
if action_type == ActionTypes.COMMITTEE:
16081614
dbsync_committee_info = list(dbsync_queries.query_new_committee_info(txhash=txid))[-1]
16091615
es_committee_id = epoch_state_data[0].committee_id
16101616
tx_committee_id = dbsync_committee_info.id
16111617
assert es_committee_id == tx_committee_id, (
16121618
f"Committee id mismatch between epoch_state {es_committee_id} "
16131619
f"and committee table {tx_committee_id}."
16141620
)
1615-
1616-
if change_type == "constitution":
1621+
elif action_type == ActionTypes.CONSTITUTION:
16171622
dbsync_constitution_info = list(dbsync_queries.query_new_constitution(txhash=txid))[-1]
16181623
es_constitution_id = epoch_state_data[0].constitution_id
16191624
tx_constitution_id = dbsync_constitution_info.id
16201625
assert es_constitution_id == tx_constitution_id, (
16211626
f"Committee id mismatch between epoch_state {es_constitution_id} "
16221627
f"and committee table {tx_constitution_id}."
16231628
)
1629+
else:
1630+
msg = f"Unsupported action type for epoch state check: {action_type.value}"
1631+
raise ValueError(msg)

0 commit comments

Comments
 (0)