diff --git a/cardano_node_tests/tests/tests_conway/conway_common.py b/cardano_node_tests/tests/tests_conway/conway_common.py index 526abaaaf..3e867caae 100644 --- a/cardano_node_tests/tests/tests_conway/conway_common.py +++ b/cardano_node_tests/tests/tests_conway/conway_common.py @@ -16,13 +16,6 @@ LOGGER = logging.getLogger(__name__) -@dataclasses.dataclass(frozen=True, order=True) -class VotedVotes: - cc: tp.List[clusterlib.VoteCC] # pylint: disable=invalid-name - drep: tp.List[clusterlib.VoteDrep] - spo: tp.List[clusterlib.VoteSPO] - - @dataclasses.dataclass(frozen=True) class PParamPropRec: proposals: tp.List[clusterlib_utils.UpdateProposal] @@ -205,7 +198,7 @@ def cast_vote( cc_skip_votes: bool = False, drep_skip_votes: bool = False, spo_skip_votes: bool = False, -) -> VotedVotes: +) -> governance_utils.VotedVotes: """Cast a vote.""" # pylint: disable=too-many-arguments votes_cc = [] @@ -294,7 +287,7 @@ def cast_vote( assert not votes_drep or prop_vote["dRepVotes"], "No DRep votes" assert not votes_spo or prop_vote["stakePoolVotes"], "No stake pool votes" - return VotedVotes(cc=votes_cc, drep=votes_drep, spo=votes_spo) + return governance_utils.VotedVotes(cc=votes_cc, drep=votes_drep, spo=votes_spo) def resign_ccs( diff --git a/cardano_node_tests/tests/tests_conway/test_info.py b/cardano_node_tests/tests/tests_conway/test_info.py index 24f5aaca1..5bf867448 100644 --- a/cardano_node_tests/tests/tests_conway/test_info.py +++ b/cardano_node_tests/tests/tests_conway/test_info.py @@ -14,6 +14,7 @@ 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_utils from cardano_node_tests.utils import governance_setup from cardano_node_tests.utils import governance_utils from cardano_node_tests.utils import helpers @@ -175,7 +176,7 @@ def test_info( ) reqc.cli024.start(url=helpers.get_vcs_link()) - conway_common.submit_vote( + vote_tx_output = conway_common.submit_vote( cluster_obj=cluster, name_template=temp_template, payment_addr=pool_user_ug.payment, @@ -185,6 +186,8 @@ def test_info( ) reqc.cli024.success() + vote_txid = cluster.g_transaction.get_txid(tx_body_file=vote_tx_output.out_file) + vote_gov_state = cluster.g_conway_governance.query.gov_state() _cur_epoch = cluster.g_query.get_epoch() conway_common.save_gov_state( @@ -227,3 +230,9 @@ def test_info( governance_utils.check_vote_view(cluster_obj=cluster, vote_data=votes_drep[0]) governance_utils.check_vote_view(cluster_obj=cluster, vote_data=votes_spo[0]) reqc.cli022.success() + + # Check dbsync + dbsync_utils.check_votes( + votes=governance_utils.VotedVotes(cc=votes_cc, drep=votes_drep, spo=votes_spo), + txhash=vote_txid, + ) diff --git a/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py b/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py index 732f8171a..026ef74c7 100644 --- a/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py +++ b/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py @@ -164,7 +164,7 @@ def test_treasury_withdrawals( # noqa: C901 def _cast_vote( approve: bool, vote_id: str, add_spo_votes: bool = False - ) -> conway_common.VotedVotes: + ) -> governance_utils.VotedVotes: votes_cc = [] votes_drep = [] votes_spo = [] @@ -243,7 +243,7 @@ def _cast_vote( assert prop_vote["dRepVotes"], "No DRep votes" assert not votes_spo or prop_vote["stakePoolVotes"], "Unexpected stake pool votes" - return conway_common.VotedVotes(cc=votes_cc, drep=votes_drep, spo=votes_spo) + return governance_utils.VotedVotes(cc=votes_cc, drep=votes_drep, spo=votes_spo) # Check that SPOs cannot vote on treasury withdrawal action with pytest.raises(clusterlib.CLIError) as excinfo: diff --git a/cardano_node_tests/utils/dbsync_queries.py b/cardano_node_tests/utils/dbsync_queries.py index 490dabf90..e4aba4218 100644 --- a/cardano_node_tests/utils/dbsync_queries.py +++ b/cardano_node_tests/utils/dbsync_queries.py @@ -424,6 +424,17 @@ class GovActionProposalDBRow: expired_epoch: int +@dataclasses.dataclass(frozen=True) +class VotingProcedureDBRow: + # pylint: disable-next=invalid-name + id: int + voter_role: str + committee_voter: int + drep_voter: int + pool_voter: int + vote: str + + @contextlib.contextmanager def execute(query: str, vars: tp.Sequence = ()) -> tp.Iterator[psycopg2.extensions.cursor]: # pylint: disable=redefined-builtin @@ -1125,3 +1136,18 @@ def query_gov_action_proposal( with execute(query=query, vars=(query_var,)) as cur: while (result := cur.fetchone()) is not None: yield GovActionProposalDBRow(*result) + + +def query_voting_procedure(txhash: str) -> tp.Generator[VotingProcedureDBRow, None, None]: + """Query voting_procedure table in db-sync.""" + query = ( + "SELECT" + " vp.id, vp.voter_role, vp.committee_voter, vp.drep_voter, vp.pool_voter, vp.vote " + "FROM voting_procedure as vp " + "INNER JOIN tx ON tx.id = vp.tx_id " + "WHERE tx.hash = %s;" + ) + + with execute(query=query, vars=(rf"\x{txhash}",)) as cur: + while (result := cur.fetchone()) is not None: + yield VotingProcedureDBRow(*result) diff --git a/cardano_node_tests/utils/dbsync_utils.py b/cardano_node_tests/utils/dbsync_utils.py index 6ff766a05..f2845cb1e 100644 --- a/cardano_node_tests/utils/dbsync_utils.py +++ b/cardano_node_tests/utils/dbsync_utils.py @@ -985,3 +985,25 @@ def check_drep_deregistration( ), f"Wrong deposit value for deregistered DRep {drep.drep_id} in db-sync" return drep_data + + +def check_votes(votes: governance_utils.VotedVotes, txhash: str) -> None: + """Check votes in db-sync.""" + expected_votes_by_role = { + "ConstitutionalCommittee": [v.vote.name for v in votes.cc], + "DRep": [v.vote.name for v in votes.drep], + "SPO": [v.vote.name for v in votes.spo], + } + + dbsync_votes = list(dbsync_queries.query_voting_procedure(txhash=txhash)) + + dbsync_votes_by_role: dict = { + "ConstitutionalCommittee": [], + "DRep": [], + "SPO": [], + } + + for d_vote in dbsync_votes: + dbsync_votes_by_role[d_vote.voter_role].append(d_vote.vote.upper()) + + assert expected_votes_by_role == dbsync_votes_by_role, "Votes didn't match in dbsync" diff --git a/cardano_node_tests/utils/governance_utils.py b/cardano_node_tests/utils/governance_utils.py index 6e5517292..111be325a 100644 --- a/cardano_node_tests/utils/governance_utils.py +++ b/cardano_node_tests/utils/governance_utils.py @@ -63,6 +63,13 @@ class StakeDelegation: total_lovelace: int +@dataclasses.dataclass(frozen=True, order=True) +class VotedVotes: + cc: tp.List[clusterlib.VoteCC] # pylint: disable=invalid-name + drep: tp.List[clusterlib.VoteDrep] + spo: tp.List[clusterlib.VoteSPO] + + class PrevGovActionIds(enum.Enum): COMMITTEE = "Committee" CONSTITUTION = "Constitution"