Skip to content

Commit

Permalink
Merge pull request #2363 from saratomaz/test_dbsync_treasuary_table
Browse files Browse the repository at this point in the history
Test treasury_withdrawal dbsync table - CIP084
  • Loading branch information
mkoura authored Jul 15, 2024
2 parents b8c075d + a517419 commit 7680447
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cardano_node_tests/tests/reqs_conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions cardano_node_tests/utils/dbsync_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
16 changes: 16 additions & 0 deletions cardano_node_tests/utils/dbsync_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 7680447

Please sign in to comment.