diff --git a/cardano_node_tests/tests/reqs_conway.py b/cardano_node_tests/tests/reqs_conway.py index 06b0f1144..234953443 100644 --- a/cardano_node_tests/tests/reqs_conway.py +++ b/cardano_node_tests/tests/reqs_conway.py @@ -123,7 +123,7 @@ def __r(id: str) -> requirements.Req: cip081 = __r("CIP081") cip082 = __r("CIP082") cip083 = __r("CIP083") - +cip084 = __r("CIP084") cip085 = __r("CIP085") cip086 = __r("CIP086") cip087 = __r("CIP087") 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 05f73739a..903ffa8b5 100644 --- a/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py +++ b/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py @@ -15,6 +15,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_utils from cardano_node_tests.utils import helpers from cardano_node_tests.utils import submit_utils @@ -354,6 +355,17 @@ def _cast_vote( governance_utils.check_vote_view(cluster_obj=cluster, vote_data=voted_votes.cc[0]) governance_utils.check_vote_view(cluster_obj=cluster, vote_data=voted_votes.drep[0]) + reqc.cip084.start(url=helpers.get_vcs_link()) + # Check dbsync + dbsync_utils.check_treasury_withdrawal( + actions_num=actions_num, + stake_address=recv_stake_addr_rec.address, + transfer_amt=transfer_amt, + txhash=action_txid, + ) + + reqc.cip084.success() + if xfail_ledger_3979_msgs: ledger_3979 = issues.ledger_3979.copy() ledger_3979.message = " ;".join(xfail_ledger_3979_msgs) diff --git a/cardano_node_tests/utils/dbsync_queries.py b/cardano_node_tests/utils/dbsync_queries.py index ecff6ce90..2474a09e1 100644 --- a/cardano_node_tests/utils/dbsync_queries.py +++ b/cardano_node_tests/utils/dbsync_queries.py @@ -512,6 +512,15 @@ class NewCommitteeMemberDBRow: expiration_epoch: int +@dataclasses.dataclass(frozen=True) +class TreasuryWithdrawalDBRow: + # pylint: disable-next=invalid-name + expiration: int + enacted_epoch: int + addr_view: str + amount: int + + @contextlib.contextmanager def execute(query: str, vars: tp.Sequence = ()) -> tp.Iterator[psycopg2.extensions.cursor]: # pylint: disable=redefined-builtin @@ -1300,3 +1309,20 @@ def query_committee_members(committee_id: int) -> tp.Generator[NewCommitteeMembe with execute(query=query, vars=(committee_id,)) as cur: while (result := cur.fetchone()) is not None: yield NewCommitteeMemberDBRow(*result) + + +def query_treasury_withdrawal(txhash: str) -> tp.Generator[TreasuryWithdrawalDBRow, None, None]: + """Query treasury_withdrawal table in db-sync.""" + query = ( + "SELECT" + " gap.expiration, gap.enacted_epoch, stake_address.view, treasury_withdrawal.amount " + "FROM gov_action_proposal as gap " + "INNER JOIN treasury_withdrawal ON treasury_withdrawal.gov_action_proposal_id = gap.id " + "INNER JOIN stake_address ON treasury_withdrawal.stake_address_id = stake_address.id " + "INNER JOIN tx ON tx.id = gap.tx_id " + "WHERE tx.hash = %s;" + ) + + with execute(query=query, vars=(rf"\x{txhash}",)) as cur: + while (result := cur.fetchone()) is not None: + yield TreasuryWithdrawalDBRow(*result) diff --git a/cardano_node_tests/utils/dbsync_utils.py b/cardano_node_tests/utils/dbsync_utils.py index d4d74c8ca..1a57960a5 100644 --- a/cardano_node_tests/utils/dbsync_utils.py +++ b/cardano_node_tests/utils/dbsync_utils.py @@ -1200,3 +1200,19 @@ def check_committee_info(gov_state: dict, txid: str) -> None: assert ( len(dbsync_committee_members) == size_of_proposed_cm ), "The number of committee members doesn't match in dbsync" + + +def check_treasury_withdrawal( + actions_num: int, stake_address: str, transfer_amt: int, txhash: str +) -> None: + """Check treasury_withdrawal in db-sync.""" + if not configuration.HAS_DBSYNC: + return + + dbsync_data = list(dbsync_queries.query_treasury_withdrawal(txhash=txhash)) + assert len(dbsync_data) == actions_num + + for entry in dbsync_data: + assert entry.addr_view == stake_address, "Wrong stake address on dbsync" + assert entry.amount == transfer_amt, "Wrong transfer amount in dbsync" + assert entry.enacted_epoch, "Action not marked as enacted in dbsync"